Skip to content

fix(kiro): preserve IDC region across ARN discovery - #2314

Open
lukmanc405 wants to merge 1 commit into
decolua:masterfrom
lukmanc405:fix/kiro-regional-profile-topology
Open

lukmanc405 wants to merge 1 commit into
decolua:masterfrom
lukmanc405:fix/kiro-regional-profile-topology

Conversation

@lukmanc405

Copy link
Copy Markdown

Summary

Fix Kiro IDC profile ARN discovery and auto-import for accounts issued outside us-east-1.

This patch preserves regional topology end-to-end:

  • fetchKiroProfileArn(accessToken, region) now validates the caller region, hits https://codewhisperer.<region>.amazonaws.com, and uses AWS JSON RPC dispatch (x-amz-target: AmazonCodeWhispererService.ListAvailableProfiles, Content-Type: application/x-amz-json-1.0).
  • OAuth token exchange now forwards the resolved Kiro region into fetchKiroProfileArn() instead of defaulting all profile discovery to us-east-1.
  • Kiro IDE auto-import now preserves the profile ARN exactly as issued by Kiro IDE instead of rewriting the ARN region to us-east-1.
  • Regression tests cover regional endpoint selection, AWS dispatch headers, region-preferring profile selection, invalid region fallback, error-safe behavior, and auto-import ARN preservation for both IDC and Builder ID profiles.

Why

IDC users in regions like eu-west-1 / ap-southeast-1 can receive regional CodeWhisperer profile ARNs. Rewriting or discovering those profiles through us-east-1 silently causes downstream CodeWhisperer calls such as ListAvailableProfiles, GetUsageLimits, and generateAssistantResponse to 403 for non-US IDC accounts.

Testing

NODE_PATH=/tmp/node_modules /tmp/node_modules/.bin/vitest run --reporter=verbose --config ./tests/vitest.kiro-verify.config.js tests/unit/kiro-profile-arn.test.js tests/unit/kiro-profile-arn-regional.test.js tests/unit/kiro-auto-import-arn.test.js

Test Files  3 passed (3)
Tests       13 passed (13)

Also ran syntax checks:

node -c src/lib/oauth/providerHelpers.js
node -c src/app/api/oauth/kiro/auto-import/route.js
node -c src/lib/oauth/providers.js
node -c tests/unit/kiro-profile-arn-regional.test.js
node -c tests/unit/kiro-auto-import-arn.test.js

Note: local Vitest needed a temporary non-committed config to bypass root PostCSS discovery in this environment because @tailwindcss/postcss was not installed in the hoisted /tmp/node_modules test setup. The committed source and tests are independent of that temp config.

Kiro IDC connections issued outside us-east-1 (eu-west-1, ap-southeast-1,
etc.) were silently pinned to us-east-1 in two places, which caused
downstream CodeWhisperer calls (generateAssistantResponse,
GetUsageLimits, ListAvailableProfiles) to 403 for any non-US IDC user:

1. fetchKiroProfileArn() hard-coded
   https://codewhisperer.us-east-1.amazonaws.com/ListAvailableProfiles
   with Content-Type: application/json. It now accepts the token's
   region, validates it via assertValidAwsRegion() (SSRF-safe), hits
   the matching regional CodeWhisperer endpoint, and dispatches via
   x-amz-target: AmazonCodeWhispererService.ListAvailableProfiles with
   Content-Type: application/x-amz-json-1.0. When the response returns
   multiple profiles, it now prefers the one whose ARN region matches
   the caller region instead of blindly taking the first entry.

2. src/lib/oauth/providers.js now forwards the region resolved during
   token exchange to fetchKiroProfileArn() so IDC accounts hit their
   own regional endpoint rather than us-east-1.

3. src/app/api/oauth/kiro/auto-import/route.js previously rewrote the
   ARN's region segment to us-east-1 on the assumption that the runtime
   gateway required it. That assumption held only for Builder ID and
   social accounts; IDC ARNs must keep the region issued by Kiro IDE.
   The route now preserves the ARN unchanged.

Regression tests:
- tests/unit/kiro-profile-arn-regional.test.js pins the regional
  endpoint, dispatch shape, region-preferring profile selection,
  invalid/missing region fallback, and error-safe behavior.
- tests/unit/kiro-auto-import-arn.test.js pins ARN preservation for
  both IDC (non-us-east-1) and Builder ID (us-east-1) accounts.

Test run: 13/13 pass (kiro-profile-arn + regional + auto-import).
bloodf pushed a commit to bloodf/9router that referenced this pull request Jul 3, 2026
# Conflicts:
#	src/app/api/oauth/kiro/auto-import/route.js
#	src/lib/oauth/providerHelpers.js
#	src/lib/oauth/providers.js
diegosouzapw added a commit to cheaper-inference/OmniRoute that referenced this pull request Jul 5, 2026
The auto-import fallback route (tryAwsSsoCache) unconditionally
rewrote the Kiro-IDE profile.json ARN's region segment to us-east-1,
403ing non-us-east-1 Identity Center (IDC) accounts. The OAuth
device-code path (src/lib/oauth/providers/kiro.ts) already discovers
the correct region-matched ARN, so forcing us-east-1 only in this
fallback was inconsistent. Removes the forced rewrite and preserves
the profile's ARN region verbatim, mirroring the already-correct
OAuth path.

This reverses the forced normalization pinned by the #2059 regression
test (tests/unit/kiro-auto-import-idc-2059.test.ts) — that test is
updated to assert preservation instead, with added coverage for the
us-east-1 no-op case and the missing-profile.json case.

Co-authored-by: lukmanc405 <lukmanc405@users.noreply.github.com>
Inspired-by: decolua/9router#2314
philau2512 added a commit to philau2512/9router-better that referenced this pull request Jul 7, 2026
…2298 orphaned tool results, PR#2355+decolua#2314 IDC cross-region ARN

  discovery
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