Skip to content

auth: kyguard-cli login, server side (§7.6) - #27

Merged
Yoshiofthewire merged 9 commits into
mainfrom
kyguard/cli-login
Nov 26, 2026
Merged

Yoshiofthewire merged 9 commits into
mainfrom
kyguard/cli-login

Conversation

@Yoshiofthewire

@Yoshiofthewire Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

In one line: kyguard-cli login has its server side. An SSO login started by the CLI hands a 60-second one-time code to the CLI's loopback listener, and the CLI trades it for a pending session to step up in the terminal.

What changed

  • /api/sso/{kysignon,oidc}/login takes optional cli_port (1024–65535) and cli_challenge (S256). They ride with the SSO state in a short-lived cookie.
  • On such a login the callback issues no browser session. It stores a one-time code (migration 17, cli_login_codes), valid 60 seconds and bound to the verified login (issuer, sid, original iat, MFA assertion) and the challenge, and redirects to http://127.0.0.1:<port>/cb?code=….
  • POST /api/auth/cli/exchange (public, spec §7.5 table) spends the code on its first attempt, even a wrong one, then checks the verifier. It returns a pending session as a bearer token. CreateSession re-checks both logout fences after commit.
  • Step-up over bearer (/api/auth/stepup/totp, /enroll/confirm) returns the new active token in the body. Cookie callers never get it in the body.
  • Expired codes are cleaned with expired sessions; restore already deletes them (backup: broker CA in the capsule; restore clears every credential (§9.4) #26).

Review this

Checked: full suite with -race, plus the FIPS profile, on SQLite (k83) and PostgreSQL 17 (k82) at ecb2439, exit 0. All 6 mutations fail their tests; the concurrent fence test fails on PostgreSQL without the re-check.
Not checked: the CLI side. It is juniper's internal/cli.Client on the other stack (#6), and wiring it is a join task.
Decided for you: loopback only on 127.0.0.1 with ports from 1024; a wrong verifier burns the code (DECISIONS 19g).
Review fix (90db0d5): a factor reset deletes the user's outstanding CLI codes first, and redemption spends the code and inserts its session in one transaction, so a pre-reset code redeems nothing (security P2). Checked at 90db0d5: race and FIPS suites on SQLite (k80) and PostgreSQL 17 (Major, own container), exit 0.
You need to: review. Held unmerged by rule.

§13 Phase 0 checklist: Route registry and classification table (§7.5); CLI login (§7.6): the CLI-login half, server side. Acceptance 7, the CLI-redemption clauses (sequential and concurrent).

Detail

Mutation table (each mutation makes the named test fail)

# Property Mutation Failing test
C1 The verifier must match the challenge skip the comparison TestCLILoginHandsAPendingSessionToTheCLI
C2 A logout before redemption ends it drop the post-commit fence check TestLogoutBeforeCLIRedemptionEndsTheSignIn; TestLogoutRacingCLIRedemptionLeavesNoSession on PostgreSQL (3/3 runs)
C3 A code lives 60 s ignore expires_at TestExpiredCLICodeIsRefused
C4 A CLI login sets no browser session skip the hand-off TestCLILoginHandsAPendingSessionToTheCLI
C5 Only bearer callers get a token in the body always include it TestBrowserExchangeNeverReturnsTheToken
C6 Redemption yields a pending session issue it active TestCLILoginHandsAPendingSessionToTheCLI
C7 A factor reset voids outstanding codes the reset leaves codes TestFactorResetVoidsOutstandingCLICodes (200); TestFactorResetRacingCLIRedemptionLeavesNoSession on PostgreSQL (round 0)

Stack

#1 → #3 → #7 → #17 → #18 → #19 → #25 → #26 → this.

Stack merge (hawthorn fix-auth-3): head 30cdac4 merges kyguard/restore (plain merge commits, no rebase; 87a06d9 merged it first, and 30cdac4 adds a content-free merge of the pushed commit below), 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): stack merged up from main

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

Spec §7.6: an SSO login started with cli_port and an S256 cli_challenge
ends at the callback with no browser session. Instead a one-time code,
valid 60 seconds and bound to the verified login (issuer, sid, original
iat, MFA assertion), goes to http://127.0.0.1:<port>/cb.
POST /api/auth/cli/exchange spends the code on its first attempt,
checks the verifier and issues a pending session as a bearer token;
CreateSession re-checks both fences after commit. Step-up over bearer
returns the active token in the body, never to cookie callers.

cli_login_codes (migration 17) is in migrationTables, expired codes
are cleaned with expired sessions, and restore already deletes them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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-27, 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

Security review P2: a CLI code issued before a TOTP reset could still
buy a pending session carrying the old MFA assertion. DeleteFactor now
deletes the user's codes first in its transaction, and redemption
spends the code and inserts its session in one transaction, so the
code row orders the two (sequential and PostgreSQL race tests).

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

Copy link
Copy Markdown
Member Author

Security P2 (CLI codes survive a factor reset) fixed in 90db0d5: DeleteFactor deletes the user's cli_login_codes first in its transaction, and RedeemCLICode spends the code and inserts the session in one transaction, so the code row orders the two. TestFactorResetVoidsOutstandingCLICodes (a pre-reset code → 401) and the PostgreSQL race TestFactorResetRacingCLIRedemptionLeavesNoSession both fail when the reset leaves the codes.

Yoshiofthewire and others added 7 commits November 25, 2026 09:29
…-login

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Picks up the stack's merge commits as pushed. No content change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Migration 17 (cli_login_codes) stays; migration 16 is gone (#25 moved
the intents table to migration 200). migrate_postgres keeps both lists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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/restore to main November 25, 2026 23:50
@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.

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