personal homelab and IaC setup www.frytg.digital
locally docs secrets.md
4.2 kB · 79 lines
Markdown
at main

Secrets #

Every secret in this repo is committed encrypted with sops. This page covers who can decrypt, where the encrypted files are, how recipes use them without writing plaintext, and how to change recipients. Restic credentials are covered in k8up.md, and kubeconfig handling in AGENTS.md.

Recipients #

.sops.yaml has one creation rule with no path filter, so every file you encrypt in this repo gets the same recipients:

  • One age key. It is the backup key, and the private half is in 1Password.
  • The team's PGP keys, by fingerprint. just list-pgp shows your local keyring. just import-pgp [keyserver] imports every fingerprint in .sops.yaml, from hkps://keys.openpgp.org by default.

No encrypted_regex is set, so sops encrypts every value. Keys stay readable, which keeps diffs reviewable.

Where the files are #

  • .env.<host>.sops.yaml: per-host env, mainly RESTIC_REPOSITORY, RESTIC_PASSWORD, and the S3 credentials.
  • <host>/k3s-cert.sops.yaml: cluster-admin kubeconfig.
  • <host>/services/<svc>/*.sops.yaml and common/services/<svc>/*.sops.yaml: complete Kubernetes Secret manifests with stringData, for example secrets.sops.yaml and k8up-credentials.sops.yaml.
  • locally0/services/nanomq/nanomq_pwd.sops.conf: the NanoMQ password file. It is not YAML.
  • common/tailscale/acl.sops.jsonc: the tailnet ACL.
  • infra/.env.sops.yaml and infra/state/prod/terraform.tfstate.sops: Terraform credentials and state.

List them all with:

git ls-files | grep -E '\.sops(\.|$)' | grep -v '^\.sops\.yaml$'

Using secrets without plaintext on disk #

  • Env for a command: SOPS_ENV_FILE=<file> just _env "<command>" runs the command under sops exec-env --same-process. Always set SOPS_ENV_FILE. The default .env.sops.yaml doesn't exist, so just _env without it fails.
  • Kubernetes secrets: just apply-secret <host> <svc>/<file>.sops.yaml (or apply-common-secret) pipes sops decrypt into kubectl apply -f -. The service recipes use this.
  • Editing: just edit-key <file> opens the decrypted file in nano and re-encrypts it on save.
  • New file: write the plaintext manifest, then run sops encrypt --in-place <file>.sops.yaml before you stage it. Once a plaintext secret is committed, it stays in git history even after a later fix.

Some steps do write plaintext. Each one writes to a gitignored path:

  • just k3s-decrypt <host> writes <host>/k3s-cert.yaml. Every kubectl recipe reads that file.
  • just nanomq writes nanomq_pwd.conf and deletes it again. If the recipe fails partway, the file stays, and locally0/services/nanomq/.gitignore keeps it out of git.
  • just decrypt-key <file> writes the file next to the original, with .sops removed from the name. Its prompt warns that it overwrites an earlier decrypted copy.

Changing recipients #

just update-keys, just rotate-keys, and just decrypt only cover .env.sops, infra/.env.sops, and infra/secrets/dashboard-keys.sops.json. None of those paths exist any more, so the recipes fail, and they never covered the per-host or per-service files anyway. Run sops over the full file list instead.

  1. Edit .sops.yaml to add or remove an age key or PGP fingerprint.

  2. Re-wrap every file for the new recipients. updatekeys changes who can unwrap each file's data key. It doesn't touch the encrypted values:

    git ls-files | grep -E '\.sops(\.|$)' | grep -v '^\.sops\.yaml$' | xargs -n1 sops updatekeys --yes
    
  3. When you remove a recipient, also rotate. A removed recipient may still hold the old data keys, so give every file a new one:

    git ls-files | grep -E '\.sops(\.|$)' | grep -v '^\.sops\.yaml$' | xargs -n1 sops rotate --in-place
    
  4. Check the diff: every *.sops* file should change only in its sops: metadata block (and, after a rotate, in its values). The header of .sops.yaml says to sync recipient changes to the other repos that share these keys.

Re-encrypting doesn't change the secret values inside the cluster, so you don't need to re-apply anything after a recipient change.