Repository navigation
fix(kiro): read the whoami identity when kiro-cli appends its Profile block - #7455
Conversation
… block kiro-cli 2.32 prints a human-readable "Profile:" block on stdout after the `whoami --format json` object once an IAM Identity Center profile is selected. readKiroCliIdentity parsed the whole stream with JSON.parse, so the parse failed and the user email was silently dropped. Without that email, users of one organization profile collapse onto the same ARN identity (lidge-jun#6641): an import of a second user overwrote the first user's account, or, once that account had an email, was refused. Read only the leading top-level JSON object, which must end its line. Text on later lines is ignored; a second value on the same line still leaves the identity unread.
|
✅ READY
Review readiness checklist
✅ 4/4 boxes ticked. This pull request is already Ready for Review. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
Ingwannu
left a comment
There was a problem hiding this comment.
Manual authentication-boundary review at 33f6bafb235223b544df41414016fd0994d38f6f:
The new parser consumes only a leading JSON object, respects quoted/escaped delimiters, requires a line boundary, and leaves malformed/nonzero/throwing CLI output on the existing unread-identity path. It does not parse the human-readable profile ARN, mint identity from trailer text, change credential destinations, or alter account selection/persistence rules. Email normalization, narrow ARN validation and the existing same-session/session-switch fences remain in their original owner after parsing.
Independently ran bun test tests/providers/kiro/kiro-oauth.test.ts tests/providers/kiro/kiro-org-user-identity.test.ts on Linux/Bun 1.4.3 under fresh homes and hard resource limits: 82 passed, 0 failed. These include org-user isolation, add/import identity, invalid output and the new Profile trailer cases; no real Kiro login or account was touched. I am applying maintainer-sponsored on this reviewed scope. This records a completed manual boundary review, not a CI waiver, whole-branch approval, live acceptance or merge decision. Functional CI execution was separately approved and must actually finish.
Ingwannu
left a comment
There was a problem hiding this comment.
Approved exact head 33f6bafb235223b544df41414016fd0994d38f6f against current dev 12025981e5a3, following the explicit authentication-boundary review already recorded on this head. Independent capped/fresh-home OAuth and organization-identity suites passed 82 tests, 0 failures. Actual Cross-platform CI, Catalog contracts and React Doctor now completed successfully, and the author-owned readiness gate has moved this unchanged head out of Draft with no unresolved review threads or outstanding change request. The bounded leading JSON object is parsed with string/escape awareness; trailing human Profile output is not treated as identity authority, invalid/nonzero/throwing results retain the existing unread-identity path, and validation/account-selection/persistence/destination boundaries remain intact. No live Kiro account or Codex Security scan was used. This approval is not a merge/release.
Summary
Importing a second user of the same Kiro organization (IAM Identity Center) profile still loses one account when the users have a profile selected in kiro-cli. #6981 keys these rows by profile ARN plus the email from same-session
kiro-cli whoami --format json, but that email never arrives.Once an Identity Center profile is selected, kiro-cli 2.32.0 prints a human-readable profile block on stdout after the JSON object:
readKiroCliIdentitypasses all of stdout toJSON.parse, the parse throws, and the catch returns an empty identity. Every import of such a session therefore carries only the shared ARN:KiroUserIdentityUnavailableErrorOn a headless hub I hit the third row: the existing account had an email, so the import of the next organization user was refused. The first two rows are what happens when the existing account was itself imported through this output and so has no email; the new regression tests pin them and fail on the current code.
The fix reads only the leading top-level JSON object of the whoami output. The object has to start the output and end its line, so text on later lines is ignored. A second value on the same line still leaves the identity unread rather than picking one. Everything after parsing is unchanged: the narrow
email/profile ARN fields, the session-switch revalidation (#993), and the identity rules from #6641. The profile ARN printed in the text block is deliberately not read. The SQLite profile state already supplies it, and parsing human-readable output for an ARN would contradict the narrow-shape rule from #993.structure/providers-and-adapters.mdrecords the parsing contract in thesrc/oauth/row. This touches Kiro OAuth identity, which is an authentication surface, so it needs maintainer sponsorship per CONTRIBUTING.Verification
whoami --format jsonstdout has the shape above, andJSON.parseof it throws. The import of a second user of that profile is refused. With a temporary wrapper that kept only the first line of that output,ocx login kiroimported two more users of the profile as separate accounts, each with its email, andocx account refresh kiroreported quota for all three.bun test tests/providers/kiro/kiro-oauth.test.ts tests/providers/kiro/kiro-org-user-identity.test.ts: 82 pass, 0 fail. Withsrc/oauth/kiro.tsreverted, the three new trailer tests fail (79 pass, 3 fail). The new same-line test passes both ways because it pins a boundary the fix must keep.bun run typecheck: pass. After the docstring-only commit 33f6baf (it documentsreadKiroCliIdentity, the production function the docstring check flagged), the two Kiro test files were rerun (82 pass, 0 fail) andbun run typecheckpassed again.bun run structure:check: pass.bun run privacy:scan: pass.bun run test:changedwith Bun 1.4.3 (OCX_TEST_RUNNER_BUN): 33020 pass, 40 skip, 0 fail across 1466 files.bun run testwith Bun 1.4.3 on macOS arm64: 51134 pass, 152 skip, 2 fail. Both failures also occur onupstream/devwithout this change on the same machine.tests/claude-integration/claude-desktop-remote-hub.test.ts("connected Desktop uses hub IDs across a cold restart (stored profile=false)") fails on both.tests/clients/link-ssh-argv-discovery.test.ts("remote sh reports missing when all candidates are absent or fail --version") hits its 5 s timeout on both, and passes 12/12 when rerun on this branch.Checklist
Review readiness checklist
This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:
Required local validation passed; commands, results, and any full-suite exception are documented.
I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
I resolved all correct Codex and CodeRabbit findings.
My PR is ready for review.
Summary by CodeRabbit
Bug Fixes
Documentation
Tests