Configuring OpenSearch custom resources

Edit the OpenSearch custom resource configuration.

Reducing the storage size

You can edit the OpenSearch custom resource (CR) configuration to reduce the OpenSearch PVC size from the default.

To reduce the PVC size after deployment, back up your data, delete existing PVCs, and restore and re-create the PVCs with updated sizeLimit values.

Reduced PVC sizing is generally acceptable for development and test environments with light workloads. However, before you reduce storage allocation, consider the following potential conditions if the disk becomes full:

  • Index growth exceeds the allocated capacity.
  • Clusters might become unstable under heavy write workloads.
  • Proactive storage monitoring and capacity planning might be needed with reduced storage.

Customizing admin credentials with a Kubernetes Secret

The ibm-openSearch-operator operator generates a default password for the OpenSearch admin user. However, you can specify your own custom Kubernetes Secret that contains the admin credentials. Customize admin credentials for enhanced security, compliance requirements, or to avoid including default credentials in production environments.

  1. Create a Base64-encoded credential with the following command. In this example, opensearch@123 is the custom password for your admin user.
    echo -n 'opensearch@123' | base64
    The command results in output similar to the following example:
    b3BlbnNlYXJjaEAxMjM=
  2. In the same namespace where the OpenSearch cluster is deployed, run the oc apply -f or kubectl apply -f command to create a custom Secret with an admin name and Base64-encoded password.
    kind: Secret
    apiVersion: v1
    metadata:
      name: custom-admin-user
      namespace: <namespace>
    data:
      opensearch-admin: b3BlbnNlYXJjaEAxMjM=
    type: Opaque
  3. Reference the Secret in your OpenSearch CR.
    apiVersion: opensearch.cloudpackopen.ibm.com/v1
    kind: Cluster
    ...
    spec:
      ...
      plugins:
        ...
        security:
          enabled: true
          version: 3.2.0.0 # Replace this value with your latest OpenSearch version.
          internalUserSecret: custom-admin-user

    After the custom-admin-user Secret is configured, the OpenSearch route and indexes become accessible with the custom-admin-user credentials. The custom Secret is used to populate the internal_users file inside of the operand pods, and the operator doesn't generate the default admin:password admin credentials.

    If the internalUserSecret Secret is used to populate the internal_users.yml file, the credentials are available to all components that use internal user authentication. This authentication includes both route-based access and intra-cluster and internal client communication unless LDAP or another authentication domain takes precedence for internal access.

Customizing admin credentials with Vault

version 46x From IBM Cloud PakĀ® foundational services version 4.6.20 and onward, you can fetch custom admin credentials directly from HashiCorp Vault by using the Secrets Store CSI Driver. The ibm-opensearch-operator operator generates a default password for the admin user, admin:password. However, you can override this behavior by configuring Vault integration and specifying your own custom credentials that are stored in Vault.

Configuring and enabling audit logging

version 46x From foundational services version 4.6.19 and onward, you can configure and enable audit logging in OpenSearch with a sidecar container. The sidecar converts audit logs into the Cloud Auditing Data Federation (CADF) format and optionally forwards them to the Zen audit service.

Enable forwarding to Zen according to your audit logging requirements. If your requirement is for OpenSearch audit logs to be generated in the CADF format and forwarded to Zen, similar to other platform components, enable this feature. This feature is for environments where centralized audit collection through Zen is required, and OpenSearch audit events must conform to the CADF standard.

  1. Enable the webhook audit configuration in the opensearchyml section.
  2. Enable the audit sidecar in the audit section. In your OpenSearch CR YAML file, add the following parameter details under the spec.nodePools section.
    • Use the opensearchyml section to configure OpenSearch to send audit logs with the webhook. Replace the <CR_NAME> value with your cluster and the <NAMESPACE_NAME> value with your namespace.
    • Set the audit.enabled value to true to create and enable the audit sidecar container.
    • Set the audit.forwardToZen value to true if you want the sidecar to forward CADF audit logs to the Zen service.
    • The audit.resources value defines CPU and memory requests and limits for the audit sidecar container.
    • The audit.zenAuditURL Zen endpoint forwards the logs when the forwardToZen value is enabled.
    • The audit.zenSecretName value is the name of the Kubernetes Secret that contains the Zen token.
    apiVersion: opensearch.cloudpackopen.ibm.com/v1
    kind: Cluster
    metadata:
      name: opensearch-cr
      namespace: <namespace>
      ...
    spec:
      ...
      nodePools:
        ...
        opensearchyml: |
          plugins.security.audit.type: webhook
          plugins.security.audit.config.webhook.url: "http://<CR_NAME>.<NAMESPACE_NAME>.svc.cluster.local:8085/audit"
          plugins.security.audit.config.webhook.format: JSON
          plugins.security.audit.config.webhook.ssl.verify: false
        ...
        audit:
          enabled: true
          forwardToZen: <true/false>
          resources:
            limits:
              cpu: 200m
              memory: 256Mi
            requests:
              cpu: 50m
              memory: 64Mi
          zenAuditURL: '<ZEN_AUDIT_URL>'
          zenSecretName: <ZEN_TOKEN_SECRET_NAME>
  3. If forwarding to Zen is enabled, create a Kubernetes Secret with the Zen token.
    kind: Secret
    apiVersion: v1
    metadata:
      name: <zen-audit-token-secret_name>
      namespace: <NAMESPACE>
    data:
      token: <ZEN_TOKEN in Base64 format>
    type: Opaque

Enabling custom Log4j logging with rotation

For custom logging and log file management, configure a custom log4j2.properties file to enable OpenSearch log rotation.

  1. Create a ConfigMap with your custom log4j2.properties file.

    The following configuration enables daily log rotation. If a file exceeds 1 MB, a maximum of two files are retained. Excess logs are automatically deleted if the total size exceeds 2 GB.

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: log4j-rotation-config
      namespace: <namespace>
    data:
      log4j2.properties: |-
        status = error
    
        # Console appender
        appender.console.type = Console
        appender.console.name = console
        appender.console.layout.type = PatternLayout
        appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %m%n
    
        # Rolling file appender
        appender.rolling.type = RollingFile
        appender.rolling.name = rolling
        appender.rolling.fileName = logs/opensearch.log
        appender.rolling.filePattern = logs/opensearch-%d{yyyy-MM-dd}-%i.log.gz
        appender.rolling.layout.type = PatternLayout
        appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %m%n
    
        appender.rolling.policies.type = Policies
        appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
        appender.rolling.policies.time.interval = 1
        appender.rolling.policies.time.modulate = true
        appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
        appender.rolling.policies.size.size = 1MB
    
        appender.rolling.strategy.type = DefaultRolloverStrategy
        appender.rolling.strategy.max = 2
        appender.rolling.strategy.fileIndex = nomax
        appender.rolling.strategy.action.type = Delete
        appender.rolling.strategy.action.basepath = logs
        appender.rolling.strategy.action.condition.type = IfAccumulatedFileSize
        appender.rolling.strategy.action.condition.exceeds = 2GB
    
        # Root logger
        rootLogger.level = info
        rootLogger.appenderRef.console.ref = console
        rootLogger.appenderRef.rolling.ref = rolling
  2. Reference the ConfigMap in the OpenSearch CR. Disable the default Log4j configuration mount and mount your custom ConfigMap.
    apiVersion: opensearch.cloudpackopen.ibm.com/v1
    kind: Cluster
    metadata:
      name: opensearch-cr
      namespace: <namespace>
      ...
    spec:
      ...
      nodePools:
        - disableConfigMounts:
            log4j: true  # Disable the default Log4j ConfigMap mounting with the operator.
          ...
          addConfigmaps:
            - location: /workdir/opensearch/config/log4j2.properties
              name: log4j-rotation-config    # Add your custom Log4j ConfigMap.
              subPath: log4j2.properties
    ...

Enabling custom JVM options

For workload-specific JVM tuning or for troubleshooting, override default JVM options with your own jvm.options file in the OpenSearch cluster that is deployed with the IBM OpenSearch operator.

  1. Create a ConfigMap with your custom JVM options.
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: jvm-custom-config
      namespace: <namespace>
    data:
      jvm.options: |-
        -Xms4g
        -Xmx4g
        -XX:+UseG1GC
        -XX:InitiatingHeapOccupancyPercent=75
        ...
  2. Reference the custom JVM options in the CR. Like with the log4j2.properties file, disable the default jvm.options file and mount your custom file.
    apiVersion: opensearch.cloudpackopen.ibm.com/v1
    kind: Cluster
    metadata:
      name: opensearch-cr
      namespace: <namespace>
      ...
    spec:
      ...
      nodePools:
        - name: all
          disableConfigMounts:
            jvmOptions: true    # Disable the default jvmOptions ConfigMap mounting with the operator.
          addConfigmaps:
            - name: jvm-custom-config
              location: /workdir/opensearch/config/jvm.options    # Add your custom jvm.options ConfigMap.
              subPath: jvm.options
    ...

Configuring the plugins.security.ssl.http.clientauth_mode setting

The plugins.security.ssl.http.clientauth_mode parameter controls whether OpenSearch requires client certificates during HTTP connections that are used by REST APIs. Use this setting to enable mutual Transport Layer Security (mTLS) authentication for REST.

For more information about TLS client authentication modes, see Client authentication Opens in a new tab.

Note:

Changing the plugins.security.ssl.http.clientauth_mode setting dynamically, such as while the cluster is running, is not supported. During certificate reconciliation, the HTTP layer might temporarily reject incoming SSL connections from other pods that did not yet receive the updated configuration. PodInitialize errors might occur and affect the <CR>-000 pod during startup.

Instead of changing the plugins.security.ssl.http.clientauth_mode setting dynamically, set it to NONE, OPTIONAL, or REQUIRE in a fresh deployment.

Setting the plugins.security.ssl.http.clientauth_mode parameter to NONE

If the plugins.security.ssl.http.clientauth_mode parameter is not provided in the CR in the opensearch.yml section, the parameter defaults to NONE, and no client certificate is required.

apiVersion: opensearch.cloudpackopen.ibm.com/v1
kind: Cluster
  ...
  name: opensearch-cr
spec:
  ...
  plugins:
    ...
    security:
      enabled: true
      version: 2.19.1.0   # Use the latest plug-in version based on your OpenSearch version.
      httpCertificateSecret: route-cert-secret   # Use the secret name that was created from the custom certificate for the reencrypted route.
  nodePools:
    - name: "all"
      replicas: 3
      opensearchyml: |
        plugins.security.ssl.http.enabled: true
        plugins.security.allow_default_init_securityindex: true
        http.compression: false
        plugins.security.ssl.http.clientauth_mode: NONE
...

Setting the plugins.security.ssl.http.clientauth_mode parameter to OPTIONAL or REQUIRE

If you want to set the plugins.security.ssl.http.clientauth_mode parameter to OPTIONAL or REQUIRE, create a custom certificate and configure the httpCertificateSecret parameter.

  1. Create an issuer for a custom certificate.
    apiVersion: cert-manager.io/v1
    kind: Issuer
    metadata:
      name: custom-opensearch-issuer   # Mention the same name in the certificate issuerRef value.
      namespace: <namespace>
    spec:
      selfSigned: {}   # This example shows a selfSigned issuer, but you can change this value according to your requirement.
  2. Create a custom certificate.
    apiVersion: cert-manager.io/v1
    kind: Certificate
    metadata:
      name: route-cert
      namespace: <namespace>
    spec:
      secretName: route-cert-secret   # Enter the secret name to be used in the httpCertificateSecret parameter.
      duration: 2160h
      renewBefore: 360h
      commonName: opensearch-cr   # Enter your CR name.
      dnsNames:
        - '*.cluster.local'
        - '*.svc.cluster.local'
        - <cr-name>.cluster.local
        - <cr-name>.svc.cluster.local
        - '*.apps.<cluster-name>.<domain-name>'   # An example domain name is cp.fyre.ibm.com
        - '*.<cr-name>'
        - <cr-name>.<namespace>.svc
        - '*.<cr-name>.<namespace>.svc'
        - <cr-name>.<namespace>.svc.cluster.local
        - '*.<cr-name>.<namespace>.svc.cluster.local'
      privateKey:
        algorithm: RSA
        encoding: PKCS8   # This value is for the private.key in Public-Key Cryptography Standards (PKCS) #8 format encoding.
        size: 2048
      usages:
        - digital signature
        - key encipherment
        - server auth
        - client auth
      issuerRef:
        kind: Issuer
        name: custom-opensearch-issuer   # Replace this value with your self-signed issuer.
  3. Configure your secret into the CR.
    apiVersion: opensearch.cloudpackopen.ibm.com/v1
    kind: Cluster
      ...
      name: ibm-opensearch-cr
    spec:
      ...
      plugins:
        ...
        security:
          enabled: true
          version: 2.19.1.0   # Use the latest plug-in version based on your OpenSearch version.
          httpCertificateSecret: route-cert-secret   # The secret name that was created from the custom certificate for the reencrypted route.
    ...
  4. Use certificate details in route creation. When you create the route after cluster CR deployment, place your certificate, private key, certificate authority (CA) certificate, and destination CA certificate by using the ca.crt and tls.crt certificates and tls.key key from the route-cert-secret secret. The OpenSearch route is reencrypted.

After you create a custom certificate and configure the httpCertificateSecret parameter, update the CR with the custom certificate and set the plugins.security.ssl.http.clientauth_mode parameter to OPTIONAL or REQUIRE.

  • The following example shows the parameter set to OPTIONAL:
    apiVersion: opensearch.cloudpackopen.ibm.com/v1
    kind: Cluster
      ...
      name: opensearch-cr
    spec:
      ...
      plugins:
        ...
        security:
          enabled: true
          version: 2.19.1.0   # Use the latest plug-in version based on your OpenSearch version.
          httpCertificateSecret: route-cert-secret   # Enter the secret name that was created from the custom certificate for the reencrypted route.
      nodePools:
        - name: "all"
          replicas: 3
          opensearchyml: |
            plugins.security.ssl.http.enabled: true
            plugins.security.allow_default_init_securityindex: true
            http.compression: false
            plugins.security.ssl.http.clientauth_mode: OPTIONAL
    ...
  • The following example shows the parameter set to REQUIRE:
    apiVersion: opensearch.cloudpackopen.ibm.com/v1
    kind: Cluster
      ...
      name: opensearch-cr
    spec:
      ...
      plugins:
        ...
        security:
          enabled: true
          version: 3.2.0.0   # Use the latest plug-in version based on your OpenSearch version.
          httpCertificateSecret: route-cert-secret   # Enter the secret name that was created from the custom certificate for the reencrypted route.
      nodePools:
        - name: "all"
          replicas: 3
          opensearchyml: |
            plugins.security.ssl.http.enabled: true
            plugins.security.allow_default_init_securityindex: true
            http.compression: false
            plugins.security.ssl.http.clientauth_mode: REQUIRE
    ...

If you set the plugins.security.ssl.http.clientauth_mode parameter to OPTIONAL or REQUIRE, pass certificates to access OpenSearch with a passthrough route:

% curl --cert tls.crt --key tls.key --cacert ca.crt https://<opensearch-route-url>.apps.<cluster-name>.<domain-name>   # An example domain name is cp.fyre.ibm.com
{
  "name" : "opensearch-cr-all-001",
  "cluster_name" : "opensearch-cr",
  "cluster_uuid" : "pegCpeJmQMmSwl0fZGnclQ",
  "version" : {
    "distribution" : "opensearch",
    "number" : "2.19.1",
    "build_type" : "tar",
    "build_hash" : "2e4741fb45d1b150aaeeadf66d41445b23ff5982",
    "build_date" : "2025-03-28T21:37:46.902666262Z",
    "build_snapshot" : false,
    "lucene_version" : "9.12.1",
    "minimum_wire_compatibility_version" : "7.10.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "The OpenSearch Project: https://opensearch.org/"
}