Skip to content

Reference Secrets

ConfigHub is not a secret manager, and secret values don't belong in it. A Unit's data can be read by anyone with View on it, stays in every Revision of the Unit's history, and is bundled into Releases that operators pull. Keep the values where you keep them now, in a secret manager such as AWS Secrets Manager or Parameter Store, Vault, or a cloud's key vault, and keep the references to them in ConfigHub: which Secret a workload reads, and which keys in the secret manager fill it. Those references are ordinary configuration, changed, reviewed and released like any other. See Secrets for the background.

Referencing a secret with the External Secrets Operator

The External Secrets Operator runs in the cluster, reads values from a secret manager, and writes them into Kubernetes Secrets. The configuration in ConfigHub is an ExternalSecret that names the secret manager's keys and the Secret to create, and a workload that reads that Secret as usual:

apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
  name: backend-db
  namespace: app
spec:
  refreshInterval: 1h
  secretStoreRef:
    kind: ClusterSecretStore
    name: aws-parameter-store
  target:
    name: backend-db
  data:
  - secretKey: password
    remoteRef:
      key: /prod/backend/db-password
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend
  namespace: app
spec:
  template:
    spec:
      containers:
      - name: backend
        env:
        - name: DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: backend-db
              key: password

The ClusterSecretStore says how to reach the secret manager. It is set up once per cluster, usually by the team that runs the cluster, and can be a Unit in the cluster's Space like the operator itself. Give the operator access to the secret manager with the cloud's workload identity, such as IAM Roles for Service Accounts on EKS, rather than with a credential stored in another Secret. The Secrets Store CSI Driver works the same way, with a SecretProviderClass that names the keys and is mounted as a volume.

A different key in each environment

Each environment usually reads its own keys. Write the part that varies as a named placeholder in the base, and fill it in each variant:

      remoteRef:
        key: /confighubplaceholderenv/backend/db-password
cub function set --space backend-prod --where "Slug = 'backend-db-externalsecret'" \
    --change-desc "Read prod's parameters" -- search-replace confighubplaceholderenv prod

The vet-placeholders function finds a placeholder left anywhere in a value, so a variant whose keys haven't been filled in can't be released to a cluster connected with cub cluster attach, whose no-placeholders Trigger runs it. The basic guardrail group checks the same on any Space it is installed in.

A Secret's name can be a placeholder too, such as the secretName of a volume that set-container-volume-mount-path adds with secret as its source. Needs/Provides doesn't fill it, since the Secret it would come from isn't in ConfigHub, so set it in the base, or in each variant as above.

Secrets in what you bring in

Configuration you bring into ConfigHub often comes with Secrets in it. None of them are stored:

  • cub variant upload and cub helm install leave out every Secret they are given, and list the ones they left out, to apply to the cluster another way.
  • cub package install keeps the Secrets a package renders, such as a bot's credentials, in a local directory that it names when the install finishes, rather than removing them with the rest of its working files. See Install Packages.
  • cub cluster attach applies the credentials it creates, the operator's pull token and k8sbot's key, straight to the cluster. --secrets-dir writes them to a directory instead, for you to load into a secret store, and --existing-secrets uses the ones the store keeps in the cluster. See Credentials from a secret store.

A Secret left out of an upload is still referenced by the workloads that read it, and the upload lists those references as ones it couldn't resolve. Put the values in your secret manager and add an ExternalSecret for each Secret, so that what the cluster needs is all in ConfigHub, and the local copies can be deleted.

Checking that no secret slips in

The secrets guardrail pack warns on what looks like a secret in configuration: a Secret resource, a container environment variable whose literal name or value looks like a credential, and a ConfigMap key or value that does. Optionally, it also warns on a container that reads a Secret into its environment rather than mounting it as files.

cub manage guardrails secrets install --commit

A secret that has been written into a Unit stays in its earlier Revisions after it is removed from the head. Rotate it in the secret manager.