Hello Geoff,
Regarding changing the terminal as root, you need to reset the root password and you will have access to the terminal with all the permissions. To do that, you will have to make use of any of the tutorials you can find over the internet regarding how to reset the root password.
Once you get access as root, you can reset the admin password of OpenDistro, and get access to your Kibana Interface.
You can change the admin password by following this Wazuh Documentation article: Wazuh documentation - Change users’ password
Having in mind this is an Opendistro feature, you should check also the OpenDistro documentation: Apply configuration changes using securityadmin.sh
I will explain to you how to do it easily:
Passwords are stored in a hash format in a file named internal_users.yml file. As the name suggests this file stores user credentials including the admin user. Therefore, the first step is to create the hash. Elasticsearch provides a script to create a password hash
export JAVA_HOME=/usr/share/elasticsearch/jdk/ && /usr/share/elasticsearch/plugins/opendistro_security/tools/hash.sh
This will prompt you to enter a password and outputs its hash. Copy the output as we are going to store it in internal_users.yml
vi /usr/share/elasticsearch/plugins/opendistro_security/securityconfig/internal_users.yml
Find the “admin” user section and update the hash value:
admin:
hash: "$2y$12$UrLh1/OG6EhZ8RC27BD5ROOQ.4ioECP7RbE1ILC9vg4bWo0cx6vhS"
reserved: true
backend_roles:
- "admin"
description: "Demo admin user"
Simply run the following commands:
export JAVA_HOME=/usr/share/elasticsearch/jdk/ && /usr/share/elasticsearch/plugins/opendistro_security/tools/securityadmin.sh -cd /usr/share/elasticsearch/plugins/opendistro_security/securityconfig/ -nhnv -cacert /etc/elasticsearch/certs/root-ca.pem -cert /etc/elasticsearch/certs/admin.pem -key /etc/elasticsearch/certs/admin-key.pem -h <elasticsearch_IP>
Output:
Open Distro Security Admin v7
Will connect to localhost:9300 ... done
...
...
...
Done with success
You should see “Done with success” at the bottom of the output.
I hope this information could be helpful.
Hello Geoff,
As far as I can see this is the error:
Caused by: ElasticsearchSecurityException[Error while initializing transport SSL layer from PEM: ElasticsearchException[Unable to read /etc/elasticsearch/certs/admin.key (/etc/elasticsearch/certs/admin.key). Please make sure this files exists and is readable regarding to permissions. Property: opendistro_security.ssl.transport.pemkey_filepath]]; nested: ElasticsearchException[Unable to read /etc/elasticsearch/certs/admin.key (/etc/elasticsearch/certs/admin.key). Please make sure this files exists and is readable regarding to permissions. Property: opendistro_security.ssl.transport.pemkey_filepath]
It means the script can not access /etc/elasticsearch/certs/admin.key file, even because it does not exist or the user elasticsearch does not have permission to read it, please check this with the following command:
ls -l /etc/elasticsearch/certs/
If the file is there, check the permissions, and set read permissions to all the users to test:
chmod +r /etc/elasticsearch/certs/*
If the file is not there, you will need to recreate the admin certificate from the root-ca but you will need the private key and the public certificate root-ca.key and root-ca.pem:
Create a private key
openssl genrsa -out admin-key-temp.pem 2048
Convert private key to PKCS#8 format
openssl pkcs8 -inform PEM -outform PEM -in admin-key-temp.pem -topk8 -nocrypt -v1 PBE-SHA1-3DES -out admin.key
Create a CSR that'll be signed by the CA
openssl req -new -key admin.key -subj "/C=AR/ST=MZA/O=Wazuh/OU=Ops/CN=admin" -out admin.csr
Sign the CSR
openssl x509 -req -in admin.csr -CA root-ca.pem -CAkey root-ca.key -CAcreateserial -sha256 -out admin.pem -days 3650
If this does not work, try recreating the certificates for all the environment (Filebeat, Elasticsearch, and Kibana): https://documentation.wazuh.com/current/user-manual/certificates.html
I hope this could be helpful.
Hello Geoff,
That file is the same that admin.key but with another name, and the name of the file is not important, you only need the name to use it. Have in mind this, the certificates come in pairs, one is the private key (.key file, or key.pem file), and the other is the public certificate (.pem file).
For the script /usr/share/elasticsearch/plugins/opendistro_security/tools/securityadmin.sh you need to specify the private key of the admin user under the -key parameter, and the certificate for the admin user under the -cert parameter.
That being said, you can use the admin-key.pem file instead of admin.key and vice-versa.
I hope that answers your question.
Hello Geoff,
Yes, you need to check now first if Elasticsearch is running:
systemctl status elasticsearch
And then see if the ports are open, you can make use of netstat and having in mind the Elasticsearch runs under Java:
netstat -tulnap | grep LISTEN | grep java
The 9200 port is for the API calls, and the 9300 port is for cluster connection.
I hope this information could be helpful.
Hello Geoff,
That is a common issue and it can be skipped by adding the -icl to the securityadmin.sh command as stated in the OpenDistro troubleshooting: Troubleshooting securityadmin.sh
export JAVA_HOME=/usr/share/elasticsearch/jdk/ && /usr/share/elasticsearch/plugins/opendistro_security/tools/securityadmin.sh -cd /usr/share/elasticsearch/plugins/opendistro_security/securityconfig/ -nhnv -cacert /etc/elasticsearch/certs/root-ca.pem -cert /etc/elasticsearch/certs/admin.pem -key /etc/elasticsearch/certs/admin-key.pem -h <elasticsearch_IP> -icl
There are some other ways of troubleshooting that if is still failing, please check the documentation I send in this message.
I hope this could be helpful