Lab & Completion

What You Will Produce

On your own kind cluster, a Secret encrypted with your key travels the whole path: your editor, ENC[...] in your fork, decrypted by secrets-local into develop - where it is plaintext again. Then you reproduce the incident: the sops-encrypted check refuses a plaintext Secret before it can be committed. A file encrypted for a key your cluster does not hold stops secrets-local until you re-encrypt it. Last, you rotate your age key through Terraform - both keys during the transition, sops updatekeys and sops rotate, then the old key out - and prove that the old key opens nothing new, but still opens your old commit. The lab commits to your fork and ends with the lab Secrets removed.

Before You Start

The baseline from Chapter 00 must be clean:

flux --context kind-sre-control-plane get kustomizations -A          # every row READY=True and SUSPENDED=False
kubectl --context kind-sre-control-plane get pods -A --no-headers | grep -vE 'Running|Completed'   # prints nothing
make smoke-test                     # Fail: 0

This chapter also needs:

  • Flux following your fork (flux_git_repository_url in terraform.tfvars, Chapter 00) - B3 plans and applies Terraform with it;
  • your key registered: scripts/sops-setup.sh --local and .sops.yaml committed (Chapter 00);
  • sops, age and pre-commit installed (make check-tools).

The Lab in Three Parts

  • A. Verify - Flux follows your fork; your key is the same in age.agekey, .sops.yaml and the cluster; secrets-local decrypts; a Secret you encrypt arrives in develop.
  • B. Break & Fix - a plaintext Secret refused by the check; a file for a foreign key that stops secrets-local, fixed by re-encrypting; a full rotation of your age key through Terraform.
  • C. Rollback & Cleanup - the lab Secrets removed through Git and pruned by Flux; the baseline and make kind-drift proven.

Open the lab →

Done When

  • age-keygen -y age.agekey and the flux/secrets/local/ rule in .sops.yaml printed the same key, and scripts/sops-setup.sh --local said the cluster holds it (A3)
  • flux/secrets/local/lab-secret.yaml showed greeting: ENC[AES256_GCM,..., and the Secret in develop decoded to hello from my key (A5)
  • pre-commit run sops-encrypted printed Failed and NOT ENCRYPTED: flux/secrets/local/lab-plain.yaml, and nothing was committed (B1)
  • with lab-wrong-key encrypted for the other key, secrets-local was READY False with identity did not match any of the recipients, while lab-secret stayed (B2)
  • after sops updatekeys with the other key, secrets-local was READY True and lab-wrong-key existed (B2)
  • both rotation plans showed exactly Plan: 0 to add, 1 to change, 0 to destroy. - the in-place update of kubernetes_secret_v1.sops_age (B3)
  • updatekeys: value unchanged - same data key, rotate: value re-encrypted - new data key, and old key, new file: exit=128, while the old key still opened A5’s commit (B3)
  • with only the new key in the cluster, flux reconcile kustomization secrets-local printed ✔ applied revision (B3)
  • at the end, lab-secret and lab-wrong-key are NotFound, the baseline is clean, make kind-drift returns 0, git status --short prints nothing, and ls *.agekey lists only age.agekey (C1-C2)

Knowledge Check

Before finishing this chapter, complete the Quiz.