Changing a User Password in OpenSearch
4 minute read
This guide explains how to change passwords in OpenSearch.
Recommended: Change the admin password via the package value
The OpenSearch admin password is managed through the adminPassword package value.
Set it for the opensearch-os package (and the matching opensearch-dashboards
package) in your enterprise-values.yaml and run an update:
packages:
- name: opensearch-os
enabled: true
values:
standard:
adminPassword: "<your-new-password>" # must match opensearch-dashboards
- name: opensearch-dashboards
enabled: true
values:
standard:
adminPassword: "<your-new-password>" # must match opensearch-os
On the next kubeopsctl apply/update the new password is enforced automatically
after the deployment. This also works on existing clusters and does not remove any
other internal users.
admin password and reapplies the
authentication/authorization configuration; it never overwrites your internal users.
Advanced: Change any user’s password manually via securityadmin
Use this method to change the password of any internal user (for example testuser
or kibanaro) without a package update.
This process reads the live internal users from the security index (via
securityadmin -backup), so every other user — including users you created in the
OpenSearch Dashboards Security UI — is preserved. Do not build the file from the
internal-users-config-secret: that secret only holds the packaged baseline users and
would remove UI-created users when applied.
Prerequisites
- Access to the Kubernetes cluster and
kubectl. - The admin certificate is available in the pod at
/usr/share/opensearch/config/certs/(root-ca.pem,admin.pem,admin-key.pem) in a KubeOps deployment.
Set a shell variable for convenience (adjust the namespace and pod name as needed):
NS=logging; POD=opensearch-cluster-master-0
Step 1: Back up the current internal users (live state)
kubectl exec -it $POD -n $NS -- bash -c "\
/usr/share/opensearch/plugins/opensearch-security/tools/securityadmin.sh -backup /tmp/os-sec \
-icl -nhnv \
-cacert /usr/share/opensearch/config/certs/root-ca.pem \
-cert /usr/share/opensearch/config/certs/admin.pem \
-key /usr/share/opensearch/config/certs/admin-key.pem"
This writes the current configuration — including all internal users — to
/tmp/os-sec/ in the pod.
securityadmin -backup may end with Configuration for 'audit' failed because of empty source and a non-zero exit code. This is harmless: internal_users.yml is written
before that step, so the file you need is already present.
Step 2: Generate a new password hash for each user
Run this once per user and note the resulting hash:
kubectl exec -it $POD -n $NS -- bash -c "sh /usr/share/opensearch/plugins/opensearch-security/tools/hash.sh -p <new_password>"
Step 3: Update the hashes in the backup file
Copy the file out, edit it locally, and copy it back:
kubectl cp $NS/$POD:/tmp/os-sec/internal_users.yml ./internal_users.yml
# edit ./internal_users.yml: replace the hash: value under each user you want to change
kubectl cp ./internal_users.yml $NS/$POD:/tmp/os-sec/internal_users.yml
Only change the hash: line of the target users; leave everyone else untouched:
testuser:
hash: "<new-hash-for-testuser>"
reserved: false
backend_roles:
- "testrole"
kibanaro:
hash: "<new-hash-for-kibanaro>"
reserved: false
backend_roles:
- "kibanauser"
Step 4: Apply only the internal users configuration
The DN of the certificate specified with -cert must be listed under
plugins.security.authcz.admin_dn in opensearch.yml. In a KubeOps deployment the
admin certificate subject is C=DE,L=test,O=client,OU=client,CN=admin.
More information: Opensearch Documentation.
Apply only the internalusers config type. Do not use -cd (the whole directory)
here: -cd requires the complete security config set (including nodes_dn.yml,
allowlist.yml, audit.yml), which a KubeOps deployment does not ship, so it would
fail with nodes_dn.yml ... No such file or directory.
kubectl exec -it $POD -n $NS -- bash -c "\
/usr/share/opensearch/plugins/opensearch-security/tools/securityadmin.sh \
-f /tmp/os-sec/internal_users.yml -t internalusers \
-icl -nhnv \
-cacert /usr/share/opensearch/config/certs/root-ca.pem \
-cert /usr/share/opensearch/config/certs/admin.pem \
-key /usr/share/opensearch/config/certs/admin-key.pem"
The change is written to the security index and takes effect immediately — no pod restart required.
Important
Once applied withsecurityadmin.sh, credentials are stored in the OpenSearch
security index, which lives on the persistent volume and therefore survives pod and
container restarts as well as package updates. Editing files inside the container
without running securityadmin.sh only changes the local file and is not applied to
the cluster. For the admin user, prefer the adminPassword package value described
above — it is enforced again on every update and keeps all other internal users intact.