Skip to content

fix: send sign-in and refresh requests through the configured proxy - #31966

Closed
okajun35 wants to merge 2 commits into
kirodotdev:mainfrom
okajun35:fix/kas-login-proxy
Closed

okajun35 wants to merge 2 commits into
kirodotdev:mainfrom
okajun35:fix/kas-login-proxy

Conversation

@okajun35

@okajun35 okajun35 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: kirocrew kas login and token refresh reach the sign-in service on a proxy-only network.

On a network whose only egress is an HTTP(S) proxy, kirocrew kas login and the dashboard's Sign in time out: every request to the issuer is dialed directly because aiohttp sessions do not read HTTP_PROXY/HTTPS_PROXY/NO_PROXY on their own, and each token refresh fails the same way afterwards. Reported by Zedmor on #20185.

Why it matters

Sign-in is the onboarding gate: a fresh user on a proxy-only network cannot authenticate at all even though install worked, and an existing sign-in silently degrades once the token needs refreshing. The unreachable-service error also reads as "the service is down", sending users to retry instead of checking their proxy.

Not a goal

What changed (motivation → approach → change)

Symptom: sign-in and refresh dial the issuer directly, so proxy-required networks time out. Root cause: none of the auth call sites passed proxy=, and the sessions correctly keep trust_env off, so the environment's proxy settings are never consulted. Change: every issuer request in kiro_crew.auth now passes proxy=resolve_proxy(url) — the helper the update check and MCP registry already use — covering device authorization, both poll loops, portal and external-IdP code exchange, control-plane profile lookup, and all three refresh paths (the sessions auth/provider.py and dashboard/sign_in_refresher.py create issue no requests themselves; their calls flow through auth/refresh.py). Every control-plane host the profile lookup falls through to gets its own resolve_proxy. On top of the port-qualified NO_PROXY check from #31732, the shared resolver in src/kiro_crew/http_proxy.py now also keeps an IPv6 literal's brackets ([2001:db8::1]:8443), treats wss as port 443, and falls back to the scheme's default port on an unparsable port instead of raising. kirocrew kas login names the configured proxy, with any user:password@ redacted, in its unreachable-service and lost-contact errors, and docs/system-specs/modules/kas-auth.md documents the transport rules.

Backwards compatibility

Compatible: with no proxy variables configured every request resolves to a direct dial, exactly as today, and NO_PROXY semantics only get strictly more faithful.

Removes nothing: the diff only adds request kwargs, a bypass check, and error text.

Tests

test/test_kas_auth_proxy.py (new): every issuer call site × {HTTPS-first, HTTPS-only, HTTP-fallback, direct} plus NO_PROXY cases (exact host, suffix, wildcard, port-qualified, unrelated host, custom IdP port), the control-plane fallback to a second host, the end-to-end begin_device + poll path, the trust_env is False pin, and both CLI error messages including credential redaction. test_http_proxy.py adds the IPv6 bracket cases, and it and test_update_feed_proxy.py pin the resolver's two-step bypass check. Seven existing fake post() doubles accept the new proxy kwarg.

Proof: PROVEN test/test_http_proxy.py::test_environment_bypass_ipv6_port_qualified[[2001:db8::1]:8443-None], test/test_http_proxy.py::test_ipv6_port_qualified_check_keeps_brackets, test/test_kas_auth_proxy.py::test_auth_request_uses_the_env_proxy[social-authorize-https-first], test/test_kas_auth_proxy.py::test_auth_request_uses_the_env_proxy[social-authorize-https-only], test/test_kas_auth_proxy.py::test_auth_request_uses_the_env_proxy[social-authorize-http-fallback] (head b30dcfa)

Manual verification

No live proxy host was available; coverage sits at the request seam (aiohttp.ClientSession._request kwargs, including the real trust_env flag on live sessions) plus urllib's real environment readers for NO_PROXY semantics.

Related Issues

Part of #20185

Sibling sweep

Swept: git grep -nE "session\.(get|post|put|request|ws_connect)|ClientSession\(" -- src/kiro_crew/auth/ src/kiro_crew/cli_kas_login.py src/kiro_crew/dashboard/sign_in_refresher.py src/kiro_crew/dashboard/handlers/kas_login.py
Sibling: src/kiro_crew/auth/provider.py:82 -- not affected -- the session issues no requests; its refresh call flows through auth/refresh.py
Sibling: src/kiro_crew/dashboard/sign_in_refresher.py:121 -- not affected -- the session is only handed to ensure_fresh
Sibling: src/kiro_crew/auth/login/builder_id.py -- changed here
Sibling: src/kiro_crew/auth/login/control_plane.py -- changed here
Sibling: src/kiro_crew/auth/login/device.py -- changed here
Sibling: src/kiro_crew/auth/login/external_idp.py -- changed here
Sibling: src/kiro_crew/auth/login/portal.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/handlers/link_meta.py -- tracked in #20185
Sibling: src/kiro_crew/dashboard/messaging_api/teams_settings.py -- tracked in #20185

Pattern harvest

Rule candidate: review-prompt
Pattern: outbound aiohttp request to an external URL issued without an explicit proxy= argument while trust_env stays off -- #20185 tracks the remaining sweep.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (fix: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (docs/system-specs/modules/kas-auth.md)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Transport-error messages expose authenticated proxy passwords, and IPv6 NO_PROXY matching incorrectly routes direct traffic through the proxy.

3 open issues
What changed in this PR

This PR extends the proxy-support work in #20185 to Kiro Crew sign-in and token refresh, using explicit proxy selection without enabling .netrc credential discovery.

Changes:

  • Routes authentication requests through the shared proxy resolver.
  • Adds port-qualified NO_PROXY handling and proxy-aware CLI error messages.
  • Documents transport behavior and adds proxy-routing tests.
File Description
test/​test_update_feed_proxy.py Updates bypass-call expectations.
test/​test_sign_in_refresher.py Allows proxy arguments in the refresh fake.
test/​test_kas_login_signout_generation.py Allows proxy arguments in the session fake.
test/​test_kas_login_service.py Updates the login-service session fake.
test/​test_kas_login_loopback.py Updates the loopback session fake.
test/​test_kas_auth_shape_idp.py Updates the IdP session fake.
test/​test_kas_auth_proxy.py Adds authentication proxy and bypass coverage.
test/​test_kas_auth_flows.py Updates authentication request doubles.
test/​test_kas_auth_device.py Updates the device-login session fake.
test/​test_http_proxy.py Tests port-qualified bypass behavior.
src/​kiro_crew/​http_proxy.py Checks effective ports for proxy bypasses.
src/​kiro_crew/​cli_kas_login.py Adds proxy context to connection errors.
src/​kiro_crew/​auth/​service.py Applies proxy selection to service polling.
src/​kiro_crew/​auth/​refresh.py Applies proxy selection to all refresh paths.
src/​kiro_crew/​auth/​login/​portal.py Proxies portal token exchange.
src/​kiro_crew/​auth/​login/​external_idp.py Proxies external IdP token exchange.
src/​kiro_crew/​auth/​login/​device.py Proxies social device authorization and polling.
src/​kiro_crew/​auth/​login/​control_plane.py Proxies profile lookup requests.
src/​kiro_crew/​auth/​login/​builder_id.py Proxies OIDC registration, authorization, and polling.
docs/​system-specs/​modules/​kas-auth.md Documents authentication proxy transport rules.

Review effort: Balanced

Comment thread src/kiro_crew/cli_kas_login.py Outdated
proxy = resolve_proxy(base)
if not proxy:
return ""
return f"; the request goes through your configured proxy ({proxy}) -- check it is reachable"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in f383f36. _configured_proxy_note() now passes the proxy URL through redact_log_via_context() before formatting, so http://user:pass@proxy:3128 prints as [REDACTED: credential]proxy:3128. Regression: test_unreachable_message_redacts_proxy_credentials in test/test_kas_auth_proxy.py.

Comment thread src/kiro_crew/http_proxy.py Outdated
port = None
if port is None:
port = 443 if parsed.scheme in ("https", "wss") else 80
if urllib.request.proxy_bypass(host) or urllib.request.proxy_bypass(f"{host}:{port}"):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in f383f36. The port-qualified check now builds [addr]:port when the host is an IPv6 literal, so NO_PROXY=[2001:db8::1]:8443 bypasses https://[2001:db8::1]:8443/token. Covered by test_environment_bypass_ipv6_port_qualified (match and non-matching port) and test_ipv6_port_qualified_check_keeps_brackets in test/test_http_proxy.py.

Comment thread test/test_kas_auth_proxy.py Outdated
Comment on lines +245 to +247
Enterprise IdP endpoints are operator-configured, so the shared resolver
checks the effective port alongside the bare host -- the finding the GPT 6.1
lane upheld on #31732.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in f383f36. Removed the ticket IDs and review/reporter history from both docstrings in test/test_kas_auth_proxy.py, keeping only the current-behavior explanation. check_comment_history.py now passes on this diff.

@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 7, 2026
@okajun35
okajun35 force-pushed the fix/kas-login-proxy branch from f383f36 to a9b1b73 Compare November 7, 2026 04:45
@okajun35

okajun35 commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main (52b17fe -> e4611c5) because the branch was out of date; no conflicts. The review-fix commit f383f36 cited in the thread replies is now a9b1b73 with identical content. Related auth/proxy tests (304) and the lint and diff-scoped gates pass locally on the rebased head.

@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
@okajun35
okajun35 force-pushed the fix/kas-login-proxy branch from a9b1b73 to b30dcfa Compare November 8, 2026 09:24
@okajun35

okajun35 commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main to resolve conflicts with #31732 and #32445. At the author's request, the ## Not a goal Slack bullet now says #31732 has landed instead of "in flight"; the scope it excludes is unchanged. What changed now describes the resolver delta on top of #31732, and _list_profiles_at passes proxy= for every control-plane host #32445 falls through to.

@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 8, 2026
okajun35 and others added 2 commits November 8, 2026 18:55
Every issuer request in the auth path now passes proxy=resolve_proxy(url),
the helper the update check and MCP registry already use, so kirocrew kas
login and token refresh work on a proxy-only network while the sessions
keep trust_env off (no ~/.netrc credentials). The shared resolver now also
checks a port-qualified NO_PROXY entry against the URL's effective port --
the defect the GPT 6.1 lane upheld on kirodotdev#31732. kirocrew kas login names the
configured proxy in its unreachable-service and lost-contact errors.

Part of kirodotdev#20185.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The kas login connection-error note printed the configured proxy URL
verbatim, so an authenticated proxy's user:password reached stderr and
captured login logs. The note now passes the URL through
redact_log_via_context before formatting it.

The port-qualified NO_PROXY check built "addr:port" from the bracketless
hostname, so an IPv6 entry such as [2001:db8::1]:8443 never matched and
the request went through the proxy. The check now keeps the brackets.

Also drop ticket and review history from two test docstrings, which the
comment-history gate rejects.
@iamwhatever

Copy link
Copy Markdown
Contributor

Thanks for this work, @okajun35. The same change landed on main in #36978 (merged 2026-11-14, commit c8f45fb): sign-in, polls, code exchange and every token refresh in auth/login/*, auth/refresh.py and auth/service.py now pass proxy=resolve_proxy(url). Rebasing this PR leaves only conflicts on those same lines, so I am closing it as superseded. If you find a request #36978 still sends around the proxy, please reopen with the path.

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Nov 17, 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) 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.

3 participants