Skip to content

api: classified route registry and per-action step-up (§7.5, §7.3 rule 6) - #18

Merged
Yoshiofthewire merged 8 commits into
mainfrom
kyguard/routes
Nov 25, 2026
Merged

Yoshiofthewire merged 8 commits into
mainfrom
kyguard/routes

Conversation

@Yoshiofthewire

@Yoshiofthewire Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

In one line: Every route is now registered through one classified registry, so an unclassified or stray route fails a test. Backup actions and factor resets need a fresh step-up.

What changed

  • s.route(class, pattern, handler, opts...) is the only way onto the main mux, SCIM's routes included. The classes are public, machine, pending and session (spec §7.5 table). Session routes get the active-session middleware (and CSRF for cookies) there.
  • TestEveryRouteIsClassified parses the source and fails on any Handle/HandleFunc outside the registry, and pins the spec table. A route without a class panics at registration.
  • Every session route is walked with anonymous and pending callers, by cookie and by Bearer.
  • Backup actions need a step-up within 5 minutes (fresh(StepupWindow)). An active session refreshes it with a code.
  • An admin can delete an SSO user's TOTP factor with a fresh code of their own. The user's sessions end, and the next sign-in enrolls again. Break-glass factors are not reachable over the web.

Review this

Checked: go test -race and the FIPS profile, full suite, SQLite and PostgreSQL 17 at this head. Mutation table below.
Not checked: the compose e2e locally (CI only, see #3).
You need to: review. Held unmerged by rule.

§13 Phase 0 checklist: Route registry and classification table (§7.5), plus the per-action step-up of §7.3 rule 6. Acceptance 11.

Detail

Mutation table (each mutation makes the named test fail)

# Property Mutation Failing test
R1 A route without a class is refused accept an empty class TestRouteWithoutAClassPanics
R2 Backup actions need step-up within 5 min widen or skip the freshness check TestBackupActionsNeedAFreshStepUp
R3 No registration outside the registry add a mux.HandleFunc in another file TestEveryRouteIsClassified
R4 Break-glass factors are not web-resettable allow account_type = break_glass TestAdminFactorResetNeedsAFreshCode
R5 A factor reset needs a fresh code skip the code check TestAdminFactorResetNeedsAFreshCode

hawthorn ran R1–R5 at the pre-rebase head 25f8da9. Since then the branch moved only by rebasing and by one test change (the reset's wrong code no longer leans on 000000).

Checks at 283d936

  • gofmt, go vet, go build, go test -race -count=1 -p 2 ./... and the same under GODEBUG=fips140=on: SQLite pass (Major, kslot; every K host was busy); PostgreSQL 17 pass (Major, own postgres:17-alpine container). Exit 0 on both.

Stack

#1 → #3 → #7 → #17 → #18 (this) → #19.

Review fixes (hawthorn fix-auth)

  • Security P2 (54bd0f2): DeleteFactor takes the same user-row lock as every session issuance. An exchange authorized by the old factor either commits first, and its session is deleted with the rest, or waits and finds the factor gone.
  • Guide, pending-session regression: not reproduced. AuthenticateRequest admits pending sessions on /api/auth/stepup/* (pendingAllowed). TestEnrolledUserStepsUpAPendingSession now pins that an enrolled user's pending session exchanges with a code.
Property Mutation Test Result
no session survives a factor reset drop the user-row lock TestFactorResetRacingAnExchangeLeavesNoSession fails on PostgreSQL (round 1)
an enrolled pending session can step up pendingAllowed admits only /stepup/enroll* TestEnrolledUserStepsUpAPendingSession fails (401)

Checked at 54bd0f2: race and FIPS suites on SQLite (k82) and PostgreSQL 17 (k80), exit 0; the factor-reset race also 3/3 on my own PostgreSQL container.

Stack merge (hawthorn fix-auth-3): head 62f55c3 merges kyguard/stepup (plain merge commit, no rebase), so this PR carries #7's fail-closed SSO sign-in (9220dd7) and every fix below it. The only conflicts were in docs/DECISIONS.md, and both sides were kept. Go vet passes at this head; CI runs the suites.

Round 4 (hawthorn): Guide "Pending Authentication"

  • activeSession now refuses any session whose stage is not active, answering 403 stepup_required (d737ccf). It no longer relies on AuthenticateRequest's path list alone. That list admits pending sessions on /api/auth/stepup/* by design, which is how handleStepupTOTP serves a pending session; the handler now says so in a comment. A session-class route is therefore unreachable before step-up whatever its path.
  • On the note itself: /api/auth/stepup/totp still admits a pending session, so an enrolled SSO user still completes sign-in. TestEnrolledUserStepsUpAPendingSession and TestOIDCSignInStepsUpToActive pass at this head.
Property Mutation Test Result
A session route refuses a pending session by its stage disable the new stage check in activeSession TestSessionClassChecksTheStageOnStepUpPaths (a session route registered under /api/auth/stepup/) fails (404: the pending session got through)

Also merges kyguard/stepup (main, and #17's web fix).

Round 4b (hawthorn): main merged; broker routes classified

  • bd2fb58 merges origin/main, which now has Broker listener, CA and pairing (§4.1) #8's broker routes. Broker listener, CA and pairing (§4.1) #8 registered them with s.mux.HandleFunc under TODO(hawthorn §7.5). They now go through the registry, and TestEveryRouteIsClassified would fail on the raw calls:
    • POST /api/broker-pools and POST /api/broker-pools/{id}/pairing-tokens: session routes with the 5-minute step-up window (§7.3 rule 6: broker and pairing actions).
    • POST /api/manifests: a session route with no window. Rule 6 does not list it, and the Custodian signatures are what authorize it (DECISIONS 16a). requireAuthenticated has no callers left and is removed.
  • TestSessionRoutesRefusePendingSessions now walks the three broker routes too.
Property Mutation Test Result
Broker and pairing actions need fresh step-up drop fresh(StepupWindow) from POST /api/broker-pools TestBrokerRoutesAreClassifiedWithTheirWindows fails

Checks: race + FIPS on SQLite and PostgreSQL 17, at the bottom (#18 @ bd2fb58: SQLite k81 exit 0, PostgreSQL own container exit 0) and the top (#28 @ 0cb6d83: SQLite k82 exit 0, PostgreSQL own container exit 0). Affected packages were also run at this head on k82.

🤖 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-18, 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 and others added 3 commits November 25, 2026 07:52
Every main-mux route, SCIM's included, now registers through one
function with its spec §7.5 class (public, machine, pending, session);
session routes get the active-session middleware there. A test fails
on any Handle or HandleFunc outside the registry, pins the spec table,
and walks every session route with anonymous and pending callers.

Backup actions need a step-up within five minutes (spec §7.3 rule 6);
an active session refreshes it with a code. Administrators can reset
an SSO user's TOTP factor with a fresh code of their own; the user's
sessions end and the next sign-in enrolls again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DeleteFactor now holds the same user-row lock as every session
issuance, so an exchange authorized by the old factor either commits
first and its session is deleted with the rest, or waits and finds the
factor gone (security review P2; PostgreSQL race test). A test also
pins that an enrolled user's pending session steps up with a code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Security P2 (factor reset vs exchange) fixed in 54bd0f2: DeleteFactor takes the user-row lock every session issuance holds. TestFactorResetRacingAnExchangeLeavesNoSession races them; without the lock it fails on PostgreSQL in round 1. Guide (pending-session regression): not reproduced. AuthenticateRequest admits pending sessions on /api/auth/stepup/* (pendingAllowed). TestEnrolledUserStepsUpAPendingSession now pins the enrolled-user exchange and fails (401) if that allowance is narrowed.

@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Guide (pending sessions rejected), again at 54bd0f2: not reproduced. AuthenticateRequest admits a pending session on /api/auth/stepup/* (pendingAllowed in internal/auth/session.go); activeSession is the session-class middleware, not this path. TestEnrolledUserStepsUpAPendingSession is in this head and passes on both drivers; it fails with 401 if pendingAllowed stops admitting /stepup/totp.

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

"Pending sessions rejected" still doesn't reproduce at 62f55c3, which now merges #7's fail-closed sign-in through #17. AuthenticateRequest refuses a pending session only outside pendingAllowed, and pendingAllowed admits /api/auth/stepup/* (internal/auth/session.go). So the step-up handler reaches the code check and the exchange.

TestEnrolledUserStepsUpAPendingSession and TestOIDCSignInStepsUpToActive pass at this head. Removing the /api/auth/stepup/ prefix from pendingAllowed makes both fail with enroll: 401 Authentication required. That is the regression the note describes, and the tests catch it.

Yoshiofthewire and others added 2 commits November 25, 2026 14:57
AuthenticateRequest admits a pending session on /api/auth/stepup/*, so
activeSession now refuses any non-active stage itself (403
stepup_required). The step-up handler says why it accepts both stages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
Brings #17's step-up retry and #18/#25 fixes up. web/dist rebuilt from
the merged sources with Node 26.13.1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire
Yoshiofthewire changed the base branch from kyguard/stepup to main November 25, 2026 21:59
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Merger (saltmarsh-merge): closing and reopening right away so CodeQL runs now that the base is main. The branch is unchanged.

Brings #8's broker routes in. server.go: both sides kept. The broker
routes now register through the route registry (the TODOs #8 left
here): pools and pairing tokens are session routes with the 5-minute
step-up window, manifests a session route without one (DECISIONS 16a).
requireAuthenticated has no callers left and is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire
Yoshiofthewire merged commit 3fe2322 into main Nov 25, 2026
16 checks passed
Yoshiofthewire added a commit that referenced this pull request Nov 26, 2026
main's route registry (#18) removed requireAuthenticated. Reserving and
submitting an enrollment need a five-minute step-up (§4.5).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yoshiofthewire added a commit that referenced this pull request Nov 26, 2026
main's route registry (#18) removed requireAuthenticated. Inventory and
attribute writes need a five-minute step-up (decision 206).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yoshiofthewire added a commit that referenced this pull request Nov 26, 2026
…suer

main's route registry (#18) refuses routes registered outside it, and
main now stores the SSO issuer on the user (§7.2), so a principal is
matched by the caller's stored issuer and subject, not only for KySignOn.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yoshiofthewire added a commit that referenced this pull request Nov 26, 2026
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