Merge pull request 'docs(registry): rotate/add registry pull secrets through SOPS' (#47) from docs/registry-sops into master
This commit is contained in:
commit
ce13f756f9
1 changed files with 24 additions and 9 deletions
|
|
@ -57,6 +57,9 @@ 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 \
|
||||
|
|
@ -65,7 +68,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. build the dockerconfigjson without printing it
|
||||
# 2. rewrite the encrypted value in every namespace's file (no plaintext ever hits disk)
|
||||
umask 077
|
||||
read -r -s -p 'token: ' RT; echo
|
||||
python3 - "$RT" > /tmp/dc.json <<'PY'
|
||||
|
|
@ -75,21 +78,33 @@ 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
|
||||
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 -
|
||||
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"
|
||||
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
|
||||
|
||||
`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.
|
||||
Three edits, all in git:
|
||||
|
||||
1. copy an existing `secret-forgejo-pull.sops.yaml` into `apps/base/<ns>/` and point it at the
|
||||
namespace (`sops` re-encrypts on save; `metadata.namespace` is not encrypted);
|
||||
2. list it plus `secret-<other>.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.
|
||||
|
||||
## Why not a node-level credential
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue