Skip to content

fix(auth): let KIRO_CPS_URL and KIRO_OIDC_SCOPE_PREFIX reach a gamma IdC profile - #36242

Closed
tim-finnigan wants to merge 1 commit into
mainfrom
fix/kiro-cps-url-env
Closed

tim-finnigan wants to merge 1 commit into
mainfrom
fix/kiro-cps-url-env

Conversation

@tim-finnigan

@tim-finnigan tim-finnigan commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

This is one of two alternative fixes for the same bug (#36190); only one should land. The other is #36188, which asks the relay viewer's tunnel.relay_viewer_cps_url first.

Problem / Motivation

Goal: An Identity Center user whose Kiro profile lives on a non-production control plane (gamma) can sign in by naming that control plane (KIRO_CPS_URL) and the OIDC scope prefix it lists profiles under (KIRO_OIDC_SCOPE_PREFIX). Gamma sign-in needs both: the host alone was asked and answered, but listed zero profiles for a token holding the public scopes.

Sign-in approves the device code, then reports "no Kiro profile". list_available_profiles only ever asks the production hosts in _CPS_ENDPOINTS, and control_plane_url() can only return one of them, so a profile only gamma lists is never found.

Why it matters

Anyone testing against a gamma account (Tim reproduced it today) cannot sign in at all.

Not a goal

  • Changing which OAuth scopes are requested when KIRO_OIDC_SCOPE_PREFIX is unset.
  • Any UI or config-file setting for the control plane or the scope prefix; these are environment variables only.
  • Changing which hosts are asked when KIRO_CPS_URL is unset.
  • Moving the LTS policy fetch: it stays on the built-in control planes whatever the environment says.

What changed (motivation → approach → change)

Symptom: "no Kiro profile" for a gamma IdC user. Root cause: the control-plane host is hard-coded to the production table. Change: KIRO_CPS_URL, read in src/kiro_crew/auth/login/control_plane.py the same way endpoints.py reads KIRO_AUTH_PORTAL_URL. No existing KIRO_* variable names a CPS, control-plane or management URL on main, so this adds a new one.

  • Set to an https:// URL: the sign-in profile listing (control_plane_urls(), so list_available_profiles()) asks only that host. control_plane_url() is not affected.
  • Unset or blank: unchanged, the production table as today.
  • Any other value (http, no host, or a value urlsplit cannot parse): ignored, with one warning per distinct value, since the bearer token is sent to it.
  • An LTS build ignores the variable altogether, also with a warning.

Callers: control_plane_url has one other caller, the LTS policy fetch at src/kiro_crew/platform/enterprise_policy_fetch.py:171. It deliberately does NOT follow KIRO_CPS_URL: a locally set host could otherwise answer the policy read and replace the administrator's policy ceiling (RFC rfc-crew-lts-edition, D2), so control_plane_url() always answers from the built-in table. _CPS_ENDPOINTS is read only inside control_plane.py. docs/system-specs/modules/kas-auth.md documents both variables.

Scope prefix (added at a reviewer's request, so both alternatives can sign a gamma user in): a gamma control plane lists profiles only for scopes under its own prefix, so a token holding the public codewhisperer: scopes gets zero profiles there. KIRO_OIDC_SCOPE_PREFIX mirrors kiro-cli's api.oidc.scopePrefix setting (the setting name is in the kiro-cli 3.3.0 binary): set, it replaces the codewhisperer prefix of every SSO-OIDC scope (Builder ID and Identity Center) at RegisterClient, via oidc_scopes() in src/kiro_crew/auth/login/endpoints.py.

  • Unset or blank: today's public scopes, for every sign-in.
  • Set: the value must be lowercase letters and underscores ([a-z_]{1,64}, so no colon or space can add or split a scope); anything else is ignored with one warning per distinct value. The check is a token pattern, not a list of accepted values.
  • Refresh: SSO-OIDC refresh sends only the client credentials, so the scopes stay the registration's. They are recorded in the token's extra["oidc_scopes"] (only when not the public ones, so a public-scope token is stored exactly as before), and refresh.py already carries extra forward. stored_client reuses a registration only for a sign-in asking the same scopes, so changing the prefix registers a new client. This is the same mechanism fix(auth): sign in to the relay viewer's control plane with its own profile and scopes #36188 uses, so the two options stay comparable; they differ only in what picks the scopes (this env var vs the relay viewer's CPS setting).
  • OIDC_SCOPES has no other reader: builder_id.register_client is the only place scopes are sent.

Rebase note: main's #35620 moved the host list into control_plane_urls(), which also names the hosts in the "no profile" message (src/kiro_crew/auth/service.py). The override now lives there, so that message names the override too.

Desktop app pass-through: the Electron gateway supervisor passes its own process environment to the gateway it spawns, minus KIROCREW_PORT (website/electron/gateway-supervisor.js:860, spread into the spawn env at :930-931, kept by buildGatewayEnvironment at website/electron/gateway-env.js:111-114). A macOS app opened from Finder or the Dock gets launchd's environment, not the shell's, so a tester has to start the app binary from a terminal:

KIRO_CPS_URL=https://<gamma-cps-host> KIRO_OIDC_SCOPE_PREFIX=<gamma-scope-prefix> "/Applications/KiroCrew Nightly.app/Contents/MacOS/KiroCrew Nightly"

If a gateway is already running on the port, the app adopts it and the variable never reaches it, so quit Kiro Crew fully first.

Backwards compatibility

Compatible: with KIRO_CPS_URL and KIRO_OIDC_SCOPE_PREFIX unset, the hosts asked, their order, the scopes registered and the stored token are exactly as on main. A stored registration with no recorded scopes reads as the public ones, so existing sign-ins keep reusing theirs.

Removes nothing: both variables only add a path; the production table, the fallback region and OIDC_SCOPES are untouched.

Tests

  • test_kiro_cps_url_names_the_only_listing_host_but_not_the_region_host: set, the listing asks only the override for any region, and control_plane_url() keeps the table.
  • test_kiro_cps_url_is_ignored_in_an_lts_build: an LTS build ignores the variable and warns.
  • test_kiro_cps_url_that_is_not_https_is_ignored_with_a_warning: http, host-less and unparseable (https://[::1) values are ignored and warned about.
  • test_kiro_cps_url_unset_still_asks_every_table_host: unset, the listing asks the production hosts as today.
  • test_kiro_cps_url_listing_asks_only_that_host: set, the listing asks the override and nothing else.
  • TestSuccess::test_kiro_cps_url_does_not_move_the_policy_read: with KIRO_CPS_URL set, the policy fetch still posts to the built-in host.
  • TestSuccess::test_the_policy_read_ignores_an_accepted_cps_override: even an override the listing accepts (LTS check bypassed) does not reach the policy host.
  • test_scope_prefix_unset_or_blank_keeps_the_public_scopes: unset or blank gives OIDC_SCOPES, and pins their literal values.
  • test_scope_prefix_replaces_the_public_prefix: a made-up prefix (acme_test) replaces codewhisperer on all three scopes.
  • test_scope_prefix_that_is_not_a_token_is_ignored_with_a_warning: colon, space, uppercase, digit, hyphen and over-length values are ignored and warned about.
  • test_a_sign_in_registers_for_the_configured_scopes (Builder ID and IdC, unset and set): unset reuses the stored public registration; set refuses it and registers the prefixed scopes.
  • test_the_registrations_scopes_ride_from_sign_in_through_refresh: scopes go out at registration only, are recorded on the stored token, survive refresh, and gate reuse.
  • test_a_public_scope_sign_in_is_stored_as_before: public scopes are sent and nothing is added to extra.

Proof: PROVEN test/test_enterprise_policy_fetch.py::TestSuccess::test_the_policy_read_ignores_an_accepted_cps_override, test/test_kas_login_service.py::test_kiro_cps_url_names_the_only_listing_host_but_not_the_region_host (head e5b4b75)

Checked by hand rather than with prove.py, which reverts to main and so cannot isolate this round: the two tests above fail with the previous head's control_plane.py (override inside control_plane_url). For the scope prefix: with endpoints.py, builder_id.py and service.py taken from main and the tests kept, 13 of the 14 scope tests fail; the one that passes is test_a_public_scope_sign_in_is_stored_as_before, which pins unchanged behaviour.

Local gates, kept to auth/login and policy-fetch tests (#36188 has priority on local runs): the six auth/login and policy-fetch test files pass (360 tests). mypy is clean on the four touched modules, black and flake8 on touched files, and scripts/docs-lint.sh passes. I did not run the full backend suite or mypy across all of src; CI owns those.

Manual verification

Not yet run against gamma with this PR. A patched nightly copy for Tim to test it on was built before the scope prefix was added, so it carries KIRO_CPS_URL only and has not been rebuilt.

Related Issues

Closes #36190. Alternative: #36188.

Sibling sweep

Swept: git grep -nE "control_plane_url|_CPS_ENDPOINTS|management\.[a-z0-9-]+\.kiro\.dev" -- src
Swept: git grep -nE "OIDC_SCOPES|register_client|stored_client" -- src
Sibling: src/kiro_crew/auth/service.py -- changed here (the only register_client and stored_client caller now passes the configured scopes)
Sibling: src/kiro_crew/platform/enterprise_policy_fetch.py:171 -- not affected -- policy fetch stays on the built-in table by design; two tests pin it

Pattern harvest

Not generalizable: the auth portal already has its env override; the control-plane host and the scope prefix were the two non-production settings kiro-cli has that Kiro Crew lacked.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • 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

Contributions are accepted under the project's Apache-2.0 license.

@tim-finnigan tim-finnigan self-assigned this Nov 13, 2026
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] e5b4b75

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

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision e5b4b75bccfde68e2b68859e5348e11513beeaa3 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 added the readiness: action required A blocking check or review needs attention label Nov 13, 2026
@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
@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 Nov 13, 2026
@tim-finnigan tim-finnigan changed the title fix(auth): let KIRO_CPS_URL name the control plane for IdC profile lookup fix(auth): let KIRO_CPS_URL and KIRO_OIDC_SCOPE_PREFIX reach a gamma IdC profile Nov 13, 2026
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: both variables add an opt-in path, the unset path is the same as main, and the policy host stays on the built-in table.

Notes

[DESIGN-REVIEWED] e5b4b75

Description read

[DESCRIPTION-READ] f96cbe07293d6c70370df851c522e3dae5914c1e8cb889f567e519b4b5fb1053

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 13, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of e5b4b75bccfde68e2b68859e5348e11513beeaa3 — 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

Both variables are off by default and come from the frozen Goal; nothing blocks. Item 1 is a second way to name a control-plane URL. The open #36188 already offers the other way.

Not checked: the claim that the kiro-cli 3.3.0 binary has an api.oidc.scopePrefix setting, and that gamma lists profiles only under its own prefix.

Notes

  • Item 1 — duplicate of tunnel.relay_viewer_cps_url (src/kiro_crew/config/integration_sections.py:1181, 4 src readers): the description says "No existing KIRO_* variable names a CPS, control-plane or management URL on main". That holds only because it counts env vars; a config key that names a control plane host already exists. Subtraction: delete CPS_URL_ENV and cps_url_override's env read, and have the listing read the existing key. That is fix(auth): sign in to the relay viewer's control plane with its own profile and scopes #36188, so land only one of the two.

What this change ships

Inventory (7 items) — 6 justified

Intent: a gamma Identity Center user can sign in by naming their control plane and its OIDC scope prefix. FIX (#36190).

  1. KIRO_CPS_URL makes the sign-in profile listing ask only that one host — duplicate of tunnel.relay_viewer_cps_url
  2. KIRO_OIDC_SCOPE_PREFIX replaces codewhisperer in every scope sent at registration — justified
  3. Non-public scopes are recorded in the stored token's extra, and a stored registration is reused only when its scopes match — justified
  4. Invalid values of either variable are ignored, with one warning per distinct value — justified
  5. An LTS build ignores KIRO_CPS_URL and warns — justified
  6. The "no profile" error names the override host — justified
  7. The LTS policy fetch stays on the built-in hosts whatever the environment says — justified

[FIRST-PRINCIPLES-REVIEWED] e5b4b75

Description read

[DESCRIPTION-READ] 4ef24414045456878c78bae85289a1a50bbb946ec42f7354f0beb7f6172fe5df

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 13, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] e5b4b75

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

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

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Nov 13, 2026
@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 Nov 13, 2026
…IdC profile

Sign-in only ever asked the production control planes, so an Identity
Center account whose profile lives on a gamma control plane found no
profile. KIRO_CPS_URL, when it is an https URL, replaces the host table
for the sign-in profile listing only: the listing asks only that host.
control_plane_url(), which the LTS policy fetch uses, never reads it, so
the environment cannot choose where the organisation's policy comes from.
Any other value, including one that does not parse, is ignored with a
warning, and an LTS build ignores the variable altogether.

That control plane also lists profiles only for scopes under its own prefix.
KIRO_OIDC_SCOPE_PREFIX, like kiro-cli's api.oidc.scopePrefix, replaces the
public prefix of every SSO-OIDC scope at registration. The scopes are recorded
on the token, carried through refresh, and a stored registration is reused
only for the same scopes. A value that is not lowercase letters and
underscores is ignored with a warning.

Unset, both behave exactly as before.

Closes #36190
@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
@tim-finnigan

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #36188, which merged at 06:17 UTC and fixes the same bug (#36190) through the relay viewer's control plane and scopes. This was the env-var alternative; only one of the two was meant to land.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IdC sign-in finds no Kiro profile for an account on a non-production control plane

1 participant