Apply configuration changes using securityadmin.sh

The security plugin stores its configuration—including users, roles, and permissions—in an index on the OpenSearch cluster (.opendistro_security). Storing these settings in an index lets you change settings without restarting the cluster and eliminates the need to edit configuration files on every single node.

After changing any of the configuration files in plugins/opensearch-security/securityconfig, however, you must run plugins/opensearch-security/tools/securityadmin.sh to load these new settings into the index. You must also run this script at least once to initialize the .opendistro_security index and configure your authentication and authorization methods.

After the .opendistro_security index is initialized, you can use OpenSearch Dashboards to manage your users, roles, and permissions.

Configure the admin certificate

You can configure all certificates that should have admin privileges in opensearch.yml by specifying respective distinguished names (DNs). If you use the demo certificates, for example, you can use the kirk certificate:

  1. plugins.security.authcz.admin_dn:
  2. - CN=kirk,OU=client,O=client,L=test,C=DE

You can’t use node certificates as admin certificates. The two must be separate. Also, do not use any whitespace between the parts of the DN.

Basic usage

The securityadmin.sh tool can be run from any machine that has access to the transport port of your OpenSearch cluster (the default is 9300). You can change the security plugin configuration without having to access your nodes through SSH.

Each node also includes the tool at plugins/opensearch-security/tools/securityadmin.sh. You might need to make the script executable before running it:

  1. chmod +x plugins/opensearch-security/tools/securityadmin.sh

To print all available command line options, run the script with no arguments:

  1. ./plugins/opensearch-security/tools/securityadmin.sh

To load configuration changes to the security plugin, you must provide your admin certificate to the tool:

  1. ./securityadmin.sh -cd ../securityconfig/ -icl -nhnv \
  2. -cacert ../../../config/root-ca.pem \
  3. -cert ../../../config/kirk.pem \
  4. -key ../../../config/kirk-key.pem
  • The -cd option specifies where the security plugin configuration files to upload to the cluster can be found.
  • The -icl (--ignore-clustername) option tells the security plugin to upload the configuration regardless of the cluster name. As an alternative, you can also specify the cluster name with the -cn (--clustername) option.
  • Because the demo certificates are self-signed, we also disable hostname verification with the -nhnv (--disable-host-name-verification) option.
  • The -cacert, -cert and -key options define the location of your root CA certificate, the admin certificate, and the private key for the admin certificate. If the private key has a password, specify it with the -keypass option.

The following table shows the PEM options.

NameDescription
-certThe location of the PEM file containing the admin certificate and all intermediate certificates, if any. You can use an absolute or relative path. Relative paths are resolved relative to the execution directory of securityadmin.sh.
-keyThe location of the PEM file containing the private key of the admin certificate. You can use an absolute or relative path. Relative paths are resolved relative to the execution directory of securityadmin.sh. The key must be in PKCS#8 format.
-keypassThe password of the private key of the admin certificate, if any.
-cacertThe location of the PEM file containing the root certificate. You can use an absolute or relative path. Relative paths are resolved relative to the execution directory of securityadmin.sh.

Sample commands

Apply configuration in securityconfig using PEM certificates:

  1. /usr/share/opensearch/plugins/opensearch-security/tools/securityadmin.sh -cacert /etc/opensearch/root-ca.pem -cert /etc/opensearch/kirk.pem -key /etc/opensearch/kirk-key.pem -cd /usr/share/opensearch/plugins/opensearch-security/securityconfig/

Apply configuration from a single file (config.yml) using PEM certificates:

  1. ./securityadmin.sh -f ../securityconfig/config.yml -icl -nhnv -cert /etc/opensearch/kirk.pem -cacert /etc/opensearch/root-ca.pem -key /etc/opensearch/kirk-key.pem -t config

Apply configuration in securityconfig with keystore and truststore files:

  1. ./securityadmin.sh \
  2. -cd /usr/share/opensearch/plugins/opensearch-security/securityconfig/ \
  3. -ks /path/to/keystore.jks \
  4. -kspass changeit \
  5. -ts /path/to/truststore.jks \
  6. -tspass changeit
  7. -nhnv
  8. -icl

Using securityadmin with keystore and truststore files

You can also use keystore files in JKS format in conjunction with securityadmin.sh:

  1. ./securityadmin.sh -cd ../securityconfig -icl -nhnv
  2. -ts <path/to/truststore> -tspass <truststore password>
  3. -ks <path/to/keystore> -kspass <keystore password>

Use the following options to control the key and truststore settings.

NameDescription
-ksThe location of the keystore containing the admin certificate and all intermediate certificates, if any. You can use an absolute or relative path. Relative paths are resolved relative to the execution directory of securityadmin.sh.
-kspassThe password for the keystore.
-kstThe key store type, either JKS or PKCS#12/PFX. If not specified, the security plugin tries to determine the type from the file extension.
-ksaliasThe alias of the admin certificate, if any.
-tsThe location of the truststore containing the root certificate. You can use an absolute or relative path. Relative paths are resolved relative to the execution directory of securityadmin.sh.
-tspassThe password for the truststore.
-tstThe truststore type, either JKS or PKCS#12/PFX. If not specified, the security plugin tries to determine the type from the file extension.
-tsaliasThe alias for the root certificate, if any.

OpenSearch settings

If you run a default OpenSearch installation, which listens on transport port 9300 and uses opensearch as a cluster name, you can omit the following settings altogether. Otherwise, specify your OpenSearch settings by using the following switches.

NameDescription
-hOpenSearch hostname. Default is localhost.
-pOpenSearch port. Default is 9300—not the HTTP port.
-cnCluster name. Default is opensearch.
-iclIgnore cluster name.
-sniffSniff cluster nodes. Sniffing detects available nodes using the OpenSearch _cluster/state API.
-arc,—accept-red-clusterExecute securityadmin.sh even if the cluster state is red. Default is false, which means the script will not execute on a red cluster.

Certificate validation settings

Use the following options to control certificate validation.

NameDescription
-nhnvDo not validate hostname. Default is false.
-nrhnDo not resolve hostname. Only relevant if -nhnv is not set.
-noopensslDo not use OpenSSL, even if available. Default is to use OpenSSL if it is available.

Configuration files settings

The following switches define which configuration files you want to push to the security plugin. You can either push a single file or specify a directory containing one or more configuration files.

NameDescription
-cdDirectory containing multiple security plugin configuration files.
-fSingle configuration file. Can’t be used with -cd.
-tFile type.
-rlReload the current configuration and flush the internal cache.

To upload all configuration files in a directory, use this:

  1. ./securityadmin.sh -cd ../securityconfig -ts ... -tspass ... -ks ... -kspass ...

If you want to push a single configuration file, use this:

  1. ./securityadmin.sh -f ../securityconfig/internal_users.yml -t internalusers \
  2. -ts ... -tspass ... -ks ... -kspass ...

The file type must be one of the following:

  • config
  • roles
  • rolesmapping
  • internalusers
  • actiongroups

Cipher settings

You probably won’t need to change cipher settings. If you need to, use the following options.

NameDescription
-ecComma-separated list of enabled TLS ciphers.
-epComma-separated list of enabled TLS protocols.

Backup, restore, and migrate

You can download all current configuration files from your cluster with the following command:

  1. ./securityadmin.sh -backup /file/path -ts ... -tspass ... -ks ... -kspass ...

This command dumps the current security plugin configuration from your cluster to individual files in the directory you specify. You can then use these files as backups or to load the configuration into a different cluster. This command is useful when moving a proof-of-concept to production:

  1. ./securityadmin.sh -backup ~ -icl -nhnv -cacert ../../../config/root-ca.pem -cert ../../../config/kirk.pem -key ../../../config/kirk-key.pem

To upload the dumped files to another cluster:

  1. ./securityadmin.sh -h production.example.com -p 9301 -cd /etc/backup/ -ts ... -tspass ... -ks ... -kspass ...

To migrate configuration YAML files from the OpenSearch 0.x.x format to the 1.x.x format:

  1. ./securityadmin.sh -migrate ../securityconfig -ts ... -tspass ... -ks ... -kspass ...
NameDescription
-backupRetrieve the current security plugin configuration from a running cluster and dump it to the working directory.
-migrateMigrate configuration YAML files from version 0.x.x to 1.x.x.

Other options

NameDescription
-dciDelete the security plugin configuration index and exit. This option is useful if the cluster state is red due to a corrupted security plugin index.
-esaEnable shard allocation and exit. This option is useful if you disabled shard allocation while performing a full cluster restart and need to recreate the security plugin index.
-wDisplays information about the used admin certificate.
-rlBy default, the security plugin caches authenticated users, along with their roles and permissions, for one hour. This option reloads the current security plugin configuration stored in your cluster, invalidating any cached users, roles, and permissions.
-iThe security plugin index name. Default is .opendistro_security.
-erSet explicit number of replicas or auto-expand expression for the opensearch_security index.
-eraEnable replica auto-expand.
-draDisable replica auto-expand.
-usUpdate the replica settings.