Skip to content

fix(kas-auth): send sign-in and renewal through the proxy - #36978

Merged
buluoray merged 1 commit into
mainfrom
crew/slack/kas-auth-through-proxy
Nov 14, 2026
Merged

buluoray merged 1 commit into
mainfrom
crew/slack/kas-auth-through-proxy

Conversation

@buluoray

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: On a network that reaches Kiro only through an HTTP(S) proxy, Kiro Crew's sign-in and token renewal go through that proxy, and a proxy's own refusal says the proxy blocked it instead of "Not signed in to Kiro".

Two gaps on main, tracked in #36954:

  1. Kiro Crew's requests to the Kiro sign-in service (device authorization, polls, code exchange, profile lookup, every token refresh) passed no proxy=, and their sessions keep trust_env off on purpose. So HTTPS_PROXY / HTTP_PROXY / NO_PROXY were never read, while kiro-cli follows them. A renewal that could not reach the issuer reached the engine as a failed refresh, and the chat said "Not signed in to Kiro".
  2. An engine line where a proxy refused the request (a proxy 407, "403 from proxy after CONNECT", a tunnel error) matched the sign-in failure wording, set the signed-out latch and showed the sign-in row.

Why it matters

Not a goal

What changed (motivation → approach → change)

Part Change
Sign-in and renewal (kiro_crew/auth/) Every request to the sign-in service passes proxy=resolve_proxy(url) from the existing http_proxy.py, which reads HTTPS_PROXY / HTTP_PROXY and honours NO_PROXY
Renewal timeout (auth/refresh.py, auth/provider.py, auth/service.py) The login service's 30 s / 10 s timeout moves to refresh.HTTP_TIMEOUT; the temporary renewal session uses it instead of aiohttp's five-minute default
Proxy refusals (acp/proxy_refusal.py, acp/transport_errors.py) A line that names the proxy, its tunnel or CONNECT and carries a refusal (401/403/407, "authentication required", tunnel error, "could not be established", !== 200) is dropped before the sign-in check, classified as a connection error, and shown as "A network proxy blocked the request to the model backend…"
Spec (kas-auth.md) A "Proxy" subsection under Refresh

The proxy helpers live in a new acp/proxy_refusal.py, re-exported by transport_errors.py, which keeps that file under the 2,000-line cap.

This builds on the approach of #31966 by okajun35 (the same resolve_proxy routing for sign-in and refresh), which has had a merge conflict with main since 2026-11-10. It is rewritten fresh on current main, with the proxy-refusal half added.

builder-security checked: the change only alters the route of outbound HTTPS requests. It adds no listener and weakens no auth. The proxy comes from the operator's own environment, and the sign-in URLs are https://, so the proxy carries a CONNECT tunnel and cannot read the tokens.

Backwards compatibility

Compatible: with no proxy variables set, resolve_proxy returns None and every request is sent exactly as before; only engine lines that name a proxy change class.

Removes nothing: no key, route or function is removed; the timeout constant moves from service.py to refresh.py, and both readers import it from there.

Tests

Proof: PROVEN test/test_acp_auth_failure_on_stderr.py::test_a_proxy_refusal_is_a_network_error_not_a_sign_in_failure[HTTP status client error (407 Proxy Authentication Required) for url (https://q.example/)], test/test_acp_auth_failure_on_stderr.py::test_a_proxy_refusal_is_a_network_error_not_a_sign_in_failure[Received HTTP code 403 from proxy after CONNECT], test/test_acp_auth_failure_on_stderr.py::test_a_proxy_refusal_is_a_network_error_not_a_sign_in_failure[proxy returned HTTP 403 Forbidden], test/test_acp_auth_failure_on_stderr.py::test_a_proxy_refusal_does_not_set_the_signed_out_latch, test/test_acp_auth_failure_on_stderr.py::test_a_proxy_refusal_frame_names_the_proxy_not_the_sign_in (head 75e6dc5)

  • test/test_kas_auth_proxy.py: 12 request sites × 2 cases. With HTTPS_PROXY set each request carries that proxy; with its host in NO_PROXY it carries proxy=None. Also the login service's poll uses the proxy, and the renewal session has a timeout of at most 30 s with trust_env off.
  • test/test_acp_auth_failure_on_stderr.py: three proxy lines are not auth failures and classify as connection; the signed-out latch stays off when it reads them; a Kiro 403, a named AccessDeniedException and a real sign-in line beside a proxy line still read as signed out; the error frame names the proxy and not the sign-in.
  • Seven existing fake sessions accept proxy=None.
  • Determinism: the 11 touched or related files pass 3 runs in a row (399 passed each), and the two new-test files pass in a seeded shuffled order (41 passed). test_flake_pattern_ratchet.py and test_wait_discipline_ratchet.py pass with -n0.

Manual verification

N/A — no end-to-end run through a real proxy; request routing is pinned with fake sessions, and the engine wording comes from the HTTP stacks' own strings (reqwest/hyper's in the kiro-cli binary, curl's, undici's), since no captured engine log from a proxy refusal exists.

Related Issues

Closes #36954
Part of #32425

Sibling sweep

Swept: git grep -nE "session.(post|get)(" -- src/kiro_crew/auth/
Sibling: src/kiro_crew/auth/login/builder_id.py -- changed here
Sibling: src/kiro_crew/auth/login/device.py -- changed here
Sibling: src/kiro_crew/auth/login/portal.py -- changed here
Sibling: src/kiro_crew/auth/login/external_idp.py -- changed here
Sibling: src/kiro_crew/auth/login/control_plane.py -- changed here
Sibling: src/kiro_crew/auth/refresh.py -- changed here
Sibling: src/kiro_crew/auth/service.py -- changed here
Sibling: src/kiro_crew/dashboard/sign_in_refresher.py -- not affected -- its requests go through refresh.ensure_fresh, covered here

Pattern harvest

Rule candidate: semgrep
Pattern: an outbound aiohttp request on a session with trust_env off that passes no proxy=, which silently ignores the proxy environment

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

@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners November 14, 2026 01:04
@buluoray
buluoray requested a review from iamwhatever November 14, 2026 01:04
@buluoray
buluoray enabled auto-merge (squash) November 14, 2026 01:04
@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision ab712384989a0f7dfc1ab6a100694640b04353bc 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 Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: sign-in and renewal now reuse the existing resolve_proxy seam, the moved timeout has no readers outside the patch, and the proxy-refusal check only applies to lines that name a proxy.

Notes

  • Anyone whose proxy variables point at a proxy aiohttp cannot use (for example socks5://), but who reaches Kiro directly today, will start failing sign-in and renewal. Mention this risk in the PR's compatibility section.
  • _names_proxy treats any line containing the word "tunnel" plus 401 or 403 as a proxy refusal. A Kiro 403 that shares a line with tunnel-related engine text would then lose its signed-out verdict. Consider requiring the refusal and the proxy word to sit close together.

[DESIGN-REVIEWED] ab71238

Description read

[DESCRIPTION-READ] 011e53033e1eabc01f5e62a94ad1fe53343cec894fe9cc42df37e1f38f3a27c9

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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

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

One stray re-export is the only surplus. It is small and private, so it does not block.

Notes

  • Item 6 — zero consumers: transport_errors.py re-exports _proxy_refusal_line, but nothing reads it through that module (grepped _proxy_refusal_line: its only caller is inside proxy_refusal.py). Subtraction: delete _proxy_refusal_line from the from kiro_crew.acp.proxy_refusal import (...) list in transport_errors.py.

What this change ships

Inventory (6 items) — 5 justified

Intent: on a network that reaches Kiro only through a proxy, sign-in and token renewal work, and a proxy's refusal is reported as a proxy problem. This is a FIX.

  1. Sign-in requests (device, portal, external IdP, SSO-OIDC, profile lookup) now go through the HTTPS_PROXY/NO_PROXY proxy using the existing http_proxy.resolve_proxy — justified
  2. All three token-refresh paths go through the proxy — justified
  3. An engine line where a proxy refuses the request no longer sets the signed-out latch or shows the sign-in row — justified
  4. The chat shows "A network proxy blocked the request…" and the error is classified as a retryable connection error — justified
  5. The temporary renewal session is capped at 30 s instead of aiohttp's 5-minute default — justified
  6. New public helpers in acp/proxy_refusal.py, re-exported through transport_errors — zero consumers for the _proxy_refusal_line re-export

[FIRST-PRINCIPLES-REVIEWED] ab71238

Description read

[DESCRIPTION-READ] de2dbb0c8d4f54e13d1f077bfea106956e239cfe9a7e2e668e45e85aa7a34535

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] ab71238

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

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

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] ab71238

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

@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: action required A blocking check or review needs attention labels Nov 14, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks. I read the whole diff on this head, and all checks are green. Most of it is good to keep:

  • Every sign-in and renewal request now passes proxy=resolve_proxy(url), the shared helper on main (http_proxy.resolve_proxy). With no proxy configured it returns None, which is aiohttp's own default, so a host without a proxy sends exactly what main sends. NO_PROXY hosts go direct, trust_env stays off (no ~/.netrc), and the tests cover each of the twelve request sites both ways.
  • Nothing new is logged. No log line is added, the refresh token and codes still travel only in the request bodies, and the existing log lines are untouched.
  • The temporary session KasAuthProvider opens now uses the same 30s / 10s HTTP_TIMEOUT the login service's shared session already used on main, moved to refresh.py so both read one constant.
  • A proxy's own refusal now reads as a network error, not a sign-out. A bare status code 403 and a named service exception keep their sign-in verdict, and the tests check both.

I am requesting changes on one point: new regex in product code. The new acp/proxy_refusal.py adds _RE_PROXY_NAMED and _RE_PROXY_REFUSED (re.compile), used by _proxy_refusal_line and so by _is_session_expired, classify_provider_error and the chat wording. Product code takes no new regex. The same per-line test works with plain string checks on line.lower():

  • the proxy is named: the line holds the word proxy, tunnel or tunneling, or CONNECT (case-sensitive), checked as whole words by splitting on non-letters;
  • and it refuses: the line holds 401, 403 or 407 as a whole token, or one of the phrases authentication required, authorization required, tunnel error, tunnel failed, tunneling failed, could not be established, or !== 200.

The behaviour, tests and chat text can stay as they are. I will approve once proxy_refusal.py has no re import.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: passed Eligible automated validation passed for the current revision labels Nov 14, 2026
@buluoray
buluoray force-pushed the crew/slack/kas-auth-through-proxy branch from 75e6dc5 to a2abab2 Compare November 14, 2026 05:28
@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 14, 2026
@buluoray

Copy link
Copy Markdown
Contributor Author

Thanks @bolichen97. Done in a2abab2: acp/proxy_refusal.py has no re import and no regex.

  • Proxy named: the line, split on non-letters, holds CONNECT (case-sensitive), or its lowercased form holds the word proxy, tunnel or tunneling.
  • Refuses: the line, split on non-alphanumerics, holds 401, 403 or 407 as a whole token, or line.lower() contains one of authentication required, authorization required, tunnel error, tunnel failed, tunneling failed, could not be established, !== 200.

Behaviour, tests and chat text are unchanged. The 18 test files that cover the classifier, the auth flows and the proxy paths pass 1056/1056 on 3 runs and on 1 shuffled run, and black, flake8 and mypy --platform linux are clean.

@buluoray
buluoray requested a review from bolichen97 November 14, 2026 05:29
@KiroCrewCaptain

KiroCrewCaptain commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider estimates a 12% chance that this change introduces a defect, within the 12% limit for approving on its own, but it changes 483 lines, more than the 400 it may approve on its own.

I'd approve this head as it stands; I found nothing that blocks it.

Sign-in and renewal through the proxy. I listed every outbound request under src/kiro_crew/auth/: there are 12 call sites. All of them now pass proxy=resolve_proxy(url). The sessions keep trust_env off, so ~/.netrc is still never read. Every token refresh goes through refresh._refresh_*, so all of these callers are covered:

  • the gateway refresher tick (sign_in_refresher.py)
  • the KasAuthProvider callers
  • the login service

Timeout move. HTTP_TIMEOUT moved from service.py to refresh.py. Its only readers are service.py and provider.py, it introduces no import cycle, and the renewal session now has a 30-second cap instead of aiohttp's five-minute default.

Proxy refusals. The new check applies per line, only to lines that name the proxy, a tunnel or CONNECT. It is used consistently in four places:

  • the signed-out check (_is_session_expired)
  • the retry decision (_is_transient_raw_error)
  • the error classifier (classify_provider_error)
  • the chat message formatter

Named service exceptions such as AccessDeniedException, and a real sign-in line next to a proxy line, stil

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

Kiro Crew's own requests to the sign-in service ignored HTTPS_PROXY,
HTTP_PROXY and NO_PROXY, so on a proxy-only network a renewal failed and
the chat said 'Not signed in to Kiro'. Every sign-in and refresh request
now passes resolve_proxy(url), with trust_env still off (no netrc), and
the temporary renewal session is bounded to 30 s.

An engine line that names the proxy, its tunnel or CONNECT and carries a
refusal is now a connection error with a proxy message, not a sign-in
failure. A bare 403 keeps its signed-out verdict.

Closes #36954
@buluoray
buluoray force-pushed the crew/slack/kas-auth-through-proxy branch from a2abab2 to ab71238 Compare November 14, 2026 06:21
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 14, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed at ab71238. The change I asked for is in place, so I'm approving.

  • acp/proxy_refusal.py no longer has _RE_PROXY_NAMED or _RE_PROXY_REFUSED, and the change has no import re, re.compile or other re. call. _names_proxy splits the line into letter runs and checks for CONNECT (case-sensitive) or proxy / tunnel / tunneling as whole words. _refuses checks for 401 / 403 / 407 as whole alphanumeric tokens, or one of the fixed phrases on line.lower(). That's the same per-line test as before.
  • Compared with 75e6dc5, which I reviewed in full, this is the only change. Every sign-in and renewal request still passes proxy=resolve_proxy(url), with trust_env off and the shared HTTP_TIMEOUT. A bare status code 403 keeps its sign-in verdict, and only a line that names the proxy reads as a network error.
  • It adds no refusal. A proxy refusal now goes to the connection class and the bounded retry, where main read it as a terminal sign-out.

All checks are green. Approving. Auto-merge is left as you set it.

@buluoray
buluoray merged commit c8f45fb into main Nov 14, 2026
99 checks passed
@buluoray
buluoray deleted the crew/slack/kas-auth-through-proxy branch November 14, 2026 08:06
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 14, 2026
buluoray added a commit that referenced this pull request Nov 14, 2026
Kiro Crew's own requests to the sign-in service ignored HTTPS_PROXY,
HTTP_PROXY and NO_PROXY, so on a proxy-only network a renewal failed and
the chat said 'Not signed in to Kiro'. Every sign-in and refresh request
now passes resolve_proxy(url), with trust_env still off (no netrc), and
the temporary renewal session is bounded to 30 s.

An engine line that names the proxy, its tunnel or CONNECT and carries a
refusal is now a connection error with a proxy message, not a sign-in
failure. A bare 403 keeps its signed-out verdict.

Closes #36954

(cherry picked from commit c8f45fb)
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.

KAS sign-in on a proxy network: renewal skips the proxy, and a proxy's 403 reads as not signed in

3 participants