Repository navigation
fix(docs,deploy): the KEK rotation step 3 dropped every retired key, not one - #977
Conversation
…not one The four optional notes from the approving review of #976 (ingpaolodettori-dev), the first of which is a data-loss bug introduced by that PR's own safety fix. Step 3 keeps `${ring%%,*}` and writes it as the whole value, so it drops EVERY entry after the first, not just the retired one. A ring of three -- step 1 run twice before step 3 ever ran -- passed the "has a comma" guard and silently discarded two keys at once, which is exactly the unrecoverable loss the section warns about. It now requires EXACTLY TWO non-empty entries and refuses otherwise, so a longer ring stops the operator instead of destroying keys, and says to rotate one key at a time. Checked against "a,b" (proceeds), "a,b,c", a single key, empty, ",b", "a," and "a,,b" (all refuse). `NS` is guarded: unset, empty or the literal placeholder now refuses, because kubectl otherwise falls back to the current context's default namespace -- the wrong place to patch a Secret or read a ring from. Step 2's remaining `-n <namespace>` uses "$NS" like the other two. Two comments contradicted themselves, both written by #976 and both carried in that review: - setup.sh:758 said the render "has no patch target" for a claim this run does not render, which reads as though that were a problem, while the block at 1393 correctly says kustomize tolerates it. Verified on kustomize v5.8.1: an unmatched `patches:` target is skipped and the build exits 0, so the class is simply never applied rather than failing. Says that now. - the vault component said "re-reads it on every request" and "reads the sink ONCE, SYNCHRONOUSLY, at boot" four lines apart. `vaultTokenSource` does both: it validates the sink once at boot (`readFileSync`) and re-reads it per request (`readFile`). Both the component and the runbook now say validate at boot, then re-read per request. Refs #823 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Mariusz Sabath <[email protected]>
clawgenti
left a comment
There was a problem hiding this comment.
Summary
The bug is real and the fix is the right shape. On a three-entry ring ${ring%%,*} kept entry 1 and step 3 wrote back only it, so a second rotation before a step 3 dropped two keys at once — the unrecoverable case the section is about. The new guard requires exactly two non-empty entries, and I probed it against seven ring shapes: K1,K2 passes with primary=K1; K1, K1,, K1,K2,, K1,,K2, K1,K2,K3 and empty all refuse. The doc claim the PR also corrects — that the sink is validated at boot and re-read per request, with 503 only for a sink that goes unreadable later — matches packages/control-plane/src/vault-store.ts:244-263 (a boot-time readFileSync inside check(), then an async re-read per request, and headers() maps that failure to credential_unavailable/503). The two deploy-file hunks are comment-only.
No must-fix. Two suggestions, both about the same hazard the PR is fixing, one step further out.
Author: mrsabath (MEMBER — maintainer)
Areas reviewed: Docs (runbook fenced shell), Shell (deploy/sbx/setup.sh — comment only), K8s YAML (overlay patch — comment only)
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing (no workflow runs the runbook's fenced blocks; the change is unexecuted by CI)
Verified by: ring-guard probe over seven inputs (results above); NS-guard probe ("" and <namespace> refuse, sbx passes); vault-store.ts read at head for the boot-validation / per-request / 503 claims; kubectl 1.37.2 accepts -n "" and proceeds to the server rather than refusing, i.e. it falls back to the context default.
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
| NS=<namespace> | ||
| # Unset or empty, kubectl silently uses the current context's default namespace, which is the wrong | ||
| # place to patch a Secret or read a ring from. | ||
| [[ -n "$NS" && "$NS" != '<namespace>' ]] || |
There was a problem hiding this comment.
suggestion — the new guard only exists in step 1's block, but steps 2 and 3 are separate fenced blocks that the prose above explicitly says are safe to run in separate shells ("Step 3 takes the key it keeps from the live ring rather than from a variable, so the steps are safe to run in separate shells"). A fresh shell that pastes only step 3 has NS unset, so this guard never runs — and step 3 is the one that patches the Secret. I checked that kubectl 1.37.2 accepts -n "" and goes on to the server (i.e. falls back to the context's default namespace) rather than refusing, which is exactly the "wrong place to patch a Secret" case the new comment describes.
Suggested fix: repeat the two-line guard at the top of the step 2 and step 3 blocks, or use : "${NS:?set NS to the deployment namespace first}", which is one line and fails the same way.
| # the retired entry, leaving the new key alone. The key to keep comes from the LIVE ring rather | ||
| # than from $new, so a fresh shell cannot write an empty key. | ||
| # | ||
| # EXACTLY TWO entries, or it refuses. This step keeps the first and drops the rest, so on a ring of |
There was a problem hiding this comment.
suggestion — the new "exactly two entries" refusal is right, but it leaves an operator who is already at three entries (step 1 run twice before step 3 ever ran — the mistake this PR is about) with no documented way out: the remedy in the comment, "rotate one key at a time: finish step 3, then start step 1 again", only applies from a two-entry ring.
Suggested fix: one paragraph for the three-entry case. Run step 2's evidence check against the ring as it stands; once it is quiet across a full cycle of use, patch the Secret to the first two entries — that is the drop step 3 would itself have made — let a second full cycle go quiet, then run step 3 to drop the third. The order matters: dropping the oldest without the quiet counter is the unrecoverable loss this section warns about.
There was a problem hiding this comment.
Approving. I verified the same ground independently at 9659c3f and reached the same conclusion as the review above:
- Step 3 guard: the new entry-count check holds on all seven ring shapes from the PR body (
a,bproceeds keepinga;a,b,c,a, empty,,b,a,,a,,ball refuse), and keying on entry count rather than "has a comma" is what closes the two-key-loss path #976 opened. $NSguard: refuses on empty and on the un-substituted<namespace>placeholder.vault-store.tscomments:vaultTokenSourcevalidates the boot sink withreadFileSyncand re-reads per request, with a per-request failure surfacing ascredential_unavailable(503) — the new wording is right and the old "reads ONCE" wording was the wrong half of the truth.setup.shcomment: kustomize skips an unmatchedpatches:target with exit 0, so "silently never applied rather than failing the build" is accurate.
I didn't repeat the two inline suggestions already posted at runbook.md:510 and :546 — I agree with both. The :510 one (the $NS guard lives only in step 1's block, so a fresh shell running step 3 alone falls back to the context's default namespace) is the only thing I'd still change before merge; a one-line ${NS:?…} check at the top of each fenced block covers it. The :546 gap — no documented remedy for an operator whose ring is already at three entries — is worth a short paragraph. Neither is blocking.
Author: mrsabath (MEMBER — maintainer)
Areas reviewed: docs (runbook markdown + shell snippets), shell comment, k8s YAML comment
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, signed-off: yes
CI status: passing (19 checks)
Upstream rossoctl#972, rossoctl#977, rossoctl#978, rossoctl#979, rossoctl#981, rossoctl#983, rossoctl#985, rossoctl#988 and rossoctl#990 (44 commits past 49cce28). No conflict. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Summary
The four optional notes from @ingpaolodettori-dev's approving review of #976. The first is a data-loss bug that #976's own safety fix introduced, so it is worth landing on its own rather than waiting. Docs and comments only — no behaviour change outside the runbook procedure. Refs #823.
1. Step 3 dropped every retired key, not one
docs/operate/sandbox-service/runbook.md#976 fixed step 3 reading
$newfrom step 1's shell (which could write an empty KEK) by taking the surviving key from the live ring instead. But it keeps${ring%%,*}and writes that as the whole value, so it drops every entry after the first.A ring of three — step 1 run twice before step 3 ever ran — passed the "has a comma" guard and silently discarded two keys at once. That is precisely the unrecoverable loss the section exists to warn about: those credentials can never be decrypted, and the only repair is every affected user re-entering them by hand.
Now requires exactly two non-empty entries and refuses otherwise, so a longer ring stops the operator rather than destroying keys, and says to rotate one key at a time. Verified against every shape:
a,baa,b,ca(single),b/a,/a,,b2.
$NSwas unguardedThe preamble said to set
NSfirst, but nothing enforced it and step 2 still used a literal-n <namespace>. Unset or empty, kubectl silently falls back to the current context's default namespace — the wrong place to patch a Secret or read a ring from. Now refuses on unset, empty, or the un-substituted<namespace>placeholder, and step 2 uses"$NS"like the other two steps.3. Two self-contradicting comments, both from #976
deploy/sbx/setup.sh:758said the render "has no patch target" for a claim this run does not render, which reads as though that were a failure, while the block at:1393correctly says kustomize tolerates it. Verified on kustomize v5.8.1: an unmatchedpatches:target is skipped and the build exits 0 — so the storage class is simply never applied rather than failing the build, which is quieter and worse. The older sentence now says that.egress-credentials-vault/patch-control-plane.yamlsaid "re-reads it on every request" and "reads the sink ONCE, SYNCHRONOUSLY, at boot" four lines apart.vaultTokenSourcedoes both: it validates the sink once at boot (readFileSync) and re-reads it per request (readFile). The component and the runbook now both say validate at boot, then re-read per request.Testing
deploy/sbx/tests/overlay.test.sh: 22ok, exit 0.$NSguards exercised directly against the seven ring shapes above and the threeNSstates.bash -n deploy/sbx/setup.sh,prettier --check,make check-links(242 files, 0 broken): clean.No code paths change, so the control-plane suite is unaffected; CI's
checkleg covers it.Note
Finding 1 is a case of a fix introducing a narrower version of the bug it fixed — #976 closed the "empty key" path and opened a "drops two keys" path, and both are the same unrecoverable class. Worth knowing when reviewing the guard: it is now an entry-count check, not a substring check, which is what makes it hold.