Skip to content

How Secret Rotation Works

This feature was introduced in Hydrolix version 6.6.

The Hydrolix operator runs each secret rotation itself, not as a separate job. It runs copies of the init jobs to apply the new values, and a job failure or an upgrade at that stage triggers a revert. Then it restarts the workloads that use the new values.

The Hydrolix operator generates the passwords and keys that the cluster's services use to reach each other and stores them in the general Kubernetes secret. Secret rotation replaces most of these values at a time set in the secret_rotation tunable. The operator applies each new value to the service that owns it before it writes anything to general, so a failure before that point leaves the cluster on its current values. To schedule a rotation, see Rotate Cluster Secrets.

Rotated keys⚓︎

A rotation replaces every key the operator generates, except the keys listed in Keys that are never rotated.

Keys that are rotated⚓︎

  • The database password for each Hydrolix service, and for Grafana, Superset, and Keycloak
  • KEYCLOAK_ADMIN_PASSWORD and KEYCLOAK_REALM_ADMIN_PASSWORD, the Keycloak administrator passwords
  • KEYCLOAK_CLIENT_SECRET_KEY, the secret turbine-api and Superset use to authenticate to Keycloak
  • GRAFANA_ADMIN_PASSWORD and SUPERSET_ADMIN_PASSWORD, the admin sign-in passwords
  • DJANGO_SECRET_KEY, the Django secret key for turbine-api
  • GRAFANA_RENDERER_TOKEN, CONFIG_CACHE_S3PROXY_PASSWORD, and LITELLM_MASTER_KEY

Keys the operator doesn't generate are never rotated.

Keys in the curated secret⚓︎

The curated secret holds values supplied for the cluster. The operator copies them into general and treats them as owned by the cluster administrator. A key present in curated is never rotated, whichever group it belongs to. Removing a key from curated returns it to rotation at the next rotation.

Keys that are never rotated⚓︎

The operator never rotates these keys:

  • ADMIN_USER_PASSWORD, the initial password of the first Hydrolix administrator. It belongs to that person after their first sign-in.
  • DB_ENCRYPTION_PASSWORD, the passphrase that encrypts catalog database backups. Existing backups still need the old value.
  • ELASTICSEARCH_PASSWORD, used by the Kibana stack. It might belong to a user on a customer's own Elasticsearch.
  • LITELLM_SALT_KEY
  • RABBITMQ_COOKIE, shared by every RabbitMQ node. Changing it requires stopping all RabbitMQ nodes at once.
  • ROOT_DB_PASSWORD, the PostgreSQL superuser password. The init-cluster job uses it to change every other database password.
  • SERVICE_ACCOUNT_PRIVATE_KEY and SERVICE_ACCOUNT_PUBLIC_KEY, the key pair that signs and verifies every service account token. Changing it invalidates all existing tokens.
  • SUPERSET_SECRET_KEY, which encrypts the connection secrets Superset stores. Changing it without re-encrypting them makes every stored connection unusable. It's separate from SUPERSET_ADMIN_PASSWORD, which is rotated.
  • TRAEFIK_PASSWORD, the password for HTTP basic authentication, which external clients use. See the basic_auth tunable.
  • VK_SECRET_SALT

Because the service account key pair isn't rotated, existing service account tokens remain valid after a rotation.

Phases⚓︎

The operator checks the schedule every 15 seconds. A rotation starts once the at time has passed, the cluster status is Ready, and no other rotation is in progress. It then moves through these phases:

  1. stage: The operator generates new values for the rotated keys and writes them to a separate secret, general-next. general is unchanged.
  2. init-cluster: A rotation copy of the init-cluster job reads the staged values and sets the new database role passwords.
  3. init-turbine-api: A rotation copy of the init-turbine-api job reads the staged values and applies the new Keycloak passwords and client secret.
  4. promoting: The operator writes the staged values into general in one update, then deletes general-next and any general backup secrets. After this phase, a rotation can't revert. See Effects during a rotation and Failure and revert.
  5. restarting: The operator restarts the workloads that read a changed key.
  6. complete: Every restarted workload is ready, and the operator deletes the rotation jobs.

A rotation copy is a separate Job, built from the cluster's own init-cluster or init-turbine-api job, that reads the rotated keys from general-next instead of general. It carries the hdx_secret_rotation label, runs each step once, and stops at the first error. Running services don't read general-next. They keep their current values until the restarting phase restarts them.

Each at value starts one rotation. A later at is required to rotate again, including after a failure. An at earlier than the cluster's creation time is ignored, so a specification copied from another cluster doesn't rotate a new cluster.

Timeout⚓︎

The timeout setting, 30m by default, limits how long each of the init-cluster, init-turbine-api, and reverting phases can take. The promoting and restarting phases have no time limit.

Failure and revert⚓︎

Failures are unlikely, and most of them leave the cluster on its current values. A rotation can revert only before the promoting phase. A revert works by running the init jobs again against the values in general. Until promoting, general still holds the previous values, so a revert can restore them. promoting replaces those values and deletes the staged and backup copies, so no previous values remain to revert to.

Revert before promoting⚓︎

The rotation reverts when one of these happens in the init-cluster or init-turbine-api phase:

  • A rotation job fails.
  • The phase exceeds timeout.
  • The init jobs change, because of a Hydrolix upgrade or a specification change that alters them.

The operator runs both init jobs again against the values in general, then deletes general-next. The phase becomes rolled-back. general is unchanged, and no workload restarts. To try again, set a later at.

Failed revert⚓︎

If the revert itself fails or exceeds timeout, the phase becomes failed. general holds the previous values, and running workloads haven't restarted, but the databases and Keycloak might hold the new values, the previous values, or a mix. The operator leaves general-next and the rotation jobs in place for inspection, and the error field in the rotation status gives the reason.

To recover, return every service to the values in general:

  1. Read the rotation job logs to find the cause.

    List the Rotation Jobs
    kubectl get jobs -l hdx_secret_rotation
    
  2. Delete the rotation jobs and the staged secret.

    Delete the Rotation Jobs and Staged Secret
    kubectl delete jobs -l hdx_secret_rotation
    kubectl delete secret general-next
    
  3. Delete the init-cluster job. The operator recreates it, and the new run sets every database password back to its value in general.

  4. After the init-cluster job finishes, delete the init-turbine-api job the same way, so Keycloak returns to the values in general.
  5. Confirm the cluster's workloads are healthy, then set a later at to rotate again.

After promoting⚓︎

After promoting, a rotation can't revert. If writing general fails, the operator retries every 15 seconds. In the restarting phase, the operator waits for every restarted workload to become ready, with no time limit. A workload that never becomes ready keeps the rotation in restarting, and because at most five workloads restart at a time, it can delay the rest. The operator holds the restarts on purpose, rather than restarting more workloads into a broken state. To find the stuck workload, look for one whose kubectl.kubernetes.io/restartedAt annotation matches the rotation's phaseStartedAt but isn't ready. Fix it like any failed rollout, and the restarts continue within 15 seconds.

Restarts⚓︎

The operator restarts each Deployment, StatefulSet, and DaemonSet that reads a changed key from general. It restarts at most five workloads at a time, and starts with turbine-api, keycloak, grafana, and superset. The rotation completes when every restarted workload is ready.

postgres and rabbitmq aren't restarted, because they read general only when they first start. CronJobs pick up new values on their next run.

The same restart applies to any change to general outside a rotation. The operator detects these changes while it's running. A change made while the operator is stopped isn't detected, and the affected workloads need a manual restart.

Effects during a rotation⚓︎

Effects start in the init-cluster phase and end as each workload restarts in the restarting phase.

  • Database connections. After the init-cluster phase sets the new database passwords, workloads that haven't restarted yet still hold the previous passwords and can't open new database connections until they restart. Existing connections continue to work.
  • Sign-in. After the init-turbine-api phase applies the new Keycloak client secret, sign-in can fail until turbine-api and keycloak restart.
  • Grafana and Superset. The admin passwords change to the new values in general. Both services reset the admin password from general each time they start.
  • Service account tokens. Tokens remain valid.

Status and metrics⚓︎

The rotation's state is in the status.secretRotation field of the HydrolixCluster resource:

Field Value
phase Current phase
generation Count of rotations started on the cluster
keys Keys the rotation changes
requestedAt The at value the rotation started from
startedAt, phaseStartedAt, completedAt When the rotation, the current phase, and the rotation ended
error Reason for a revert or failure

The o6r_hdx_secret_rotation_phase metric reports the phase as a gauge with a phase label. The current phase is 1, and every other phase is 0. Phase values are idle, init-cluster, init-turbine-api, promoting, restarting, complete, reverting, rolled-back, and failed. The idle value appears only in the metric, before the first rotation.

Rotation jobs carry the hdx_secret_rotation label, and the operator log marks each step with secret rotation <generation>:.