How are secrets stored and delivered? #57

Closed
opened 2026-11-23 16:05:25 -05:00 by bobby · 4 comments
Owner

Part of #44

Question

Where do secrets (DB credentials, Bot keys, ntfy tokens, signing keys, Linode API tokens) live, and how do they reach the cluster and the app? Options include SOPS, Sealed Secrets, External Secrets with a backing store (OpenBao/Vault, a password manager), plus rotation.

Part of #44 ## Question Where do secrets (DB credentials, Bot keys, ntfy tokens, signing keys, Linode API tokens) live, and how do they reach the cluster and the app? Options include SOPS, Sealed Secrets, External Secrets with a backing store (OpenBao/Vault, a password manager), plus rotation.
bobby added the wayfinder:grilling label 2026-11-23 16:05:25 -05:00
bobby added a new dependency 2026-11-23 16:05:35 -05:00
bobby added a new dependency 2026-11-23 16:05:35 -05:00
Author
Owner

Input from Which libraries and conventions form the FastAPI app skeleton?: the app reads config via pydantic-settings (HAPI_-prefixed env vars, or mounted secret files) and fails fast at startup. Secrets must land in one of those two forms.

Input from [Which libraries and conventions form the FastAPI app skeleton?](https://git.bobbypalko.com/bobby/hapi/issues/51#issuecomment-196): the app reads config via pydantic-settings (`HAPI_`-prefixed env vars, or mounted secret files) and fails fast at startup. Secrets must land in one of those two forms.
Author
Owner

Inputs from How does hAPI connect to its managed database? (#53, ADR-0004): two DB passwords need a home and delivery path: hapi_app (app and admin CLI) and hapi_migrator (migrate and break-glass only, so ideally not mounted into normal app pods). The DB CA cert (from OpenTofu ca_cert) is also needed. akmadmin stays only in encrypted OpenTofu state and is pasted in at bootstrap time, never stored in the cluster. Rotation is manual by runbook.

Inputs from **How does hAPI connect to its managed database?** (#53, [ADR-0004](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0004-database-access.md)): two DB passwords need a home and delivery path: `hapi_app` (app and admin CLI) and `hapi_migrator` (migrate and break-glass only, so ideally not mounted into normal app pods). The DB CA cert (from OpenTofu `ca_cert`) is also needed. `akmadmin` stays only in encrypted OpenTofu state and is pasted in at bootstrap time, never stored in the cluster. Rotation is manual by runbook.
Author
Owner

Constraints from How do code changes reach the cluster? (#56, ADR-0007):

  • Flux applies everything from this public repo and holds no git credentials. Any secret committed to git must be encrypted (e.g. SOPS with a key Flux can decrypt), or it has to live outside git entirely.
  • Secrets to place:
    • Flux's decryption key, if any (it can't come through Flux itself)
    • hapi_app and hapi_migrator DB credentials (the migrate Job uses only the latter)
    • Actions secrets on Gitea: the CI write deploy key, the Renovate bot token, the ntfy token for CI failures
    • the OpenTofu state-encryption key
  • CI holds no cluster credentials, so secret delivery can't be CI-push either.
Constraints from **How do code changes reach the cluster?** (#56, [ADR-0007](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0007-flux-pull-delivery.md)): - Flux applies everything from this **public** repo and holds no git credentials. Any secret committed to git must be encrypted (e.g. SOPS with a key Flux can decrypt), or it has to live outside git entirely. - Secrets to place: - Flux's decryption key, if any (it can't come through Flux itself) - `hapi_app` and `hapi_migrator` DB credentials (the migrate Job uses only the latter) - Actions secrets on Gitea: the CI write deploy key, the Renovate bot token, the ntfy token for CI failures - the OpenTofu state-encryption key - CI holds no cluster credentials, so secret delivery can't be CI-push either.
bobby self-assigned this 2026-11-24 13:39:12 -05:00
Author
Owner

Resolution

Recorded as ADR-0008.

  • In-cluster secrets: encrypted with SOPS + age in this public repo (deploy/**/*.sops.yaml, encrypting only data/stringData), and decrypted natively by Flux. ESO, Sealed Secrets and hand-created Secrets were rejected.
  • The age key: one prod key, generated offline and kept in Vaultwarden. The Owner installs it by hand as flux-system/sops-age during the Flux install, so it's never in OpenTofu state. If it's ever exposed, every value it protected is rotated.
  • Mounting: secrets are read-only files under pydantic-settings' secrets_dir, never env vars. The DB CA certificate is a plaintext ConfigMap.
  • DB credentials:
    • hapi-db-app is mounted only into the app Deployment, which also hosts the admin CLI.
    • hapi-db-migrator is mounted only into the migrate Job and a runbook admin pod for bootstrap and break-glass.
    • No workload ServiceAccount can read Secrets.
    • The Owner generates the passwords and commits them encrypted. The idempotent hapi db bootstrap makes the roles match. akmadmin is still pasted in at run time.
  • One narrow token per integration:
    • The CCM's Linode token is dedicated and least-privilege, created by OpenTofu.
    • The future DNS-01, ntfy and backup-target tokens will come through SOPS.
  • CI: the deploy key, the Renovate token and a publish-only CI ntfy token are repo-level Gitea Actions secrets. CI never decrypts SOPS.
  • Guardrails: gitleaks runs in pre-commit and as a required CI check, along with a CI check that every Secret file is SOPS-encrypted. A leaked plaintext secret gets rotated, not just removed from history.
  • Rotation: manual, with no schedule. It's triggered by suspected exposure or a change in who has access. For DB passwords: SOPS change → Flux → hapi db bootstrap (ALTER ROLE) → rollout restart. A few seconds of failed new connections is accepted, and there's no Reloader.
  • Owner roots: the Tofu state key, the Linode and Object Storage tokens, talosconfig/kubeconfig and the age key are all in Vaultwarden (cloud-hosted, backed up). An extra offline copy (paper or USB, kept away from home) holds the age key, the Tofu passphrase and the Linode recovery codes.
  • No signing keys in v1: Tokens are stored as plain SHA-256 (ADR-0005).
## Resolution Recorded as [ADR-0008](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0008-sops-secrets-in-git.md). - **In-cluster secrets:** encrypted with **SOPS + age** in this public repo (`deploy/**/*.sops.yaml`, encrypting only `data`/`stringData`), and decrypted natively by Flux. ESO, Sealed Secrets and hand-created Secrets were rejected. - **The age key:** one prod key, generated offline and kept in Vaultwarden. The Owner installs it by hand as `flux-system/sops-age` during the Flux install, so it's never in OpenTofu state. If it's ever exposed, every value it protected is rotated. - **Mounting:** secrets are read-only files under pydantic-settings' `secrets_dir`, never env vars. The DB CA certificate is a plaintext ConfigMap. - **DB credentials:** - `hapi-db-app` is mounted only into the app Deployment, which also hosts the admin CLI. - `hapi-db-migrator` is mounted only into the migrate Job and a runbook admin pod for bootstrap and break-glass. - No workload ServiceAccount can read Secrets. - The Owner generates the passwords and commits them encrypted. The idempotent `hapi db bootstrap` makes the roles match. `akmadmin` is still pasted in at run time. - **One narrow token per integration:** - The CCM's Linode token is dedicated and least-privilege, created by OpenTofu. - The future DNS-01, ntfy and backup-target tokens will come through SOPS. - **CI:** the deploy key, the Renovate token and a publish-only CI ntfy token are repo-level Gitea Actions secrets. CI never decrypts SOPS. - **Guardrails:** gitleaks runs in pre-commit and as a required CI check, along with a CI check that every Secret file is SOPS-encrypted. A leaked plaintext secret gets rotated, not just removed from history. - **Rotation:** manual, with no schedule. It's triggered by suspected exposure or a change in who has access. For DB passwords: SOPS change → Flux → `hapi db bootstrap` (`ALTER ROLE`) → `rollout restart`. A few seconds of failed new connections is accepted, and there's no Reloader. - **Owner roots:** the Tofu state key, the Linode and Object Storage tokens, talosconfig/kubeconfig and the age key are all in Vaultwarden (cloud-hosted, backed up). An extra offline copy (paper or USB, kept away from home) holds the age key, the Tofu passphrase and the Linode recovery codes. - **No signing keys in v1:** Tokens are stored as plain SHA-256 (ADR-0005).
bobby closed this issue 2026-11-24 15:09:07 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Reference: bobby/hapi#57