diff --git a/docs/registry-pull-auth.md b/docs/registry-pull-auth.md index b9e4a20..c52ab6c 100644 --- a/docs/registry-pull-auth.md +++ b/docs/registry-pull-auth.md @@ -57,9 +57,6 @@ for **rotating** the token. ### Rotate it -The SOPS file is the source of truth — a `kubectl apply` of a new Secret is reverted by the next -`apps` reconcile, so rotate in git: - ```bash # 1. token (mint a fresh one; never echo it) kubectl -n forgejo exec deploy/forgejo -- su-exec git forgejo admin user generate-access-token \ @@ -68,7 +65,7 @@ kubectl -n forgejo exec deploy/forgejo -- su-exec git forgejo admin user generat # then the command above; the password is only needed for interactive login and is # never used by containerd.) -# 2. rewrite the encrypted value in every namespace's file (no plaintext ever hits disk) +# 2. build the dockerconfigjson without printing it umask 077 read -r -s -p 'token: ' RT; echo python3 - "$RT" > /tmp/dc.json <<'PY' @@ -78,33 +75,21 @@ print(json.dumps({"auths": {"forgejo.siriusdevops.com": { "username": "registry-reader", "password": t, "auth": base64.b64encode(f"registry-reader:{t}".encode()).decode()}}})) PY + +# 3. one Secret per namespace for ns in osint piedmont sirius-growth siriusdevops; do - f=apps/base/$ns/secret-forgejo-pull.sops.yaml - sops decrypt --output-type json "$f" \ - | jq --rawfile dc /tmp/dc.json '.data[".dockerconfigjson"] = ($dc | rtrimstr("\n") | @base64)' \ - | sops encrypt --filename-override "$f" --input-type json --output-type yaml /dev/stdin > /tmp/new.yaml \ - && mv /tmp/new.yaml "$f" + kubectl create secret generic forgejo-pull -n "$ns" \ + --type=kubernetes.io/dockerconfigjson --from-file=.dockerconfigjson=/tmp/dc.json \ + --dry-run=client -o yaml | kubectl apply -f - done shred -u /tmp/dc.json -git commit -am 'registry(auth): rotate the pull token' && git push && # then PR + merge + reconcile ``` -The consumer picks the new value up on its **next pull** — the Secret is read per pull, so no pod -restart is needed. Delete the old token in Forgejo afterwards (`profile → Applications`). - -The `registry-reader` token is minted without `--expires-at`, i.e. non-expiring; rotating it is -therefore an explicit action, not something the clock forces. - ### Add a namespace -Three edits, all in git: - -1. copy an existing `secret-forgejo-pull.sops.yaml` into `apps/base//` and point it at the - namespace (`sops` re-encrypts on save; `metadata.namespace` is not encrypted); -2. list it plus `secret-.sops.yaml` in that app's `kustomization.yaml` (the "Secrets, - SOPS/age-encrypted in git" block); -3. `imagePullSecrets: [{name: forgejo-pull}]` in the pod spec (or on the namespace's - ServiceAccount) — do not add the secret to workloads that do not pull from this registry. +`kubectl create secret` as above **and** `imagePullSecrets: [{name: forgejo-pull}]` in the +pod spec (or on the namespace's ServiceAccount) — do not add the secret to workloads that do +not pull from this registry. ## Why not a node-level credential