Skip to content

fix(auth): resolve Kiro profiles by control-plane discovery, not region map - #29049

Closed
Skripd wants to merge 5 commits into
kirodotdev:mainfrom
Skripd:fix/auth-cps-profile-discovery
Closed

Skripd wants to merge 5 commits into
kirodotdev:mainfrom
Skripd:fix/auth-cps-profile-discovery

Conversation

@Skripd

@Skripd Skripd commented Nov 3, 2026

Copy link
Copy Markdown

Problem / Motivation

Goal: An IAM Identity Center user signs in from the dashboard and reaches their Kiro profile wherever it is served, instead of a silent "no available Kiro profiles" failure.

The dashboard Kiro sign-in (Settings -> Agent Harness) depends on the login region to decide which Kiro control plane (CPS) serves the user's profile. That mapping is wrong: the IAM Identity Center region a user signs in with is independent of which control plane holds their profile. An eu-west-1 IdC login whose profile is served from Frankfurt resolves against the wrong host, ListAvailableProfiles returns zero, and sign-in stalls with "no available Kiro profiles" even though the browser authorization succeeded.

Why it matters

Any IAM Identity Center user whose profile region does not match the one their login region maps to is blocked from Crew-owned auth, with a silent failure that looks like a successful sign-in (the vault is simply never written). The previously merged one-line map (eu-west-1 -> eu-central-1, #26203) fixes eu-west-1-IdC / EU-profile users but regresses eu-west-1-IdC / us-east-1-profile users onto the Frankfurt control plane, where their profile is invisible - the same wall, moved to a different population. Some Kiro capabilities are us-east-1-only, so that combination is real and common.

Not a goal

  • Multi-profile selection UX (a picker when discovery returns more than one). This PR keeps the existing "first profile wins" behavior and only changes how the profile set is discovered.
  • Parallel probing of control planes - discovery here is sequential (region's own host first), which is strictly fewer calls in the common single-region case.
  • Any change to the post-sign-in policy-fetch path, which is correctly keyed by the resolved profile ARN's own region.

What changed (motivation -> approach -> change)

  • Symptom: an eu-west-1 IdC sign-in with an EU-served profile logs "no available Kiro profiles" and writes no vault, despite a successful browser authorization.
  • Root cause: at sign-in the profile's control plane is unknown (the profile ARN that names it is exactly what the call resolves), and the login region does not reliably identify it. list_available_profiles was keyed on the login region via _CPS_ENDPOINTS, so it probed only one host. The merged eu-west-1 -> eu-central-1 row swaps which single host is wrong for whom; it does not remove the region-as-key assumption.
  • Change: resolve profiles by DISCOVERY, mirroring the Kiro web sign-in (which polls the control planes rather than mapping a region to one). list_available_profiles now probes every known CPS host - the login region's own first as a latency hint - and returns the first non-empty result. A host that errors while another answers is logged and does not fail the resolution; a ControlPlaneError is raised only when every host errored and none returned a profile. An authenticated identity with no profile on any reachable host still returns [], which the caller surfaces as "no available Kiro profiles" exactly as before. The brittle eu-west-1 region row is removed, since discovery no longer needs a region->host guess. control_plane_url is retained for the post-sign-in enterprise_policy_fetch path, which keys off the resolved ARN's own region and is authoritative.

Backwards compatibility

Compatible: no input is rejected, renamed, or removed from any wire contract. list_available_profiles keeps its signature (access_token, region=, session=); region is now a probe-ordering hint rather than a hard host selector. control_plane_url and profile_region are unchanged.

Removes nothing externally; one internal behavior is intentionally changed: when every reachable control plane returns zero profiles, resolution now returns [] (surfaced as "no available Kiro profiles") rather than depending on which single host was mapped. Readers of the changed symbol:

  • Reader: src/kiro_crew/auth/service.py:_poll_oidc -- entry: chat/dashboard sign-in poll -- unchanged: it already treats [] -> {"status": "error"} and a raised ControlPlaneError -> {"status": "error"}; both still hold. Locked by test_poll_idc_with_no_profiles_is_error_and_saves_nothing and test_poll_idc_control_plane_failure_is_error (updated to script one reply per probed host).
  • Reader: src/kiro_crew/platform/enterprise_policy_fetch.py:161 -- entry: post-sign-in enterprise policy fetch -- not affected: it calls control_plane_url(profile_region(arn)), keyed by the resolved ARN's own region, which this PR does not change.

Tests

  • test_poll_idc_discovers_profile_on_second_control_plane (new): an eu-west-1 IdC login whose profile lives on the EU control plane - us-east-1 probed first (empty), then eu-central-1 returns the profile; asserts both hosts were probed in order and the EU profile ARN is stored. This is the case the region->host map got wrong.
  • test_discovery_hosts_probe_every_control_plane_region_first (new): _discovery_hosts returns every known CPS host exactly once, the region's own first, including for a region (eu-west-1) and an unknown region that have no dedicated host.
  • test_poll_idc_with_no_profiles_is_error_and_saves_nothing, test_poll_idc_control_plane_failure_is_error (updated): one reply per probed host, since discovery now probes all of them.
  • test_control_plane_url_is_the_regional_cps_host (updated): drops the eu-west-1 -> Frankfurt assertion (the behavior being removed) and reframes the function as the post-sign-in, ARN-region-keyed path.

Proof: PROVEN test/test_kas_login_service.py::test_poll_idc_discovers_profile_on_second_control_plane (head 1071595)

Manual verification

Verified end to end against a live IAM Identity Center instance in eu-west-1 whose Kiro profile is served from the us-east-1 control plane - the exact combination the merged eu-west-1 -> eu-central-1 map (#26203) would route to the wrong control plane. With this change the dashboard Kiro sign-in discovers the profile (us-east-1 probed first, answers), completes, and writes the vault; before it, the same login stalled with "no available Kiro profiles". The mirror case (eu-west-1 IdC with an EU-served profile) is covered by test_poll_idc_discovers_profile_on_second_control_plane.

Screenshots / video

N/A - no user-visible frontend surface changes. The fix is in the auth backend; the sign-in card is unchanged by this PR.

Related Issues

Part of #26201 also related #28904

Sibling sweep

Swept: git grep -nE "list_available_profiles|control_plane_url|_CPS_ENDPOINTS" -- 'src/**/*.py'

  • Sibling: src/kiro_crew/auth/service.py:612 -- not affected -- the one login-time caller; the defect lived entirely inside list_available_profiles, which this PR fixes, so the call site needs no change
  • Sibling: src/kiro_crew/platform/enterprise_policy_fetch.py:161 -- not affected -- keyed by profile_region(arn) (the resolved ARN's own region), which authoritatively names the control plane, so no region guess is involved

Pattern harvest

Rule candidate: review-prompt
Pattern: keying a service host off an incidental region value (the login/IdC region) instead of the value that authoritatively names the resource (the profile ARN's own region), so one host is probed where the correct one is unknown.

@Skripd
Skripd requested review from a team and KiroCrewCaptain as code owners November 3, 2026 09:43
@Skripd
Skripd requested a review from mbriones98 November 3, 2026 09:43
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Nov 3, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

[operator: bolichen97] Continuing this in #32445; thanks for the start.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 7, 2026
Resolves conflicts with main's control-plane discovery (kirodotdev#32445), sign-in error codes (kirodotdev#33590) and paginated profile listing (kirodotdev#29398). Keeps main's paginated per-host listing and its refusal rule, routes the host walk through _discovery_hosts, and keeps the eu-west-1 -> eu-central-1 entry.
@kyleseaman

Copy link
Copy Markdown
Contributor

Merged main into this branch (merge commit 7603235, no rebase or force-push) to resolve the conflicts with main's newer sign-in work in the same files.

How the conflicts were resolved:

@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 12, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider raised 2 possible problems and estimates a 55% chance that this change introduces a defect; a person should check them.

The code only moves the existing every-host profile probing (already on main) into a _discovery_hosts helper and adds tests, so behaviour is unchanged. The description says the eu-west-1 -> eu-central-1 row is removed and that eu-west-1 logins probe us-east-1 first, and it claims to fix a sign-in failure; the code does none of this. The row is still there and EU is probed first. The author should either make the described change with tests, or restate the PR as a refactor plus tests.

Things to check (possible problems the decider raised; at this confidence many turn out to be fine):

  • The PR's primary stated change is not in the code. Its manual-verification and test claims ('us-east-1 probed first' for an eu-west-1 login) describe behaviour the code doesn't have: _discovery_hosts('eu-west-1') returns [eu-central-1, us-east-1], and the new test asserts EU first. Either drop the r (src/kiro_crew/auth/login/control_plane.py, medium)
  • The PR says it fixes a 'no available Kiro profiles' failure, but its code change is a pure refactor that changes no behaviour. The bug it describes is already fixed on main, so the 'before it, the same login stalled' verification can't apply to this diff. The 'PROVEN' line also cites a different hea (src/kiro_crew/auth/login/control_plane.py, low)

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 760323570d · 143 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 13, 2026
Resolves the conflict with main's control_plane_urls (kirodotdev#35620), which does what this branch's _discovery_hosts did: the host walk and its test now use main's public helper.
@kyleseaman

Copy link
Copy Markdown
Contributor

Merged main in again (merge commit 6b80908, fast-forward, no rewrite). #35620 had just landed a public control_plane_urls helper that does exactly what this branch's _discovery_hosts did, so the branch now uses main's helper and the duplicate is gone. The discovery test calls control_plane_urls too. Nothing else changed.

@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 13, 2026
Kyle Seaman added 2 commits November 13, 2026 06:23
Resolves the docstring conflict with main's relay viewer control plane (kirodotdev#36188) by taking main's docstring.
@kyleseaman

Copy link
Copy Markdown
Contributor

Merged main in again (head a36b021, fast-forward, no rewrite). #36188 (relay viewer control plane) changed the list_available_profiles docstring, and only that docstring conflicted. I took main's version. The code merged cleanly: sign-in asks the relay viewer's host first when it is set, then walks control_plane_urls. This branch's own change is the same as before.

@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 13, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

Closing as part of the stale-PR cleanup. The sign-in fix this PR describes is already on main: #32445 (merge commit 90d19e3) made sign-in ask every Kiro control plane, the login region's first, and #35620 added the public control_plane_urls helper the branch now reuses. A maintainer noted earlier that this work continued in #32445. What is left in this diff is docstring wording plus tests whose cases (profile on another region's control plane, pagination past an empty first page, timeouts) are already covered on main in test/test_kas_login_service.py. Thank you @Skripd for the original report and fix. If you see a case main still misses, please reopen with a failing test.

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants