sops: decrypt on every Flux Kustomization + static guard
`spec.decryption` is opt-in per Flux Kustomization, and a secret-*.sops.yaml
under a tree without it is still valid YAML: Flux applies the Secret with
literal ENC[AES256_GCM,...] values and reports success. The Secret is green and
wrong, and the first symptom is an auth failure days later that looks nothing
like a git problem. Only `apps` and `monitoring` had the block; the other six
trees were a trap for the next person to add a Secret there.
- add decryption: {provider: sops, secretRef: sops-age} to cert-manager,
databases, gateway-api-crds, infrastructure, logging and flux-system
(8/8 Kustomizations now decrypt; harmless where no encrypted files exist)
- scripts/check-sops-decryption.py + `make check-sops`: static guard that reads
the live sync path from gotk-sync.yaml, walks each Kustomization's kustomize
resource graph, and fails when a *.sops.yaml file is under a tree whose owner
cannot decrypt, is under no reconciled tree, or is not actually encrypted
(also catches `flux bootstrap` regenerating gotk-sync.yaml without the block)
- .gitattributes marks *.sops.yaml with diff=sopsdiffer; docs/secrets-sops.md
explains the opt-in trap, the eight Kustomizations and the guard
No secret contents, recipients or keys touched.
This commit is contained in:
parent
e9dbbbfbcd
commit
eea80f475e
10 changed files with 338 additions and 3 deletions
|
|
@ -67,7 +67,16 @@ at the repo root, so `sops` picks it up with no flags as long as the filename ma
|
|||
|
||||
## How Flux applies them
|
||||
|
||||
`clusters/homek8s/apps.yaml` — the `apps` Kustomization — carries:
|
||||
**`decryption` is opt-in per Flux Kustomization, and the failure mode is silent.** A
|
||||
`secret-*.sops.yaml` under a tree whose Kustomization lacks the block is still valid YAML:
|
||||
kustomize-controller applies the Secret with the literal strings `ENC[AES256_GCM,data:…]` as its
|
||||
values. The Secret exists, `kubectl get secret` is green, and the first symptom is an application
|
||||
failing to authenticate — possibly days later, on a pod restart, looking nothing like a git
|
||||
problem. (Same class as the registry-secret trap in `docs/registry-pull-auth.md`.)
|
||||
|
||||
So **every** Flux Kustomization in `clusters/homek8s/` carries the block, not just the two that
|
||||
need it today — harmless where a tree has no encrypted files, and it removes the "which tree am
|
||||
I in" question entirely:
|
||||
|
||||
```yaml
|
||||
decryption:
|
||||
|
|
@ -76,10 +85,47 @@ at the repo root, so `sops` picks it up with no flags as long as the filename ma
|
|||
name: sops-age
|
||||
```
|
||||
|
||||
The eight: `apps`, `monitoring`, `infrastructure`, `logging`, `databases`, `cert-manager`,
|
||||
`gateway-api-crds` and `flux-system`. Today only `apps` (`apps/base/*/`) and `monitoring`
|
||||
(`monitoring/controllers/home/`) actually contain encrypted files.
|
||||
|
||||
`clusters/homek8s/flux-system/gotk-sync.yaml` is generated by `flux bootstrap` and says
|
||||
"DO NOT EDIT"; the `decryption` block there was added by hand and a future bootstrap would drop
|
||||
it. The guard below catches that.
|
||||
|
||||
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.
|
||||
|
||||
### Guard — `make check-sops`
|
||||
|
||||
`scripts/check-sops-decryption.py` (static: no cluster, no age key, no network) reads the live
|
||||
sync path out of `clusters/*/flux-system/gotk-sync.yaml`, walks each Kustomization's kustomize
|
||||
resource graph, and fails when:
|
||||
|
||||
1. any Flux Kustomization lacks `decryption.provider: sops` (or its `secretRef.name`);
|
||||
2. a `*.sops.yaml` / `*.sops.yml` file sits under no reconciled tree, or under a tree whose
|
||||
owner cannot decrypt;
|
||||
3. a `*.sops.yaml` file contains no `sops:` block / `ENC[AES256_GCM…` — i.e. plaintext wearing
|
||||
an encrypted file's name.
|
||||
|
||||
```bash
|
||||
make check-sops # exit 0 = clean, 1 = violations, 2 = could not run (never a pass)
|
||||
./scripts/check-sops-decryption.py -v # same, plus each Kustomization and file→owner mapping
|
||||
```
|
||||
|
||||
Run it before pushing a change that adds or moves a Secret. A violation is a config error, not a
|
||||
warning: in the un-guarded case Flux applies ciphertext and reports success.
|
||||
|
||||
### Reading a diff
|
||||
|
||||
`.gitattributes` marks `*.sops.yaml` with `diff=sopsdiffer`. To make `git diff` show decrypted
|
||||
values instead of ciphertext, enable the driver once per workstation (it needs the age key):
|
||||
|
||||
```bash
|
||||
git config --global diff.sopsdiffer.textconv 'sops decrypt --output-type yaml'
|
||||
```
|
||||
|
||||
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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue