Secret Management & Rotation

For an operator rotating a credential or adding a teammate to the secrets file. The storage model, the cargo xtask secrets subcommands, the YAML-to-environment mapping and every secret’s variable name are owned by Configuration Reference › Secrets; this page is the procedure.

Where secrets live

  • At rest: SOPS-encrypted YAML with age recipients (ADR-017) — secrets/dev.yaml for the devstack (fake values), a deployment-owned encrypted file for production. .sops.yaml lists the recipients; the private key is ~/.config/sops/age/keys.txt (CI: the masked variable CANOPY_CI_AGE_KEY).

  • In a process: environment variables, injected by cargo xtask dev start|reload|restart|refresh on the devstack and by your deployment tooling in production. Services read them through canopy_secrets::EnvSecretProvider (crates/canopy-secrets/src/lib.rs), which canopy-api's bootstrap_with uses for DATABASE_URL, MIGRATION_DATABASE_URL and RABBITMQ_URL (resolve_secrets) and for the service’s canopy-identity client key, IDENTITY_CLIENT_PRIVATE_KEY (crates/canopy-api/src/bootstrap.rs); signing keys are read the same way in each service’s main.rs.

  • Never on the host: age and sops run inside the canopy-devtools container (xtask/src/devtools.rs).

An environment variable is process-lifetime, so every rotation below ends in a restart of the consuming services.

Audit log shape

Every successful secret read emits one INFO event — the value is never logged:

{
  "timestamp": "2026-09-23T12:00:00.000000Z",
  "level": "INFO",
  "message": "secret accessed",
  "service": "canopy-snap",
  "key": "CANOPY_SNAP__DATABASE_URL",
  "source": "env",
  "target": "canopy.secrets"
}

The variable’s name rides in key, not in a field called secret: every service’s logs pass through the ADR-041 redaction policy, and a field named secret is exactly what a policy redacts — canopy’s default secret rule among them (Rulesets › Logging redaction policy) — which would blank the one thing this audit line exists to record. A jurisdiction policy that adds a rule matching key does the same; keep key out of a pack’s [[logging.sensitive_fields]].

To see it on the devstack:

cargo xtask dev logs canopy-snap --tail 200 --no-follow | grep canopy.secrets

In production these lines flow with the rest of the structured logs (Deployment Guide › Observability) and are the evidence for IRS Pub 1075 §9.4.1.4 secret-access auditing.

Rotate a secret (devstack)

Preconditions: you are a recipient in .sops.yaml (otherwise an existing recipient runs cargo xtask secrets add-recipient <your age1…> first).

  1. Change the value: cargo xtask secrets edit (a signing key: paste the output of cargo xtask secrets generate-signing-key under the service’s signing_key:).

  2. Restart with the new environment — data kept: cargo xtask dev reload. Never docker compose restart <service>: restart keeps the existing container and its environment, so the rotated value is never applied, and a partial restart leaves peers on different values (Stale JWKS recovery).

  3. Verify: cargo xtask dev logs <service> --tail 200 --no-follow | grep canopy.secrets shows the key being read, and /readyz answers 200 (health).

Rollback: cargo xtask secrets edit back to the previous value, cargo xtask dev reload again. Git keeps the previous ciphertext.

Rotate a secret (production)

  1. Rotate the credential at its source first (PostgreSQL ALTER ROLE … PASSWORD, RabbitMQ rabbitmqctl change_password, canopy-web’s client secret at the upstream IdP) with the old value still valid where the system allows two.

  2. Re-encrypt the new value into the deployment’s SOPS file with the same cargo xtask secrets edit flow against that file, or your platform’s equivalent.

  3. Redeploy the consuming services one at a time with the rolling procedure in Rolling deploy & rollback; each restart re-reads the environment.

  4. Verify the canopy.secrets lines and /readyz on every restarted service, then revoke the old credential at its source.

WARNING
If a CANOPY_<SVC>__DATABASE_URL rotation points at a different database, snapshot the old one first (cargo xtask migrate snapshot on a devstack, a base backup in production — Backup & Restore).

Recipients

  • Add: the new person runs cargo xtask secrets init and sends the printed public key; an existing recipient runs cargo xtask secrets add-recipient <age1…> and commits .sops.yaml and the re-encrypted secrets/dev.yaml.

  • Remove: an existing recipient runs cargo xtask secrets remove-recipient <age1…> — it drops the key from .sops.yaml (inline or folded age: form), refuses to remove the last remaining recipient, and runs sops updatekeys --yes secrets/dev.yaml so the re-encrypted data key no longer includes it (a key that is not listed is a no-op; a failed updatekeys restores .sops.yaml so nothing is half-applied); commit .sops.yaml and secrets/dev.yaml together. Removing a key protects only values encrypted afterwards — git history keeps every earlier ciphertext the removed key could open. Treat a departure as a rotation of every value in the file, using the procedures above; the recipient edit is hygiene, not revocation, and the command prints that reminder.

Which procedure for which secret

Secret Variable Procedure

Database password

CANOPY_<SVC>DATABASE_URL (and MIGRATION_DATABASE_URL)

This page; annually and on suspected compromise.

Broker password

CANOPY_<SVC>__RABBITMQ_URL

This page; annually and on suspected compromise.

canopy-identity’s issuer and security-admin logins

CANOPY_SECURITYIDENTITY_DATABASE_URL, CANOPY_SECURITYIDENTITY_ADMIN_DATABASE_URL

This page; on a suspected compromise, Security Operations › canopy-identity key registry (Compromise response) first.

canopy-identity client keys

CANOPY_<SVC>__IDENTITY_CLIENT_PRIVATE_KEY

Security Operations › canopy-identity client keys (register the incoming key beside the current one, deliver it, retire the old).

canopy-web’s upstream client secret

CANOPY_WEB__UPSTREAM_CLIENT_SECRET

This page, after rotating the secret at the upstream IdP (IdP Integration › Registering canopy’s clients).

canopy-identity signing keys

none — each canopy-security replica holds its own in memory

They rotate on their own (Security Operations › canopy-identity signing keys); if receivers refuse tokens, Stale JWKS recovery.

Determination signing keys (ECDSA P-256)

CANOPY_<PROG>SIGNING_KEY, CANOPY_NOTICESSIGNING_KEY

Signing Key Rotation (zero-downtime protocol; verifiers read signing_key_history).

Applicant ownership-claim keypair

CANOPY_PORTALAPPLICANT_SIGNING_KEY, CANOPY_<SVC>APPLICANT_VERIFYING_KEY

Security Operations › Key Rotation Runbook (staged public key, then cut over).

PII encryption key (AES-256-GCM)

CANOPY_ENCRYPTION_KEY (+ _PREVIOUS, _VERSION during a rotation)

Security Operations › The KEK — a two-key window plus the canopy-manage rewrap-keks DEK rewrap job per sealing service, not a plain secret swap.

NOTE
History — this page previously described .env files for development and a planned HashiCorp Vault provider; ADR-017 (Accepted 2026-05-02) replaced that direction with SOPS + age, and the page now follows it.
Edit this page · default