Sealed secrets

From gilesknap/tpi-k3s-ansible · View interactive version

Sealed secrets is an AI agent skill from the GitHub repository gilesknap/tpi-k3s-ansible. Sealing, rotating, and troubleshooting SealedSecrets in the K3s cluster — file naming rules, placeholder base64 pitfalls, seal-argocd-dex subcommands, pod restart requirements after reseal.

How to use this skill

Skill file

Sealed Secrets

Bitnami sealed-secrets is the only commit-safe way to ship Kubernetes

Secrets through this repo. kubeseal reads the live cluster's public

key and encrypts secret data into a committed *-secret.yaml file that

the in-cluster controller decrypts into a real Secret.

kubeseal is one of the few commands allowed to touch the live cluster

directly (see CLAUDE.md hard rules).

File naming

*-secrets.yaml is not in the .gitleaks.toml allowlist — the

pre-commit hook will block the commit with no obvious reason.

The placeholder base64 foot-gun

**Never commit a *-secret.yaml with placeholder text like REPLACE_ME

in encryptedData.** The chain of silent failures is brutal:

  1. Controller fails to decrypt: illegal base64 data
  2. The real Secret is never created
  3. Any Prometheus operator CR (Alertmanager / Prometheus) referencing

the missing Secret via secrets: silently omits the volume mount

  1. You get runtime errors that don't obviously point at the placeholder

Always seal a real value immediately, or omit the file entirely

until you have one. If you must stub it out, use a short real string

and reseal later — never a literal REPLACE_ME.

`scripts/seal-argocd-dex` — per-secret subcommands

seal-argocd-dex needs a subcommand; a bare run prints usage and exits 1:

seal-argocd-dex <github|argocd|monitor|grafana>

Full sealing is just generate-and-seal-all (the rebuild path).

Subcommands read existing keys from the running argocd-dex-secret to

preserve values they don't touch, so it must already exist.

Pod restarts after reseal

Pods that read secret values via envFrom or secretKeyRef **cache

values at pod startup**. After re-sealing, running pods keep stale

values and OAuth/service login fails with errors like

invalid client_secret — even though the Kubernetes Secret object

itself is correct.

seal-argocd-dex does not restart anything. After a reseal, restart

only the pods that consume the secrets you changed, from these namespaces:

(kubectl -n argocd-monitor rollout restart deployment)

kubectl delete pod -n ntfy -l app.kubernetes.io/name=ntfy. The user

database is on the pod's emptyDir, and only a new pod drops the old

tokens and any minted through the account API (docs/how-to/ntfy.md)

just seal-ntfy --rotate scrap (it reads SCRAP_NOTIFY_URL at start)

reseal its token with just cf-seal-tunnel-token)

`cookie-secret` generation

oauth2-proxy's cookie secret must be exactly 16, 24, or 32 bytes

for the AES cipher. Regressions have happened twice:

scripts/seal-argocd-dex does. Do not change it.

Non-deterministic re-encryption

kubeseal adds random padding, so re-sealing the same plaintext

produces a different ciphertext each run. This is expected. Don't try

to diff-match sealed ciphertexts — diff the underlying plaintext via

the generator script or compare decrypted Secret contents on-cluster.

Sealing keys: renewal off, backed up nightly

kubernetes-services/templates/sealed-secrets.yaml), so the key changes

only on a manual rotation or a rebuild. To rotate, set the chart's

keycutofftime (date -R) through Git; the controller makes a new key

when it restarts. Then optionally kubeseal --re-encrypt the repo's

SealedSecrets. See docs/how-to/manage-sealed-secrets.md.

to backups/etcd/sealed-secrets-keys.yaml.age on the NAS. Never write

the decrypted keys to disk or print them; pipe age -d straight into

kubectl apply -f - or kubeseal --recovery-private-key <(...).

remind them to re-export it (docs/how-to/backup-restore.md).

Key files

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.