homek8s/docs/secrets-sops.md
Sirius DevOps c8f0834886 secrets: bring 29 hand-made cluster Secrets under Git via SOPS/age (audit F12)
Nothing in the cluster was reconciled from the repo: 67 hand-made Secrets and no
managed Secret at all, so a restore of this Git tree produced a cluster that would
not start. This commits the first-party ones as SOPS/age ciphertext and enables
Flux's sops decryptor.

* provider: SOPS + age (chosen over SealedSecrets: Flux already ships the sops
  decryptor, so no extra controller/CRD, and the age key is escrowed off-cluster).
* 29 Secrets across forgejo, siriusdevops, piedmont, sirius-growth, osint,
  metabase and customer1, as apps/base/<ns>/secret-<name>.sops.yaml with
  encrypted_regex ^(data|stringData)$ — names/namespaces stay reviewable.
* each file was generated from the LIVE object and decrypts to a byte-identical
  data map and type, so the first apply is a no-op (not a rotation).
* the CNPG bootstrap secrets (forgejo-pg-app, pg-app, sirius-growth-portal-db)
  are ours, not operator output — bootstrap.initdb.secret points at them, so a
  rebuild has no application password without them.
* forgejo-pull is included despite docs/registry-pull-auth.md calling it
  out-of-band: with imagePullSecrets on every workload it is the one Secret whose
  absence stops the whole cluster from pulling images.
* .gitignore keeps **/*secret*.yaml ignored and re-includes only .sops.yaml, so a
  plaintext Secret still cannot be committed; age.agekey stays ignored.
* excluded on purpose (controller/helm-owned): CNPG *-server/*-replication/*-ca,
  cnpg-system CA+webhook, cert-manager webhook CA, cilium/hubble certs, helm
  release records, prometheus-operator rendered prompts. Full table in
  docs/secrets-sops.md.

Key locations (never in git): Secret flux-system/sops-age (age.agekey) and
/root/sops/homek8s-age.key on the Linode, reached only over the mesh.
2026-11-27 00:18:14 -05:00

8.5 KiB

Cluster Secrets in Git (SOPS + age)

Decision (2026-11-27): every hand-made Secret consumed by a workload in this repo is committed as a SOPS/age-encrypted plain Secret manifest — not a SealedSecret, not secretGenerator from a plaintext file. One mechanism, no mixing.

Rationale: Flux already ships the sops decryptor (kustomize-controller), so there is no extra controller, CRD or admission webhook to run; the age private key never leaves the two places listed below. SealedSecrets would need a controller in the cluster and a sealing key escrowed somewhere anyway — the same single point of failure with more moving parts.

Where the key lives (this is the whole disaster-recovery story)

# Location Notes
1 Secret flux-system/sops-age, key age.agekey What Flux reads at reconcile time. Created out of band (kubectl create secret generic), never in git.
2 /root/sops/homek8s-age.key on the Linode VPS (0600, root) Off-workstation escrow. Reachable only over the mesh: laptop → rpi → ssh [email protected]. sha256 2d1b9d82e07ea126… (full hash in the 2026-11-27 card/handoff).
3 ~/.config/sops/age/keys.txt on the admin workstation (0600) Convenience only; sops' default lookup path. Losing this is survivable, losing #1 and #2 is not.

The key is not in the Obsidian vault (that tree is pushed nightly to Forgejo — a key there would publish itself) and not on any cluster node's disk other than as the Secret above.

Restore after losing both: nothing on the cluster can be decrypted and every encrypted file must be re-encrypted to a new recipient. That means re-entering the values from the upstream providers (Telegram bot tokens, Forgejo tokens, S3 keys, DB passwords). Treat #2 as the authoritative copy and copy it into a password manager as a third location.

Reading the key from escrow, if the workstation copy is gone:

ssh -i ~/.ssh/lancelot_priv [email protected] \
  'ssh -i ~/.ssh/linode_admin [email protected] cat /root/sops/homek8s-age.key' \
  > ~/.config/sops/age/keys.txt && chmod 600 ~/.config/sops/age/keys.txt

Working with the encrypted files

encrypted_regex: ^(data|stringData)$ — only the values are encrypted; metadata.name, namespace and type stay readable so git grep and code review still work.

# edit one (opens $EDITOR, re-encrypts on save)
sops apps/base/siriusdevops/secret-siriusdevops-contact.sops.yaml

# read key NAMES without decrypting values
sops decrypt --output-type json apps/base/siriusdevops/secret-siriusdevops-contact.sops.yaml \
  | jq -r '.data | keys[]'

# add a new secret: capture the live object, strip server metadata, encrypt through a pipe
kubectl -n <ns> get secret <name> -o json \
  | jq -S '{apiVersion:"v1",kind:"Secret",
            metadata:{name:.metadata.name,namespace:.metadata.namespace},
            type:.type,data:.data}' \
  | sops encrypt --filename-override secret-<name>.sops.yaml \
      --input-type yaml --output-type yaml /dev/stdin > apps/base/<ns>/secret-<name>.sops.yaml

Then list the file in that app's kustomization.yaml (they all end with a "Secrets, SOPS/age-encrypted in git" block).

Never commit a plaintext Secret, and never "encrypt it in a follow-up commit" — the plaintext commit is recoverable from the object database forever, even if force-pushed.

sops and age are packaged (pacman -S sops age); the recipient lives in .sops.yaml at the repo root, so sops picks it up with no flags as long as the filename matches secret-*.sops.yaml.

How Flux applies them

clusters/homek8s/apps.yaml — the apps Kustomization — carries:

  decryption:
    provider: sops
    secretRef:
      name: sops-age

Flux decrypts server-side before kustomize builds, so what lands in the cluster is an ordinary Secret. prune: true, so deleting the file deletes the Secret — that is the intended lifecycle.

Ordering note: a Secret must exist before its consumer starts (CNPG bootstrap.initdb.secret, imagePullSecrets, env refs). Kustomize sorts Secret before Deployment/Cluster, and all of these live in the same app directory, so one reconcile creates both.

Inventory — in git (29 Secrets, 7 namespaces)

Namespace Secrets
forgejo forgejo-pg-app, forgejo-runner-amd64-token, forgejo-runner-deploy-arm64-token
siriusdevops siriusdevops-contact, garage-media-s3, forgejo-pull
piedmont piedmont-contact, forgejo-pull
sirius-growth sirius-growth-contact, sirius-growth-blog-app, sirius-growth-blog-s3, sirius-growth-portal-app, sirius-growth-portal-db, sirius-growth-portal-s3, portal-wal-s3, forgejo-pull
osint osint-admin, osint-db, forgejo-pull
metabase pg-app, metabase-admin, metabase-data-source-creds
customer1 pg-app, pg-users, odoo-config, odoo-admin, metabase-admin, metabase-data-source-creds, metabase-secret-key

*-pg-app / pg-app / sirius-growth-portal-db deserve a note: these look like CNPG output but are ours — each Cluster's bootstrap.initdb.secret.name points at one of them, so CNPG reads the password from the Secret we create rather than minting it. Without them in git a rebuild's initdb has no application password and the Cluster never bootstraps. They are static (no password-rotation policy is configured), so re-applying the same bytes is a no-op.

forgejo-pull is committed even though docs/registry-pull-auth.md (F11) describes it as "out of band (never in git)". That wording predates this card: once every Deployment carries imagePullSecrets: [forgejo-pull], that Secret is the thing whose absence stops the cluster from starting, which is exactly what this card exists to prevent. It is a Forgejo read:package token — ciphertext in git is the correct home for it.

Excluded on purpose (not in git, by design)

Secret(s) Namespace Why
pg-server, pg-replication, pg-ca forgejo, metabase Issued and rotated by the CNPG instance manager (ownerRef Cluster/pg). Committing them pins stale certs the operator immediately overwrites → permanent drift.
portal-server, portal-replication, portal-ca sirius-growth Same, ownerRef Cluster/portal.
cnpg-ca-secret, cnpg-webhook-cert cnpg-system Operator's own CA + webhook serving cert, ownerRef Deployment/cnpg-controller-manager; regenerated on install.
barman-cloud-server-tls, barman-cloud-client-tls, plugin-barman-cloud-<hash> cnpg-system Generated by the vendored plugin-barman-cloud manifest (the <hash> is a content checksum in the object name).
cert-manager-webhook-ca cert-manager Helm-generated webhook CA.
cilium-ca, hubble-server-certs, hubble-relay-client-certs kube-system Cilium Helm chart mints these (lookup-reused); a stale copy wedges an upgrade — the documented failure is HelmRelease stalled on a cert that does not match the current cluster.name.
sh.helm.release.v1.* kube-system, cert-manager, monitoring Helm release records (release state, not configuration).
kube-prometheus-stack-admission monitoring Helm-generated webhook cert.
prometheus-kube-prometheus-stack-prometheus, alertmanager-kube-prometheus-stack-alertmanager, *-generated, *-tls-assets-*, *-web-config, *-cluster-tls-config monitoring Rendered by the prometheus-operator from the CRs on every reconcile — writing them into git creates a second, losing writer. Their inputs (alertmanager-telegram, grafana-admin, grafana-secret-key) are ours and are committed separately.
kube-prometheus-stack-prometheus-token monitoring kubernetes.io/service-account-token, minted by the token controller.
flux-system flux-system Git credential created by flux bootstrap; it authenticates the very pull that would apply it (chicken-and-egg), and rotating it is a bootstrap operation.

Out of scope for this pass, tracked separately: cluster-backup-ssh (3 copies), grafana-admin, grafana-secret-key, alertmanager-telegram live in monitoring/backup CronJobs and are being migrated in a follow-up commit once the delete-and-reconcile drill below proved the path.

Delete-and-reconcile drill (2026-11-27)

siriusdevops/siriusdevops-contact — deleted, Flux recreated it from git, values verified identical to the pre-delete snapshot, contact API still serving /health. Evidence in the kanban card for t_46f03ecb (key names only, never values).