Skip to content

Policy drafts for Custodian signing (§3.3, §10) - #23

Open
Yoshiofthewire wants to merge 24 commits into
kyguard/scim-enterprisefrom
kyguard/policy-drafts
Open

Yoshiofthewire wants to merge 24 commits into
kyguard/scim-enterprisefrom
kyguard/policy-drafts

Conversation

@Yoshiofthewire

@Yoshiofthewire Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

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

  • Migration 201 adds policy_drafts (one per account, canonical object + digest + epoch).
  • PUT /api/accounts/{id}/policy-draft builds the next-epoch PolicyManifest (header, kind and pool from the account), requires an uploaded descriptor and enrolled principals, and runs every Trust.Check rule except the quorum before storing it.
  • GET /api/policy-drafts[/{id}] returns the object, the descriptor it pins and unverified labels (the shape cli.Draft expects); stale drafts are flagged with the refusal code.
  • POST /api/policy-drafts/{id}/signatures accepts 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) and GET /api/trust (custodian threshold, escrow default) feed the policy form and the dashboard's 1-of-1 warning.

Review this

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-cli HTTP client for these routes (it waits for §7.6 login).
Decided for you: DECISIONS 210–212.
You need to: nothing.

Detail
# Mutation Killed by
D1 signed object with another digest stored TestPolicyDraftSigning
D2 dropped signature accepted TestPolicyDraftSigning
D3 accepted below quorum TestPolicyDraftSigning
D4 unenrolled principal accepted TestPolicyDraftSigning
D5 descriptor never uploaded accepted TestPolicyDraftSigning
D6 drafts open to any session TestPolicyDraftSigning
D7 below-quorum update ignores the object it checked TestDraftObjectCompareAndSwap
D8 a replaced draft can be taken for admission TestTakeDraftCompareAndSwap
D10 draft and trust routes back to requireAuthenticated TestReportingRoutesWaitForBreakGlassReason
D9 an admitted draft is not recognised by digest (revert of 1328c6d) TestPolicyDraftSigning ("admitted draft … status:stale code:epoch_rollback")

Security 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: SetDraftObject is 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 listed ready (tested). Round 4 (1328c6d, c92cb09): Guide "Incomplete recovery". An immediate retry already finished cleanup (Trust.Check accepts the same epoch and digest while it is current), but once a later policy was admitted the leftover draft was stale (epoch_rollback) and a retry was refused. A draft whose digest is an admitted policy is now ready, and posting it removes it (compare-and-swap on the stored object, no second submission); D9. The draft list, a draft, the signature post and GET /api/trust use requireSession (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 (forcing trust.Submit to 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):

  • Migration 201 → 301 (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. TestRegistryIsAscending keeps the order; the CHANGELOG and internal/store/AGENTS.md follow.
  • The draft routes go through 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/principals and /api/trust need none: the signatures are what authorize a policy, as for POST /api/manifests (DECISIONS 212).
  • New TestReportingRoutesAreClassifiedWithTheirWindows pins the class and window of every report and draft route.
# Mutation (round 6, throwaway copy) Killed by
R2 drop fresh(StepupWindow) from PUT /api/accounts/{id}/policy-draft TestReportingRoutesAreClassifiedWithTheirWindows (k82)

Checks (round 6): vet plus internal/api, internal/scim, internal/reporting, internal/store on k80 (SQLite); full suites at the bottom (#20) and top (#24).

🤖 Generated with Claude Code

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪

🧪 PR contains tests

⚡ No major issues detected


Advisory only: this comment never gates the pull request.
gpt-6.1-sol using pr-agent on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Security review - cleared

Detail 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

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Autonomous review - 1/1 personas cleared

  • security: cleared

Merging remains a human decision; this bot never approves.


gpt-6.1-sol using security-audit on behalf of Yoshi

@Yoshiofthewire
Yoshiofthewire force-pushed the kyguard/scim-enterprise branch from 4ceacad to 2a03865 Compare November 25, 2026 12:49
@Yoshiofthewire
Yoshiofthewire force-pushed the kyguard/scim-enterprise branch from 2a03865 to 940da94 Compare November 25, 2026 12:51
@Yoshiofthewire
Yoshiofthewire force-pushed the kyguard/scim-enterprise branch from 940da94 to 724d59e Compare November 25, 2026 13:07
@Yoshiofthewire
Yoshiofthewire force-pushed the kyguard/scim-enterprise branch from 724d59e to d458abc Compare November 25, 2026 13:21
@Yoshiofthewire
Yoshiofthewire force-pushed the kyguard/policy-drafts branch 4 times, most recently from 3d948f2 to 1777185 Compare November 25, 2026 14:22
Yoshiofthewire and others added 7 commits November 25, 2026 09:35
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>
# Conflicts:
#	internal/store/migrate_postgres.go
Yoshiofthewire and others added 3 commits November 25, 2026 14:22
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>
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>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

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 Trust.Check treats the same epoch and digest as already current. Once a later policy is admitted, though, the leftover draft was stale (epoch_rollback) and a retry was refused. A draft whose digest is an admitted policy is now ready, and posting it removes the draft (compare-and-swap on the stored object, no second submission). TestPolicyDraftSigning admits the draft's policy and then epoch 3, and expects ready and a successful cleanup; reverting the fix fails it with stale/epoch_rollback (D9).

Yoshiofthewire and others added 12 commits November 25, 2026 16:03
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant