Hello everyone, I am writing this topic because I have an issue on my Elastic Stack. It comes from the day when certificates reached its expiration date. The following message was on in my Kibana's interface :
"Kibana is not ready yet"
So, I investigated on the 3 servers (Logstash, Elasticsearch, Kibana) and I found something about certificate. I decided to change them because they were expirate, but ELK is still down.
This is what I did, and after I will show you syslog errors tht are still alives and what I did for them.
The Elastic Stack was implemented by another employee who no longer works here and I am working on ELK since 3 months, I probably don't know evrything about it.
First of all, I noticed that there are 3 certificates and 3 differents keys. Everything is ok, the communication between servers has to be encrypted by using Xpack security features I think ...
But there was something which disturbed me in formats.
SSL Configuration :
LOGSTASH --> CA.crt + logstash.crt + logstash.p8 (for PKCS8 conversion from .key file I think)
ELASTICSEARCH --> CA.cer + elasticsearch.pem + elasticsearch.key
KIBANA --> CA.cer + kibana.pem + kibana.key
Why there are .crt and .pem certificates ? I saw on Internet that there is no difference between them and my internal CA gives me onlyt .cer and .pem files. So, from this point I decided to start certificates renewal.
I used the commands below :
DOMAIN = my Domain Name
openssl req -key elasticsearch.key -new -out elasticsearch.csr -subj /CN=elasticsearch.DOMAIN -reqexts SAN -extensions SAN -config <(cat /usr/lib/ssl/openssl.cnf <(printf '[SAN]\nsubjectAltName=DNS:elasticsearch.DOMAIN')) -sha256
openssl req -key kibana.key -new -out kibana.csr -subj /CN=kibana.DOMAIN -reqexts SAN -extensions SAN -config <(cat /usr/lib/ssl/openssl.cnf <(printf '[SAN]\nsubjectAltName=DNS:kibana.DOMAIN')) -sha256
For logstash, it asked me a password, I think because it's PKCS8 format. I didn't have the password so I generated a new private key
openssl genrsa -aes256 -out elasticsearch.key 4096
openssl req -key logstash.key -new -out logstash.csr -subj /CN=logstash.DOMAIN -reqexts SAN -extensions SAN -config <(cat /usr/lib/ssl/openssl.cnf <(printf '[SAN]\nsubjectAltName=DNS:logstash.DOMAIN')) -sha256
Now, I have my three .csr files to ask new certificates from the Internal CA.
After that I got 3 certificates from the CA and I replaced the old ones with the new ones. The new certificates are in .pem format because I don't know how to get a .crt certificate. Also, I can't read the .cer format to do a check so I picked certificates in .pem format.
Obviously I changed all paths in configurations files with the new certificates name.
Moreover I use the following command to convert the private key of logstash in the required PKCS8 format :
openssl pkcs8 -in logstash.key -topk8 -out logstash.pkcs8.key
I restarted services but it's still not working.
I think that there are 2 issues in fact.
When I go on https://kibana.DOMAIN:5601, I still have "Kibana is not ready". However, the certificate is valid. A weak algorithm is used by the CA (sha1) but I think that I should access to kibana interface despite this.
Now, I will show you what I get in /var/log/syslog
for the 3 servers.
FROM LOGSTASH /var/log/syslog :
Feb 17 15:31:38 logstash logstash[22339]: [2021-02-17T15:31:38,646][ERROR][logstash.inputs.beats ] Looks like you either have a bad certificate, an invalid key or your private key was not in PKCS8 format.
Feb 17 15:31:38 logstash logstash[22339]: [2021-02-17T15:31:38,646][WARN ][io.netty.channel.ChannelInitializer] Failed to initialize a channel. Closing: [id: 0xfea594e7, L:/10.56.245.132:5044 - R:/10.56.245.14:20534]
Feb 17 15:31:38 logstash logstash[22339]: java.lang.IllegalArgumentException: File does not contain valid private key: /etc/logstash/certs/logstash.pkcs8.key
ecurity.InvalidKeyException: IOException : DER input, Integer tag error
Feb 17 15:31:38 logstash logstash[22339]: #011at sun.security.pkcs.PKCS8Key.decode(PKCS8Key.java:351) ~[?:1.8.0_212]
Feb 17 15:31:38 logstash logstash[22339]: #011at java.security.KeyFactory.generatePrivate(KeyFactory.java:372) ~[?:1.8.0_212]
FROM ELASTICSEARCH /var/log/syslog :
Feb 17 16:19:51 elasticsearch python3[32232]: INFO:elastalert:Queried rule hid from 2021-02-17 16:19 CET to 2021-02-17 16:19 CET: 0 / 0 hits
Feb 17 16:19:51 elasticsearch python3[32232]: /usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
Feb 17 16:19:51 elasticsearch python3[32232]: InsecureRequestWarning)
Feb 17 16:19:51 elasticsearch python3[32232]: /usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
Feb 17 16:19:51 elasticsearch python3[32232]: InsecureRequestWarning)
FROM KIBANA /var/log/syslog :
Feb 17 16:27:27 kibana kibana[5792]: {"type":"log","@timestamp":"2021-02-17T15:27:27Z","tags":["warning","elasticsearch","admin"],"pid":5792,"message":"No living connections"}
Feb 17 16:27:27 kibana kibana[5792]: {"type":"log","@timestamp":"2021-02-17T15:27:27Z","tags":["warning","task_manager"],"pid":5792,"message":"PollError No Living connections"}
Feb 17 16:27:29 kibana systemd-timesyncd[408]: Timed out waiting for reply from 212.83.158.83:123 (3.debian.pool.ntp.org).
Feb 17 16:27:30 kibana kibana[5792]: {"type":"log","@timestamp":"2021-02-17T15:27:30Z","tags":["warning","elasticsearch","admin"],"pid":5792,"message":"Unable to revive connection: https://10.56.245.133:9200/"}
Feb 17 16:27:34 kibana kibana[5792]: {"type":"log","@timestamp":"2021-02-17T15:27:34Z","tags":["license","warning","xpack"],"pid":5792,"message":"License information from the X-Pack plugin could not be obtained from Elasticsearch for the [data] cluster. Error: No Living connections"}
About Logstash investigation :
Feb 18 10:37:36 logstash logstash[22339]: [2021-02-18T10:37:36,910][ERROR][logstash.inputs.beats ] Looks like you either have a bad certificate, an invalid key or your private key was not in PKCS8 format.
I followed this ERROR to find the issue, but I really don't know why it appears because I did the same thing for the two others servers (Kibana and Elasticsearch) and there is no errors like this one for them.
About Elasticsearch investigation :
Feb 17 16:19:55 elasticsearch python3[32232]: /usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
Feb 17 16:19:55 elasticsearch python3[32232]: InsecureRequestWarning)
This is interesting. I looked at the following file : /usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py and you can see below the code around the line 851.
def _validate_conn(self, conn):
"""
Called right before a request is made, after the socket is created.
"""
super(HTTPSConnectionPool, self)._validate_conn(conn)
# Force connect early to allow us to validate the connection.
if not getattr(conn, 'sock', None): # AppEngine might not have `.sock`
conn.connect()
if not conn.is_verified:
warnings.warn((
'Unverified HTTPS request is being made. '
'Adding certificate verification is strongly advised. See: '
'https://urllib3.readthedocs.io/en/latest/advanced-usage.html'
'#ssl-warnings'),
InsecureRequestWarning)
> #https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tlwarnings
> #https://urllib3.readthedocs.io/en/latest/user-guide.html#ssl
In the following guides, I can remove the error with "disable" or if I comment the function, but both solutions are not recommended. I think that maybe there is an issue on my internal CA-certificate ...
About Kibana investigation :
I followed this : https://discuss.elastic.co/t/kibana-server-inot-ready-yet/241217
root@kibana:/home/adminsys # curl -X GET elasticsearch:9200/
curl: (52) Empty reply from server
root@kibana:/home/adminsys # curl -X GET "https://elasticsearch:9200/" --key elasticsearch.pem -k -u elastic
Enter host password for user 'elastic':
{
"name" : "prod-data-1",
"cluster_name" : "MY CLUSTER NAME",
"cluster_uuid" : "_4AKCuu-SVSM4z-t6GZQ",
"version" : {
"number" : "7.2.0",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "508c38a",
"build_date" : "2019-06-20T15:54:18.811730Z",
"build_snapshot" : false,
"lucene_version" : "8.0.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
So, Elasticsearch is ready to be connected to.
root@kibana:/home/adminsys # curl -v https://elasticsearch:9200/
* Trying 10.56.245.133...
* TCP_NODELAY set
* Connected to elasticsearch (10.56.245.133) port 9200 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (OUT), TLS alert, Server hello (2):
* SSL certificate problem: self signed certificate in certificate chain
* Curl_http_done: called premature == 1
* stopped the pause stream!
* Closing connection 0
curl: (60) SSL certificate problem: self signed certificate in certificate chain
More details here: https://curl.haxx.se/docs/sslcerts.html
curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn't adequate, you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.