Skip to content

feat(auth): reuse an in-date oidc client registration on sign-in - #35700

Merged
bolichen97 merged 1 commit into
mainfrom
fix/24640-reuse-oidc-registration
Nov 12, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/24640-reuse-oidc-registration

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A Builder ID or IAM Identity Center sign-in reuses the client registration its slot's stored sign-in already carries while that registration is in date, and registers a new client only when there is none it can safely use.

Every Builder ID and Identity Center sign-in calls RegisterClient and gets a brand-new SSO-OIDC client, even when the sign-in stored in the same slot carries one that is good for weeks. kiro-cli keeps its registration and reuses it until it lapses. #31630 stored the registration's expiry (client_secret_expires_at) and left reuse open on this issue.

Why it matters

An Identity Center user whose session ends every working day registers a new client each morning, and AWS keeps each one for about 90 days. Reusing the stored registration ends that churn and matches kiro-cli, while the expiry check keeps a sign-in from ever starting on a registration that has lapsed or is about to.

Not a goal

  • Keeping a registration across sign-out. Sign-out still deletes the stored sign-in and its registration with it, so the next sign-in registers anew.
  • Sharing one registration between the Builder ID and Identity Center slots, or between regions.
  • Changing refresh, KasToken.refresh_blocker, or what kirocrew doctor and the dashboard sign-in card say about a lapsed registration.

What changed (motivation → approach → change)

Crew registered a new client on every sign-in because _begin_oidc in auth/service.py never looked at the vault: it called RegisterClient unconditionally.

It now reads the slot's stored token first, and stored_client in auth/login/builder_id.py decides whether that token's registration can carry the new sign-in: same region, and a recorded expiry more than a week away (REUSE_MARGIN_SECS). The week is there because the approved token keeps the reused client and its expiry, and AWS refuses every refresh after that date: a registration in its last week would cut short the sign-in it starts, so it is replaced instead. Otherwise a new client is registered, as before.

If StartDeviceAuthorization answers the stored client with any error, the sign-in registers a new one and starts over once, so a registration AWS refuses cannot lock anyone out of signing in. The one exception is a refused start URL (StartUrlRejectedError): it is not a client problem and keeps its own error. The kas-auth spec states the rule beside the SSO-OIDC flow.

Stored in the slot The sign-in
Same region, expiry more than a week away reuses it
Lapsed, in its last week, no expiry recorded, another region, or nothing registers a new client
Reused, then any StartDeviceAuthorization error but a start-URL refusal registers a new client

Backwards compatibility

Compatible: nothing new is asked of a stored entry. One with no recorded expiry (written before #31630), from another region or without client credentials registers a new client exactly as today, and the approved token has the same shape either way.

Removes nothing: no key, field, path or behaviour goes away; a sign-in only skips a RegisterClient call it does not need.

Tests

  • test/test_kas_login_oidc_reuse.py::test_a_sign_in_reuses_the_slots_registration_while_it_is_in_date (Builder ID and Identity Center): an in-date stored registration from the same region becomes the pending login's client, and RegisterClient is never called.
  • test/test_kas_login_oidc_reuse.py::test_a_sign_in_registers_a_new_client_when_the_stored_one_cannot_serve: a lapsed registration, one two days from lapsing, one with no recorded expiry and one from another region each get a new client.
  • test/test_kas_login_oidc_reuse.py::test_a_refused_stored_registration_is_replaced_but_a_refused_start_url_is_not: a refused stored client is replaced by exactly one new registration; a refused start URL raises StartUrlRejectedError and registers nothing.
  • Related suites pass unchanged.

Proof: PROVEN test/test_kas_login_oidc_reuse.py::test_a_sign_in_reuses_the_slots_registration_while_it_is_in_date[builder_id-builder_id-kwargs0], test/test_kas_login_oidc_reuse.py::test_a_sign_in_reuses_the_slots_registration_while_it_is_in_date[idc-identity_center-kwargs1], test/test_kas_login_oidc_reuse.py::test_a_refused_stored_registration_is_replaced_but_a_refused_start_url_is_not (head f1e9f58)

The four registers_a_new_client cases pass with the fix reverted too: before the fix every sign-in registered, so they pin the cases that must keep doing so.

Determinism: the seven cases of test_kas_login_oidc_reuse.py passed 20 runs at -n0 and 10 at -n 4 --dist loadgroup beside test_kas_login_service.py and test_kas_login_signout_generation.py; those seven and the 80 tests of test_kas_login_service.py passed in a shuffled order (seed 6163). They read no clock race: each stored expiry is days away from the margin it is checked against.

Manual verification

N/A — unit coverage sufficient: the change is one decision before the two SSO-OIDC calls, and the tests fake those calls at the same seams the existing sign-in tests use. No live AWS sign-in was run.

Screenshots / video

N/A — no frontend file changes and nothing on screen changes.

Related Issues

Closes #24640

Follows #31630, which stored the registration expiry.

Sibling sweep

Swept: git grep -n "register_client(" -- src/
Siblings: none -- _begin_oidc is the only caller of register_client, so it is the only place a sign-in registers a client.

Pattern harvest

Not generalizable: the missing reuse was a decision this one call site never made, not a code pattern a rule could catch.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 12, 2026 01:19
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 12, 2026
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision f1e9f58fbb6a2ec987f5711a7fad37f5b8fa768b touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of f1e9f58fbb6a2ec987f5711a7fad37f5b8fa768b — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: reusing the stored registration within a week's margin, with one fallback to a new registration when the stored client is refused, matches the stated goal and takes nothing away.

Notes

  • The registration's scopes aren't stored, so the next OIDC_SCOPES change would silently reuse clients registered with the old scopes. The spec warns about this, but nothing enforces it. Storing the scopes with the token, or checking a scopes fingerprint in stored_client, would make that change safe on its own rather than relying on someone reading the spec.

[DESIGN-REVIEWED] f1e9f58

Description read

[DESCRIPTION-READ] 9ec0717a0f6e328ad99cfcc738a71c3bc0d46779f1ce293be2bf57dfb95554bf

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of f1e9f58fbb6a2ec987f5711a7fad37f5b8fa768b — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. Each item traces to #24640 or the client churn the description names, and the retry on a refused stored client stops the reuse from blocking sign-in.

Not checked: whether AWS's CreateToken accepts a reused client that StartDeviceAuthorization already accepted.

What this change ships

Inventory (6 items) — 5 justified

Intent: an Identity Center or Builder ID user stops creating a new SSO-OIDC client every time they sign in. This is an ADDITION (closes #24640).

  1. A sign-in reuses its slot's stored registration when it is from the same region and in date, and skips RegisterClient — justified
  2. A registration within a week of lapsing (REUSE_MARGIN_SECS) is replaced, not reused — justified
  3. If StartDeviceAuthorization refuses a stored client, the sign-in registers a new one and tries once more — justified
  4. A refused start URL keeps its own StartUrlRejectedError and registers nothing — justified
  5. A new info log line when a stored client is refused — undeclared, harmless
  6. The kas-auth spec states the reuse rule beside the SSO-OIDC flow — justified

[FIRST-PRINCIPLES-REVIEWED] f1e9f58

Description read

[DESCRIPTION-READ] dee2c3b0a4335d8a339909444afb5891fa028ae013dff01f8c7ded5ef635b558

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed f1e9f58fbb6a2ec987f5711a7fad37f5b8fa768b — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] f1e9f58

Verdict parsed from the review's SHA-scoped output markers for commit f1e9f58fbb6a2ec987f5711a7fad37f5b8fa768b.

False positive or not applicable? A repository writer can comment:
/ai-review override fable f1e9f58fbb6a2ec987f5711a7fad37f5b8fa768b false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of f1e9f58fbb6a2ec987f5711a7fad37f5b8fa768b and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] f1e9f58

False positive or not applicable? A repository writer can comment:
/ai-review override gpt f1e9f58fbb6a2ec987f5711a7fad37f5b8fa768b false-positive: <reason, 20 to 500 characters>

@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: Approve

Why: the decider estimates a 12% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes.

Reuse of a stored SSO-OIDC client is limited to the same slot and region, both client credentials present, and a recorded expiry more than a week away. Any non-start-URL BuilderIdAuthError from StartDeviceAuthorization falls back to one new registration and a restart, while StartUrlRejectedError is re-raised unchanged. The approved token carries the client that was actually used, along with its expiry. Other readers are unaffected: refresh keeps the client fields, doctor only reads the expiry, and the identity fingerprint includes client_id, but every completed sign-in bumps the sign-in generation, so account changes are still detected. Sign-out deletes the slot entry, so the next sign-in registers anew. _begin_oidc is the only caller of register_client and start_device_authorization. Tests cover reuse for both Builder ID and Identity Center, the four cases that must still register, and the fallback versus start-URL split. No existing test stores an in-date expiry, so none should start failing. No blocking issue found.

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit 5f19faedfc · 170 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@bolichen97
bolichen97 enabled auto-merge (squash) November 12, 2026 01:48
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 12, 2026
@bolichen97
bolichen97 force-pushed the fix/24640-reuse-oidc-registration branch from 5f19fae to 1d6cd3f Compare November 12, 2026 10:32
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in src/kiro_crew/auth/login/builder_id.py, src/kiro_crew/auth/service.py, test/test_kas_login_service.py and docs/system-specs/modules/kas-auth.md since this head's CI ran (ee7a026 -> 9ef0fc4); CI re-running.

The four Backend Tests reds on the previous head (test_wait_discipline_ratchet.py::test_the_scan_matches_known_sites and test_updates_handlers_facade.py::test_every_name_served_from_outside_the_family_is_visible_to_type_checkers, plus the Coverage Gate that fails closed on them) were main's: the same node ids failed on main's own push run at ce89396, and #35625 fixed both. The new base carries that fix, and both tests pass on it locally.

Main also grew test/test_kas_login_service.py to 1,540 lines, so this PR's three tests now live in a new test/test_kas_login_oidc_reuse.py, moved verbatim, which keeps every touched file under the 1,600-line working target. The production change is unchanged. New head: 1d6cd3f.

[operator: bolichen97]

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 12, 2026
Every Builder ID and IAM Identity Center sign-in registered a new
SSO-OIDC client, even when the slot's stored sign-in carried one that
was good for weeks. kiro-cli keeps its registration and reuses it until
it lapses.

A sign-in now reuses the registration its own slot's stored token
carries when it is from the same region and its recorded expiry is more
than a week away. Otherwise, or when StartDeviceAuthorization answers
the stored client with an error, it registers a new one as before.

Closes #24640
@bolichen97
bolichen97 force-pushed the fix/24640-reuse-oidc-registration branch from 1d6cd3f to f1e9f58 Compare November 12, 2026 16:26
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in src/kiro_crew/crew_log/eager.py, src/kiro_crew/dashboard/handlers/sessions_parts/slot_teardown.py and docs/system-specs/modules/ since this head's CI ran (9ef0fc4 -> e97c8ee); CI re-running.

The one Backend Tests red on the previous head (test/test_remove_slot_for_history_key_crew_log.py::TestSessionLedgerOnPermanentDelete::test_a_ledger_the_emitter_itself_opened_is_still_removed, plus the Coverage Gate that fails closed on it) was main's: the same node id failed on main's own push run at de6219e, and #35705 fixed the race behind it (closing #34376). The new base carries that fix, and the test file passes on it locally.

The patch itself is unchanged (identical range-diff); none of this PR's four files changed on main between those two bases. New head: f1e9f58.

[operator: bolichen97]

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 12, 2026

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve on f1e9f58. A sign-in now reuses the client registration that its own slot already stores, but only when the registration is from the same region, has both client credentials, and has a recorded expiry more than a week away. Anything else registers a new client, as main does. When the auth service refuses the reused client at the start of the device flow, the sign-in registers one new client and starts over, so a refused registration cannot lock a person out. A refused start URL keeps its own error. The registration's scopes are not recorded, so a future change to the requested scopes must also stop this reuse; today that rule lives only in the spec text, while kiro-cli checks the scopes in code. No secret is written or logged in a new place: the reused credentials come from the same vault entry and go only to the same auth endpoint. One backend test shard first failed on this head on a timing test in a file this PR does not touch; it passed on one rerun, and every check on this head is now green. Decisive lines: src/kiro_crew/auth/login/builder_id.py:158-173, src/kiro_crew/auth/service.py:430-446, test/test_kas_login_oidc_reuse.py:48-118

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Nov 12, 2026
@bolichen97
bolichen97 merged commit 0fc3b49 into main Nov 12, 2026
154 of 156 checks passed
@bolichen97
bolichen97 deleted the fix/24640-reuse-oidc-registration branch November 12, 2026 19:30
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 12, 2026
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.

KAS vault: persist the SSO-OIDC client registration expiry so a lapsed registration is diagnosable

3 participants