Rotating the Load Balancer TLS Certificate

To rotate the OCI Load Balancer TLS certificate for ingress-nginx:

  1. Set the following environment variables:

    export ROTATE_NS='<siebel-namespace>'
    export ROTATE_ENV_ID='<scm-environment-id>'
    export ROTATE_HOST='<public-dns-name>'
    export CERT_DIR='<tls-certificate-directory>'
    export ROTATE_CERT="$CERT_DIR/tls.crt"
    export ROTATE_KEY="$CERT_DIR/tls.key"
    export ROTATE_NEW_SECRET="lb-tls-certificate-$(date -u +%Y%m%d%H%M%S)"
    export ROTATE_REPO='/home/opc/siebel/<env-id>/<scm-repo>'
    export ROTATE_FLUX_FOLDER='flux-crm'

    In the above commands:

    • Replace the placeholders with the values for your deployment.

    • Set ROTATE_NEW_SECRET to a new, versioned Kubernetes Secret name. Do not reuse the current secret name.

  2. Use ROTATE_FLUX_FOLDER from step 1 to derive the configuration paths:

    export ROTATE_NGINX_REL="${ROTATE_FLUX_FOLDER}/infrastructure/nginx"
    export ROTATE_SECRET_REL="${ROTATE_FLUX_FOLDER}/infrastructure/${ROTATE_NS}/oci-lb-ssl-certificate-secret.yaml"
    export ROTATE_NGINX_DIR="${ROTATE_REPO}/${ROTATE_NGINX_REL}"
    export ROTATE_SECRET_FILE="${ROTATE_REPO}/${ROTATE_SECRET_REL}"
  3. Verify the cluster and reconciliation state:

    kubectl config current-context
    kubectl -n "$ROTATE_NS" get helmrelease.helm.toolkit.fluxcd.io nginx
    kubectl -n "$ROTATE_NS" get kustomization.kustomize.toolkit.fluxcd.io infrastructure
    kubectl -n "$ROTATE_NS" get helmrelease.helm.toolkit.fluxcd.io traefik

    Verify that:

    • The NGINX Helm release and infrastructure Kustomization are ready.

    • The Traefik lookup returns NotFound.

  4. Derive the Helm release and service names:

    export ROTATE_RELEASE="$(kubectl -n "$ROTATE_NS" get helmrelease.helm.toolkit.fluxcd.io nginx -o jsonpath='{.spec.releaseName}')"
    export ROTATE_SVC="${ROTATE_RELEASE}-controller"
    kubectl -n "$ROTATE_NS" get service "$ROTATE_SVC" -o wide

    For an SCM 26.2 deployment with the default configuration, the Helm release name is <namespace>-ingress-nginx, and the Kubernetes Service name is <namespace>-ingress-nginx-controller.

  5. Verify the existing TLS configuration:

    1. Read the current secret name from the service annotation:

      export ROTATE_OLD_SECRET="$(kubectl -n "$ROTATE_NS" get service "$ROTATE_SVC" -o go-template='{{index .metadata.annotations "service.beta.kubernetes.io/oci-load-balancer-tls-secret"}}')"
      kubectl -n "$ROTATE_NS" get service "$ROTATE_SVC" -o go-template='type={{.spec.type}}{{"\n"}}sslPorts={{index .metadata.annotations "service.beta.kubernetes.io/oci-load-balancer-ssl-ports"}}{{"\n"}}tlsSecret={{index .metadata.annotations "service.beta.kubernetes.io/oci-load-balancer-tls-secret"}}{{"\n"}}'
      kubectl -n "$ROTATE_NS" get service "$ROTATE_SVC" -o jsonpath='{range .spec.ports[*]}{.name}{"="}{.port}{"->"}{.targetPort}{"\n"}{end}'
      kubectl -n "$ROTATE_NS" get secret "$ROTATE_OLD_SECRET" -o jsonpath='{.type}{"\n"}'

      You must continue only when:

      • The service type is LoadBalancer.

      • The SSL ports include 443.

      • The TLS Secret annotation contains a secret name.

      • The HTTPS Service port targets NGINX HTTP.

      • The existing secret type is kubernetes.io/tls.

      • The new secret lookup returns NotFound.

    2. Confirm that the proposed name is unused:

      kubectl -n "$ROTATE_NS" get secret "$ROTATE_NEW_SECRET"

      If the proposed secret already exists, choose another name.

  6. Record the following:

    1. The existing Kubernetes Service and OCI Load Balancer details:

      export ROTATE_UID_BEFORE="$(kubectl -n "$ROTATE_NS" get service "$ROTATE_SVC" -o jsonpath='{.metadata.uid}')"
      export ROTATE_CLUSTER_IP_BEFORE="$(kubectl -n "$ROTATE_NS" get service "$ROTATE_SVC" -o jsonpath='{.spec.clusterIP}')"
      export ROTATE_LB_ADDR_BEFORE="$(kubectl -n "$ROTATE_NS" get service "$ROTATE_SVC" -o jsonpath='{.status.loadBalancer.ingress[0].ip}{.status.loadBalancer.ingress[0].hostname}')"
      
      printf 'serviceUID=%s\nclusterIP=%s\nexternalAddress=%s\n' \
        "$ROTATE_UID_BEFORE" "$ROTATE_CLUSTER_IP_BEFORE" "$ROTATE_LB_ADDR_BEFORE"
    2. The OCI Load Balancer OCID from OCI Console or OCI CLI. These values must remain unchanged after rotation.

    3. The current certificate fingerprint, from a host that can reach the endpoint:

      openssl s_client -connect "${ROTATE_HOST}:443" \
        -servername "$ROTATE_HOST" </dev/null 2>/dev/null |
        openssl x509 -noout -fingerprint -sha256 -subject -issuer -serial -dates
    4. The expected HTTP status or authentication response for each enabled application, SMC, Prometheus, and OpenSearch Dashboards URL.

  7. Validate the replacement certificate and private key:

    openssl x509 -in "$ROTATE_CERT" -noout \
      -fingerprint -sha256 -subject -issuer -serial -dates -ext subjectAltName
    openssl x509 -in "$ROTATE_CERT" -noout -checkend 0
    openssl pkey -in "$ROTATE_KEY" -check -noout
  8. Compare the public-key hashes. Both commands must return the same hash:

    openssl x509 -in "$ROTATE_CERT" -pubkey -noout |
      openssl pkey -pubin -outform DER 2>/dev/null |
      openssl dgst -sha256
    
    openssl pkey -in "$ROTATE_KEY" -pubout -outform DER 2>/dev/null |
      openssl dgst -sha256

    Verify that:

    • The Subject Alternative Name (SAN) covers every externally exposed host name.

    • The certificate is currently valid and meets your organization’s remaining-validity requirements.

    • The certificate file contains the leaf certificate first, followed by the required intermediate certificates.

    • Only the operator can read the private key and temporary files.

    If the key is encrypted:

    1. Create a temporary directory with mode 0700, set umask 077, and decrypt the key interactively with openssl pkey. Do not put the password in a command-line argument or shell history.

    2. Set ROTATE_KEY to the path of the protected, decrypted private-key file.

    3. Remove the file after you complete verification and meet the rollback retention requirements.

  9. Synchronize the generated Git repository:

    cd "$ROTATE_REPO"
    git status --short
    export ROTATE_BRANCH="$(git branch --show-current)"
    git fetch origin "$ROTATE_BRANCH"
    git pull --ff-only origin "$ROTATE_BRANCH"
    export ROTATE_PARENT="$(git rev-parse HEAD)"

    If the working copy contains changes, the branch name is empty, or the pull cannot fast-forward, resolve the issue before continuing. Verify that the revision applied by Flux matches the recorded parent commit:

    kubectl -n "$ROTATE_NS" get \
      kustomization.kustomize.toolkit.fluxcd.io infrastructure \
      -o jsonpath='{.status.lastAppliedRevision}{"\n"}'
  10. Prepare the replacement secret manifest. Create a protected temporary directory and generate the manifest without applying it:

    umask 077
    export ROTATE_TMP="$(mktemp -d /tmp/scm-262-cert-rotation.XXXXXX)"
    chmod 700 "$ROTATE_TMP"
    
    kubectl -n "$ROTATE_NS" create secret tls "$ROTATE_NEW_SECRET" \
    --cert="$ROTATE_CERT" --key="$ROTATE_KEY" \
    --dry-run=client -o yaml > "$ROTATE_TMP/new-secret.yaml"
    
    export ROTATE_ENV_LABEL="$(kubectl -n "$ROTATE_NS" get secret "$ROTATE_OLD_SECRET" -o jsonpath='{.metadata.labels.oracle\.siebel\.namespace-envid}')"
    test -n "$ROTATE_ENV_LABEL"

    If ROTATE_ENV_LABEL is empty, verify that ROTATE_NS specifies the correct namespace and ROTATE_OLD_SECRET specifies the existing TLS Secret in that namespace. Make sure that the secret has the oracle.siebel.namespace-envid label. After resolving the issue, retrieve the label again. Continue only when ROTATE_ENV_LABEL contains the correct environment label value.

    kubectl label --local -f "$ROTATE_TMP/new-secret.yaml" \
    "oracle.siebel.namespace-envid=$ROTATE_ENV_LABEL" \
    --overwrite -o yaml > "$ROTATE_TMP/new-secret-labelled.yaml"
    Note: The manifest contains private-key data. Do not print it, display its diff, or attach it to a support ticket.
  11. Update and commit the generated configuration:

    1. Use a YAML-aware editor to make the following changes:

      • In ${ROTATE_NGINX_DIR}/release.yaml, update spec.values.controller.service.annotations["service.beta.kubernetes.io/oci-load-balancer-tls-secret"] to the new secret name. Preserve all other annotations.

      • In each existing ${ROTATE_NGINX_DIR}/siebel-ingress-*.yaml file, replace references to the old secret under spec.tls[].secretName with the new secret. Include application, SMC, and enabled observability ingress definitions.

      • Replace ${ROTATE_SECRET_FILE} with ${ROTATE_TMP}/new-secret-labelled.yaml.

      SCM stores the generated secret manifest in its private repository. Flux does not apply manifests in this namespace directory during normal reconciliation, so you must create the secret in the cluster in the next step.

    2. Review the non-secret changes and affected filenames:

      git diff -- "$ROTATE_NGINX_REL/release.yaml" \
        "$ROTATE_NGINX_REL"/siebel-ingress-*.yaml
      git diff --stat
      git diff --check
      git status --short
    3. Verify that no active NGINX reference points to the old secret. Commit the changes locally:

      git add "$ROTATE_NGINX_REL" "$ROTATE_SECRET_REL"
      git diff --cached --check
      git diff --cached --name-only
      git commit -m "Rotate ingress TLS certificate to ${ROTATE_NEW_SECRET}"
      export ROTATE_COMMIT="$(git rev-parse HEAD)"
      Note: Do not push the commit yet.
  12. Create and verify the new secret:

    1. Create new secret:

      kubectl apply -f "$ROTATE_TMP/new-secret-labelled.yaml"
      kubectl -n "$ROTATE_NS" get secret "$ROTATE_NEW_SECRET" \
        -o jsonpath='{.metadata.uid}{" "}{.type}{"\n"}'
    2. Verify that the fingerprint matches the replacement certificate. Retrieve only the public certificate; do not retrieve .data.tls.key.

      kubectl -n "$ROTATE_NS" get secret "$ROTATE_NEW_SECRET" \
        -o jsonpath='{.data.tls\.crt}' |
        openssl base64 -d -A |
        openssl x509 -noout -fingerprint -sha256 -subject -issuer -dates
    3. Verify that the fingerprint matches the input certificate. At this stage, no resource references the new secret, so existing traffic remains unchanged.

  13. Publish the commit and reconcile the existing service.

    1. Verify that the remote branch still matches the recorded parent:

      git fetch origin "$ROTATE_BRANCH"
      test "$(git rev-parse "origin/$ROTATE_BRANCH")" = "$ROTATE_PARENT"

      If the comparison fails, resolve the Git changes before continuing. Do not force-push or patch the Service directly.

    2. Publish the prepared commit:

      git push origin "HEAD:$ROTATE_BRANCH"
    3. Allow Flux and Helm to update the existing service. Do not suspend Flux or replace the service:

      flux reconcile kustomization infrastructure -n "$ROTATE_NS" \
        --with-source --timeout=30m
      flux reconcile helmrelease nginx -n "$ROTATE_NS" --timeout=30m
      kubectl -n "$ROTATE_NS" wait \
        helmrelease.helm.toolkit.fluxcd.io/nginx \
        --for=condition=Ready --timeout=30m
  14. Verify that the endpoint serves the replacement certificate:

    kubectl -n "$ROTATE_NS" get service "$ROTATE_SVC" \
      -o go-template='{{index .metadata.annotations "service.beta.kubernetes.io/oci-load-balancer-tls-secret"}}{{"\n"}}'
    
    kubectl -n "$ROTATE_NS" get events \
      --field-selector "involvedObject.kind=Service,involvedObject.name=$ROTATE_SVC" \
      --sort-by=.lastTimestamp

    The OCI Cloud Controller Manager updates the existing load balancer listener asynchronously. Check the served fingerprint at controlled intervals until it matches the replacement certificate:

    openssl s_client -connect "${ROTATE_HOST}:443" \
      -servername "$ROTATE_HOST" </dev/null 2>/dev/null |
      openssl x509 -noout -fingerprint -sha256 -subject -issuer -serial -dates

    If the approved timeout expires, perform the rollback procedure. Do not delete the service or change only the listener in OCI Console. For more information, see Rolling Back the Certificate Change.

  15. Verify that the service and load balancer remain unchanged:

    export ROTATE_UID_AFTER="$(kubectl -n "$ROTATE_NS" get service "$ROTATE_SVC" -o jsonpath='{.metadata.uid}')"
    export ROTATE_CLUSTER_IP_AFTER="$(kubectl -n "$ROTATE_NS" get service "$ROTATE_SVC" -o jsonpath='{.spec.clusterIP}')"
    export ROTATE_LB_ADDR_AFTER="$(kubectl -n "$ROTATE_NS" get service "$ROTATE_SVC" -o jsonpath='{.status.loadBalancer.ingress[0].ip}{.status.loadBalancer.ingress[0].hostname}')"
    
    test "$ROTATE_UID_AFTER" = "$ROTATE_UID_BEFORE"
    test "$ROTATE_CLUSTER_IP_AFTER" = "$ROTATE_CLUSTER_IP_BEFORE"
    test "$ROTATE_LB_ADDR_AFTER" = "$ROTATE_LB_ADDR_BEFORE"

    Verify that the OCI Load Balancer OCID also matches the recorded value. Check the enabled URLs against their recorded HTTP status or authentication responses.