Skip to content

Steps to Change the Password for the User Admin

Change the OpenSearch admin password hash inside the Docker container.

4 min read Updated SS

Updating OpenSearch Docker Container Password Hash#

1. Login to the OpenSearch Docker container on the master node:

  • The command below allows you to access the OpenSearch Docker container's shell.
docker exec -it <opensearchcontainerid> bash
  • Execute the below command to navigate to the OpenSearch Security tools directory:
cd /usr/share/opensearch/plugins/opensearch-security/tools
  • Execute the below command to generate a new password hash:
./hash.sh -p <newpassword>
  • Make a note of the generated hash output.

For example: Sample output as below

$2a$12$JJSXNfTowz7Uu5ttXfeYpeYE0arACvcwlPBStB1F.MI7f0U9Z4DGC
  • Exit the container.

Copying internal_users.yml from the OpenSearch Docker container to the host#

1. Copy internal_users.yml from the OpenSearch Docker container to the host from the master node.

  • Execute the below command to update the password hash:
docker cp <opensearchcontainerid>:/usr/share/opensearch/plugins/opensearch-security/securityconfig/internal_users.yml <InstallPath>/Appsone_Service/opensearch/config/

Updating Admin User Hash in internal_users.yml#

1. Edit the internal_users.yml file and add the new hash generated in step 1 in the admin section.

For example: The generated new hash is as below:

"$2y$12$k8JnbSyGHZxWBj3xaPtn7uVuwXJJnEde7JfCZJshMdfD0ILfyZ5Oi"

2. Save and close the file.

3. Copy the internal_users.yml file to all hosts where OpenSearch is running.

4. Mount the internal_users.yml file in opensearch.nomad file under the volumes section for all OpenSearch tasks.

Add the following line to the volumes section in the opensearch.nomad file:

<InstallPath>/Appsone_Service/opensearch/config/internal_users.yml:/usr/share/opensearch/plugins/opensearch-security/securityconfig/internal_users.yml

Verify the Default OpenSearch Certificate Availability#

To verify the default of OpenSearch Certificate Availability, follow the steps below:

1. Navigate to the path below:

<a1homepath>/Appsone_Service/opensearch/config

Check for the following files:

kirk-key.pem, kirk.pem, and root-ca.pem
  • If the above files are not present, then the user needs to generate a new admin certificate.
  • If the above files are present, then restart the OpenSearch Nomad Job.

Generating Admin Certificate#

To generate admin certificates, follow the below steps:

1. Update the opensearch-template files with the admin DN parameter on all nodes where OpenSearch is running:

  • Locate the plugins.security.authcz.admin_dn parameter in the OpenSearch-template files.
  • Replace the existing parameter or add the following line if it's not present:
CN=Admin,OU=AdminEngg,O=Appnomic,L=Bangalore,ST=Karnataka,C=IN

2. Generate an admin certificate on the OpenSearch master node.

  • Execute the following commands to create a new admin certificate:
openssl genrsa -out admin-key-temp.pem 2048
openssl pkcs8 -inform PEM -outform PEM -in admin-key-temp.pem -topk8 -nocrypt -v1 PBE-SHA1-3DES -out admin-key.pem
  • Executing the below command creates a Certificate Signing Request (CSR) using the private key.
openssl req -new -key admin-key.pem -subj "/C=IN/ST=Karnataka/L=Bangalore/O=Appnomic/OU=AdminEngg/CN=*.admin" -out admin.csr

The output of the CSR is stored in the file admin.csr.

  • The below command signs the CSR using the CA certificate and private key by creating a new admin certificate (admin.pem) valid for 730 days.
openssl x509 -req -in admin.csr -CA <InstallPath>/Appsone_Service/utilities/Certificate/ca_cert/appnomic-rootca.crt -CAkey <InstallPath>/Appsone_Service/utilities/Certificate/ca_cert/appnomic-rootca.key -CAcreateserial -sha256 -out admin.pem -days 730

3. Copy admin.pem and admin-key.pem to the OpenSearch config directory on all nodes where OpenSearch is running.

<InstallPath>/Appsone_Service/opensearch/config

Restart the OpenSearch Nomad job#

1. To restart the OpenSearch Nomad job, follow the steps below:

  • Execute the command below to stop the currently running OpenSearch Nomad job.
nomad stop opensearch
  • Execute the command below to trigger a garbage collection process in Nomad to clean up unused resources.
curl -k -X PUT https://localhost:4646/v1/system/gc;
  • Execute the command below to start the OpenSearch Nomad job using the updated configuration.
nomad run opensearch.nomad
  • Check if the OpenSearch cluster is formed.
  • Execute the command below to retrieve information about the nodes in the OpenSearch cluster.
curl -ku admin:admin https://<opensearchip>:<opensearchport>/_cat/nodes

2. Log in to the OpenSearch Docker container on the OpenSearch master node:

docker exec -it <opensearchcontainerid> bash
bashtps://<opensearchip>:<opensearchport>/_cat/nodes

3. Navigate to the OpenSearch Security tools directory:

cd /usr/share/opensearch/plugins/opensearch-security/tools

Backup the current security configuration#

1. To take a backup of the existing configuration, follow one of the two options below.

a. If you have created a new admin certificate, execute the following command:

./securityadmin.sh -backup /tmp/opensearch -icl -nhnv -cacert ../../../config/appnomic-rootca.crt -cert ../../../config/admin.pem -key ../../../config/admin-key.pem

b. If you have not created a new admin certificate, execute the following command:

sh /usr/share/opensearch/plugins/opensearch-security/tools/securityadmin.sh -backup /tmp/opensearch -icl -nhnv -cacert /usr/share/opensearch/config/root-ca.pem -cert /usr/share/opensearch/config/kirk.pem -key /usr/share/opensearch/config/kirk-key.pem

Update the security Configuration#

1. To update the new password, follow one of the two options below.

a. If you have created a new admin certificate, execute the following command:

./securityadmin.sh -f ../securityconfig/internal_users.yml -icl -nhnv -cacert ../../../config/appnomic-rootca.crt -cert ../../../config/admin.pem -key ../../../config/admin-key.pem

b. If you have not created a new admin certificate, execute the following command:

sh /usr/share/opensearch/plugins/opensearch-security/tools/securityadmin.sh -f /usr/share/opensearch/plugins/opensearch-security/securityconfig/internal_users.yml -icl -nhnv -cacert /usr/share/opensearch/config/root-ca.pem -cert /usr/share/opensearch/config/kirk.pem -key /usr/share/opensearch/config/kirk-key.pem

2. Exit the container command

exit

3. Copy the backup directory from the container to the host by executing the command below:

docker cp <opensearchcontainerid>:/tmp/opensearch <InstallPath>/Appsone_Service/opensearch/config/os_config_backups

Verify the Password Change#

Verify that you can connect with the new password by executing the command below:

curl -ku admin:<newpassword> https://<opensearchip>:<opensearchport>/_cat/nodes

If the command returns a list of nodes, it confirms that the new password is working correctly.