Repository navigation
Policy drafts for Custodian signing (§3.3, §10) - #23
Yoshiofthewire wants to merge 24 commits into
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process: ⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪🧪 PR contains tests⚡ No major issues detectedAdvisory only: this comment never gates the pull request. |
Security review - clearedDetail withheld: this repository is public, and posting an unfixed finding here would be public disclosure. The full report was posted to the hand-off board at https://myslop.urlxl.us/f/pr-reviewer-busnes-app-kyguard-server-23, where it is readable by the operator and expires seven days after the last post. gpt-6.1-sol using security-audit on behalf of Yoshi |
Autonomous review - 1/1 personas cleared
Merging remains a human decision; this bot never approves. gpt-6.1-sol using security-audit on behalf of Yoshi |
4ceacad to
2a03865
Compare
fd98ce6 to
4113285
Compare
2a03865 to
940da94
Compare
4113285 to
cecef40
Compare
940da94 to
724d59e
Compare
cecef40 to
f26bda4
Compare
724d59e to
d458abc
Compare
3d948f2 to
1777185
Compare
Migration 201 adds policy_drafts. An admin drafts an account's next PolicyManifest from a form; the Control Plane fills the header, pins an uploaded descriptor, requires every named principal to be enrolled and runs every admission check but the quorum before storing it. Custodians fetch the canonical object with its pinned target, sign it in kyguard-cli and post it back; a copy with another digest or fewer signatures is refused, and at quorum it is admitted as a manifest and the draft is removed. GET /api/principals and /api/trust feed the policy form and the dashboard's 1-of-1 warning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ject Two below-quorum submissions read from the same snapshot could each pass the keep-every-signature check and the later write would drop the earlier one's signature, because the digest leaves signatures out. SetDraftObject now updates only while the stored object is still the one the handler checked; the loser gets 409 and must re-fetch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
At quorum the handler submitted the policy without checking that the draft was still current, so a draft replaced or deleted meanwhile could still be admitted. The draft is now taken by compare-and-swap on the checked object before admission; a changed draft gets 409. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
At quorum the signed object is stored by compare-and-swap first (a replaced draft still gets 409), then submitted, and the draft removed only after admission, so an interrupted or failed submission no longer loses the collected signatures. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A draft whose admission was interrupted passes every check and is listed as ready. DECISIONS 211 now says plainly that deleting a draft does not veto a policy already at quorum. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1777185 to
937d12d
Compare
# Conflicts: # internal/store/migrate_postgres.go
If admission succeeded but the draft removal never committed, a retry failed Trust.Check (epoch already admitted) and the draft showed as stale. A signed draft whose digest is an admitted policy is now shown as ready, and posting it again removes the draft (CAS on the stored object) without a second submission. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # internal/store/AGENTS.md
Trust.Check accepts an identical retry while the policy is current, so the case that needs the digest check is an admitted draft whose policy was superseded before the retry; test that one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Note 🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire Incomplete recovery: fixed in 1328c6d, with the test in c92cb09. An immediate retry already worked, because |
The draft list, a draft, the signature post and the trust summary now use requireSession, so a break-glass session states its reason before it can read or sign policy drafts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # CHANGELOG.md # internal/api/AGENTS.md # internal/store/store.go
The reporting migrations moved to 300 below this branch (decision 204a), after main's auth stack took 200, so the draft table follows as 301. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main's route registry (#18) refuses routes registered outside it. Saving and deleting a draft need a five-minute step-up (§7.3 rule 6, decision 212); fetching and signing need none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In one line: Admins can draft an account's next policy in the Control Plane; Custodians fetch it, sign it in
kyguard-cli, post it back, and it takes effect only at quorum.§13 Phase 1A items: "policy drafts and Custodian signing (§3.3, §10)" (Control Plane side),
policy_drafts(§9.2).What changed
policy_drafts(one per account, canonical object + digest + epoch).PUT /api/accounts/{id}/policy-draftbuilds the next-epochPolicyManifest(header, kind and pool from the account), requires an uploaded descriptor and enrolled principals, and runs everyTrust.Checkrule except the quorum before storing it.GET /api/policy-drafts[/{id}]returns the object, the descriptor it pins and unverified labels (the shapecli.Draftexpects); stale drafts are flagged with the refusal code.POST /api/policy-drafts/{id}/signaturesaccepts the object back only with the same digest and every collected signature; at quorum it goes through the normal manifest admission and the draft is removed. The Control Plane never signs.GET /api/principals(admin) andGET /api/trust(custodian threshold, escrow default) feed the policy form and the dashboard's 1-of-1 warning.Review this
handleSignDraft: digest pinning, no dropped signatures, quorum →trust.Submit.handlePutDraft: what the admin form can and cannot set.Checked:
TestPolicyDraftSigning(unknown descriptor, non-admin, unenrolled principal,proxy_only, below-quorum, changed body, dropped signature, quorum acceptance, stale after a competing epoch); 9 mutations killed, including the concurrent-submission regression the security reviewer asked for.Not checked: the
kyguard-cliHTTP client for these routes (it waits for §7.6 login).Decided for you: DECISIONS 210–212.
You need to: nothing.
Detail
requireAuthenticatedSecurity P2 and the Guide's "lost signatures" (two submissions from one snapshot overwriting each other's signature, since the digest leaves signatures out) fixed in a87acec:
SetDraftObjectis a compare-and-swap on the whole stored object; the loser gets 409 and re-fetches. Guide "completion race" fixed in f26bda4: at quorum the draft is consumed by the same compare-and-swap before admission, so a draft replaced or deleted meanwhile is never admitted. Third round (04bf725): at quorum the fully signed object is stored by compare-and-swap first, then submitted, and the draft removed only after admission, so a failed or interrupted submission keeps the signatures. Fourth round (3d948f2): a fully signed draft whose admission was interrupted is listedready(tested). Round 4 (1328c6d, c92cb09): Guide "Incomplete recovery". An immediate retry already finished cleanup (Trust.Checkaccepts the same epoch and digest while it is current), but once a later policy was admitted the leftover draft wasstale(epoch_rollback) and a retry was refused. A draft whose digest is an admitted policy is nowready, and posting it removes it (compare-and-swap on the stored object, no second submission); D9. The draft list, a draft, the signature post andGET /api/trustuserequireSession(5aab6b2), so a break-glass session states its reason first (D10). Deleting a draft does not veto a policy already at quorum: it is a valid manifest anyone may post to/api/manifests(DECISIONS 211). The store-then-submit ordering is not covered by a test (forcingtrust.Submitto fail after its own check passed needs a fault hook).Routes marked
TODO(hawthorn §7.5): PUT/api/accounts/{id}/policy-draft, GET/DELETE/api/policy-drafts[/{id}], POST/api/policy-drafts/{id}/signatures, GET/api/principals, GET/api/trust.Round 6 (alder):
kyguard_policy_drafts), following Inventory: accounts, assets, descriptors and attributes (§8.2, §10) #20's move to 300 (main's backup: durable intents for pairing, pin and deposit (§9.3) #25 holds 200). No database has the old number.TestRegistryIsAscendingkeeps the order; the CHANGELOG andinternal/store/AGENTS.mdfollow.main's route registry, all session class. Saving (PUT /api/accounts/{id}/policy-draft) and deleting a draft need a step-up within five minutes (§7.3 rule 6). Fetching, posting signatures,/api/principalsand/api/trustneed none: the signatures are what authorize a policy, as forPOST /api/manifests(DECISIONS 212).TestReportingRoutesAreClassifiedWithTheirWindowspins the class and window of every report and draft route.fresh(StepupWindow)fromPUT /api/accounts/{id}/policy-draftTestReportingRoutesAreClassifiedWithTheirWindows(k82)Checks (round 6): vet plus
internal/api,internal/scim,internal/reporting,internal/storeon k80 (SQLite); full suites at the bottom (#20) and top (#24).🤖 Generated with Claude Code