Skip to content

fix(auth): read a re-sign-in as an account change in the vault fingerprint - #25608

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/vault-signin-generation-24942
Oct 29, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/vault-signin-generation-24942

Conversation

@CrysisDeu

@CrysisDeu CrysisDeu commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: after a sign-in as another account of the same kind, Crew treats the vault as a new account.

auth/bridge.vault_identity_fingerprint hashes identity, provider, profile_arn, region, client_id, token_endpoint and auth_method. It leaves out credentials on purpose, so a token refresh is not read as an account change. When two same-kind sign-ins (Google A, then Google B) come back with the same profileArn, every one of those fields matches, and the fingerprint does not move.

Why it matters

Two readers depend on that fingerprint:

  1. The KAS bundle-route model catalog (agent_sdk/kas_model_catalog.py): B gets A's recorded models and credit multipliers until B's first session records its own.
  2. The pre-turn identity sweep (kiro_prerequisite_identity._crew_vault_fingerprint, chat_turn/account_identity._retire_sessions_on_identity_change): sessions started under A are not retired.

Not a goal

  • Telling accounts apart by decoding the access token.
  • Changing how a token refresh is fingerprinted.

Intended? / Repro

Intended? No. The fingerprint's own docstring says "a Crew sign-out or account switch changes this value" (src/kiro_crew/auth/bridge.py:135-147), and the GPT review on #23618 found the gap.

Repro (read on current main):

  • src/kiro_crew/auth/bridge.py:104-112 (_VAULT_IDENTITY_CLAIMS) and :124-132 (_identity_digest): only those seven claims.
  • src/kiro_crew/auth/login/device.py _token_from_poll builds the social token from profileArn, provider and the poll's tokens; two Google accounts answered with one profileArn produce the same seven claims, so vault_identity_fingerprint() returns the same digest before and after the second sign-in.

What changed (motivation → approach → change)

Symptom: an account switch looks unchanged. Cause: no fingerprinted field names the sign-in. Change: a sign-in marker the fingerprint folds in, as the issue proposes.

  • auth/store.py: TokenStore.signin_generation() / bump_signin_generation(), file kas/signed-in, a fresh random value per bump. Same shape as the existing signout_generation.
  • auth/service.py: _persist_and_finish bumps it right BEFORE self._store.save(token), inside the same with_signout_lock flock. The dashboard and kirocrew kas login both build KasLoginService, so both write it. The refresh path never calls this code, so a refresh does not bump it. Fail closed: a marker that cannot be written raises before the save, and the login answers token_store_failed with nothing saved, because a saved sign-in the fingerprint cannot see would keep serving the previous account's state. A save that fails after the bump leaves only a moved marker, which reads as an account change (the safe side).
  • auth/bridge.py: vault_identity_claims reads the token and the marker together under with_signout_lock, the flock a login holds from its bump to its save, so a read never pairs the previous account's token with a marker the login has just moved. _identity_digest folds the marker in when it is set. An unmarked vault (signed in before this change) keeps the digest it had, so upgrading does not read as an account change.
  • docs/system-specs/modules/kas-auth.md: a Sign-in generation paragraph beside the sign-out one.

A same-account re-sign-in also bumps the marker: the catalog goes cold and the sweep retires once. The issue calls that the safe answer.

Security

area: auth. The marker is a random token in the owner-only kas/ directory (make_owner_only_dir, _assert_unlinked), never returned: only its hash reaches the fingerprint. No credential, claim or file permission changes.

Backwards compatibility

Compatible. An unmarked vault fingerprints exactly as on main. The first sign-in after upgrade changes the fingerprint once, which is the point.

Removes nothing: no key, field or error path is removed.

Tests

test/test_kas_login_signout_generation.py:

  • test_a_second_sign_in_with_the_same_profile_arn_moves_the_fingerprint: two device sign-ins with one profileArn; the marker and the fingerprint both change. Fails on main.
  • test_a_refresh_write_does_not_move_the_fingerprint: re-saving a refreshed token keeps the fingerprint.
  • test_an_unmarked_vault_keeps_the_fingerprint_it_had: no marker → the plain claims digest.
  • test_a_sign_in_whose_marker_cannot_be_written_saves_nothing: the poll answers token_store_failed and the vault stays empty.
  • test_the_fingerprint_read_waits_for_a_sign_in_between_its_marker_and_its_save: a read started between the bump and the save waits for the lock and fingerprints the saved sign-in.

Proof: not provable -- other: this host runs no local tests; CI runs them

Manual verification

N/A: needs two same-kind accounts. Static gates run locally: black, isort, flake8, scripts/docs_lint.py, scripts/check_file_line_cap.py, comment-history gate.

Related Issues

Fixes #24942

Sibling sweep

Swept: git grep -n "vault_identity_fingerprint|vault_identity_claims|_identity_digest" -- src/
Sibling: src/kiro_crew/auth/bridge.py -- changed here (the one digest)
Sibling: src/kiro_crew/agent_sdk/kas_model_catalog.py -- not affected (reads the fingerprint)
Sibling: src/kiro_crew/kiro_prerequisite_identity.py -- not affected (reads the fingerprint)
Sibling: src/kiro_crew/dashboard/handlers/kiro_vault_identity.py -- not affected (reads the claims)

Pattern harvest

Not generalizable: one marker, the sibling of an existing one.

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

Contributed under the project's Apache-2.0 license.

@CrysisDeu
CrysisDeu requested review from a team and KiroCrewCaptain as code owners October 29, 2026 03:11
@CrysisDeu
CrysisDeu requested a review from buluoray October 29, 2026 03:12
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 29, 2026
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 4f4b09473026029dc2164fbad06ade6e2607b6cd 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 Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: the sign-in marker addresses the cause, and _persist_and_finish is the only place that saves a token.

Notes

  • Every fingerprint read now takes the exclusive sign-out flock with O_CREAT. On Windows the bounded poll can time out while a sign-in or sign-out holds the lock, and the read then returns "". Consumers already handle "" as an unreadable vault, but that turn may still see a spurious change. A shared lock would fit a read better.

[DESIGN-REVIEWED] 4f4b094

Description read

[DESCRIPTION-READ] 6f713ee3cbbd30c1193f9c78dbddbd7d58ab7bcb19f7bed841cc769a6db2abf3

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 Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 4f4b09473026029dc2164fbad06ade6e2607b6cd — 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 has a named cause: issue #24942 and the fingerprint docstring's "a Crew sign-out or account switch changes this value". Each one fixes the mechanism, and the one save site has no unfixed sibling.

What this change ships

Inventory (6 items) — 6 justified

Intent: when someone signs in as a second account of the same kind, Crew stops serving the first account's model catalog and sessions. This is a FIX.

  1. Signing in as another same-kind account with the same profileArn now reads as an account change: the catalog goes cold and old sessions are retired. — justified
  2. Signing in again as the same account also retires sessions once and cools the catalog. — justified
  3. If the sign-in marker cannot be written, the login fails with token_store_failed and nothing is saved. — justified
  4. A new persisted file, kas/signed-in, holds a random marker. — justified
  5. The fingerprint read now waits on the sign-out flock, so it reads the token and the marker together. — justified
  6. The kas-auth spec gains a "Sign-in generation" paragraph. — justified

[FIRST-PRINCIPLES-REVIEWED] 4f4b094

Description read

[DESCRIPTION-READ] 255cfaf6867a280d8c794e89efc12b7dc5557b692bc97d890a777bc58738d0a0

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 Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 4f4b094

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

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

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 4f4b094

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

@CrysisDeu
CrysisDeu force-pushed the fix/vault-signin-generation-24942 branch 2 times, most recently from efa136f to 7aa19b7 Compare October 29, 2026 04:06
@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 Oct 29, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/vault-signin-generation-24942 branch from 7aa19b7 to ff3689f Compare October 29, 2026 11:30
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: ff3689f
  • What rule changed: the vault identity fingerprint (auth/bridge.vault_identity_claims) now folds in a sign-in marker (TokenStore.signin_generation, file kas/signed-in, a fresh random value per sign-in). KasLoginService._persist_and_finish bumps the marker right before it saves a new credential, inside with_signout_lock. The fingerprint reads the token and the marker together under the same lock. A token refresh never bumps it.
  • Before -> after (what was allowed/blocked, now): Before, signing in as Google account B after Google account A with the same profileArn left the fingerprint unchanged, so B was served A's model catalog and A's sessions were not retired. After, every completed sign-in changes the fingerprint. An unmarked vault (signed in before this change) keeps the digest it had. A marker that cannot be written fails the login with token_store_failed and saves nothing.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): an account switch is still missed (the old behavior), or a same-account re-sign-in turns the catalog cold and retires sessions once (by design). A marker write failure blocks sign-in with token_store_failed until kas/ is writable. No secret is exposed: the marker sits in the owner-only kas/ directory and only its hash reaches the fingerprint.
  • Evidence checked (which sandbox result proves it): code read of the new lock ordering (the read and the login both take the sign-out flock). The new test test_the_fingerprint_read_waits_for_a_sign_in_between_its_marker_and_its_save now waits on a positive signal (a wrapper around store.acquire_lock sets an Event when the reader thread reaches the lock) instead of a timed join, then saves and checks the reader fingerprints the saved sign-in. CI runs it; this host runs no local tests.
  • No regression:
    • Tools still work (which tools/commands were run, result): static gates (black, isort, flake8, line cap, docs lint, comment-history, brand) pass on this head.
    • Backward compatible (old config / old data / old callers still work, how checked): _identity_digest adds nothing when the marker is empty, pinned by test_an_unmarked_vault_keeps_the_fingerprint_it_had; refresh writes are pinned by test_a_refresh_write_does_not_move_the_fingerprint.
    • Existing tests (which suites passed on this head): CI runs the suite on this head; this host runs no local tests.
  • How to undo: revert this PR's commit; the fingerprint returns to the seven claims and the kas/signed-in file is ignored.

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

Two accounts of one kind can come back with the same profileArn, and none
of the claims vault_identity_fingerprint hashes tells them apart, so after
A then B the KAS bundle-route model catalog served A's models to B and the
identity sweep did not retire A's sessions.

The vault now carries a sign-in generation (kas/signed-in), shaped like
the sign-out one: the login service bumps it right after it saves a new
credential, inside the same flock, and a refresh does not. The
fingerprint folds it in when set, so both readers see every completed
sign-in as a change; an unmarked vault keeps its fingerprint.

Fixes #24942
@CrysisDeu
CrysisDeu force-pushed the fix/vault-signin-generation-24942 branch from ff3689f to 4f4b094 Compare October 29, 2026 11:57
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 4f4b094
  • What rule changed: the vault identity fingerprint (auth/bridge.vault_identity_claims) now folds in a sign-in marker (TokenStore.signin_generation, file kas/signed-in, a fresh random value per sign-in). KasLoginService._persist_and_finish bumps the marker right before it saves a new credential, inside with_signout_lock. The fingerprint reads the token and the marker together under the same lock. A token refresh never bumps it.
  • Before -> after (what was allowed/blocked, now): Before, signing in as Google account B after Google account A with the same profileArn left the fingerprint unchanged, so B was served A's model catalog and A's sessions were not retired. After, every completed sign-in changes the fingerprint. An unmarked vault (signed in before this change) keeps the digest it had. A marker that cannot be written fails the login with token_store_failed and saves nothing.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): an account switch is still missed (the old behavior), or a same-account re-sign-in turns the catalog cold and retires sessions once (by design). A marker write failure blocks sign-in with token_store_failed until kas/ is writable. No secret is exposed: the marker sits in the owner-only kas/ directory and only its hash reaches the fingerprint.
  • Evidence checked (which sandbox result proves it): code read of the new lock ordering (the read and the login both take the sign-out flock). The new test test_the_fingerprint_read_waits_for_a_sign_in_between_its_marker_and_its_save now waits on a positive signal (a wrapper around store.acquire_lock sets an Event when the reader thread reaches the lock) instead of a timed join, then saves and checks the reader fingerprints the saved sign-in. CI runs it; this host runs no local tests.
  • No regression:
    • Tools still work (which tools/commands were run, result): static gates (black, isort, flake8, line cap, docs lint, comment-history, brand) pass on this head.
    • Backward compatible (old config / old data / old callers still work, how checked): _identity_digest adds nothing when the marker is empty, pinned by test_an_unmarked_vault_keeps_the_fingerprint_it_had; refresh writes are pinned by test_a_refresh_write_does_not_move_the_fingerprint.
    • Existing tests (which suites passed on this head): CI runs the suite on this head; this host runs no local tests.
  • How to undo: revert this PR's commit; the fingerprint returns to the seven claims and the kas/signed-in file is ignored.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Oct 29, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

Hold for human review at 4f4b09473026029dc2164fbad06ade6e2607b6cd. The change is policy-sensitive: it changes the vault identity fingerprint that decides session retirement and the KAS model catalog, the login save path, and the locking on every fingerprint read. Per the reviewer policy, identity-trust changes go to a human.

I found no defect. The marker is folded in only when set, so existing vaults keep their digest (bridge.py#L124-L142). The login bumps it under the sign-out lock after the sign-out generation check and before the save. A failed write returns token_store_failed and saves nothing (service.py#L709-L737). No fingerprint reader runs inside a with_signout_lock body, so the new locked read cannot self-deadlock. CI and the AI lanes are green on this head.

Non-blocking, for the human reviewer: the Design Review note is accurate. On Windows, a fingerprint read that times out on the exclusive lock while a sign-in or sign-out holds it returns "" for that turn. The account is changing at that moment anyway, so the cost is at most one extra session sweep. A shared lock for the read would remove it.

To clear: a maintainer reviews and approves the identity change.

— crew-pr-reviewer (r135)

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved on behalf of the watch holder (bolichen). Design and First Principles pass on this head (or skipped / author override), UX skipped or pass, no conflict, no open change request.

@KiroCrewCaptain
KiroCrewCaptain merged commit 883556b into main Oct 29, 2026
94 of 95 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/vault-signin-generation-24942 branch October 29, 2026 19:54
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 29, 2026
@buluoray

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew Auto-Pipeline [operator: buluoray]:

Post-merge review follow-up: re-signing in to the same account now retires idle sessions and drops their conversations. Tracked in #25964.

bolichen97 pushed a commit that referenced this pull request Nov 8, 2026
…#32979)

The vault's sign-in marker moves on every saved sign-in, so a same-account re-sign-in also retires idle kiro-backed sessions once. The sign-in responses carry no per-account id that tells it apart from another account answered with the same profileArn (#24942, #25608). Records the trade so it is a stated choice.

Fixes #25964

Co-authored-by: sim <a@b.c>
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.

Same-provider account switch with the same profileArn reads as unchanged to the vault identity fingerprint

4 participants