Skip to content

fleet: tailnet tunnels use the seat's recorded tailnet proxy (#12555) - #12645

Merged
dezren39 merged 2 commits into
mainfrom
claude/12555-broker-tailnet-proxy-env
Nov 22, 2026
Merged

dezren39 merged 2 commits into
mainfrom
claude/12555-broker-tailnet-proxy-env

Conversation

@dezren39

@dezren39 dezren39 commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Refs #12555

Before: a fleet process started from a sandbox shell (for example a broker auto-spawned by fleet agent doctor) inherited the platform egress proxy in HTTPS_PROXY and opened every tailnet tunnel through it. The queue and shell legs failed while the broker looked alive.

After: tailnet tunnels use the seat's recorded tailnet proxy from fleet-proxy.env whenever that file exists, whatever the caller's environment. The Cloudflare leg keeps the ambient proxy, so it still works as a fallback when tailscaled is down. With no file, as on a kernel-mode seat, nothing changes.

How: fleet_config::tailnet_https_proxy() reads the first readable file among $FLEET_PROXY_ENV, ~/.local/state/tailscale/agents/<slug>/fleet-proxy.env (the bootstrap's own slug rule over $FLEET_AGENT) and the legacy ~/.local/state/tailscale/fleet-proxy.env. fleet_proxy::tunnel::egress_from_env, the one parser every tailnet leg uses, prefers it over HTTPS_PROXY. The muse bootstrap now removes a stale fleet-proxy.env when a seat comes up in kernel mode. Unit tests pin the lookup order, the slug rule and the parser; fleet-config and fleet-proxy tests pass and the fleet workspace builds with all features.


Generated by Claude Code

A fleet client that finds no broker spawns `fleet proxy serve` with its
own environment. From a sandbox shell that carries the platform egress
proxy in HTTPS_PROXY, the broker then opens every tailnet tunnel through
the wrong proxy and the queue and shell legs fail while it looks alive.

Both spawn sites now set HTTPS_PROXY from fleet-proxy.env, the file the
seat bootstrap writes beside tailscaled's node state ($FLEET_PROXY_ENV,
then the named agent's state, then the legacy shared state). With no
such file, as on a kernel-mode seat, the ambient env is kept.

Refs #12555

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dezren39
dezren39 marked this pull request as ready for review November 22, 2026 18:04
@dezren39
dezren39 requested a review from a team as a code owner November 22, 2026 18:04
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 30 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 058baa4a-1536-4619-8aad-6ac095caad7f
Commits

Reviewing files that changed from the base of the PR and between 24d33a5 and 8884e06.

Files selected for processing: 3

  • pkgs/fleet/crates/fleet-config/src/lib.rs
  • pkgs/fleet/crates/fleet-proxy/src/tunnel.rs
  • scripts/muse/bootstrap.sh
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T18:09:53.320321Z 8884e06 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d4dd1f7229

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +219 to +220
if let Some(proxy) = fleet_config::tailnet_https_proxy() {
cmd.env("HTTPS_PROXY", proxy);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve the platform proxy for the Cloudflare leg

On a userspace seat with a persisted fleet-proxy.env, if tailscaled is stopped or restarting, this override also disables the independent Cloudflare fallback. In fleet-proxy/src/serve.rs, startup derives both the tailnet endpoint and cf_egress from HTTPS_PROXY (via egress_from_env and egress_from_env_url_port), so both transports now connect to the unavailable 127.0.0.1:3130 instead of letting Cloudflare use the caller's working platform egress proxy. The queue client's spawn path has the same issue. Preserve the ambient proxy separately for Cloudflare and apply the seat proxy only to tailnet connections.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Right, fixed in 8884e06. The spawn sites no longer override HTTPS_PROXY. Instead tunnel::egress_from_env (the tailnet egress, used by serve, stdio, dispatch and the laptop-agent legs) prefers the seat's fleet-proxy.env, while egress_from_env_url_port keeps the ambient proxy, so the Cloudflare leg still works when tailscaled is down. The bootstrap also removes a stale fleet-proxy.env when the seat comes up in kernel mode.


Generated by Claude Code

Overriding HTTPS_PROXY at broker spawn also moved the Cloudflare leg
onto tailscaled's local proxy, so a stopped tailscaled took the
fallback down with it. Read fleet-proxy.env where the tailnet egress is
parsed instead: egress_from_env prefers the seat's recorded proxy and
the Cloudflare leg keeps the ambient one. The spawn sites go back to
inheriting the caller's env unchanged.

The bootstrap now removes a fleet-proxy.env left from a userspace run
when the seat comes up in kernel mode, since the file now steers
tailnet tunnels directly.

Refs #12555

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dezren39 dezren39 changed the title fleet: start an auto-spawned broker on the seat's tailnet proxy (#12555) fleet: tailnet tunnels use the seat's recorded tailnet proxy (#12555) Nov 22, 2026
@dezren39
dezren39 merged commit df657d1 into main Nov 22, 2026
1 check passed
@dezren39
dezren39 deleted the claude/12555-broker-tailnet-proxy-env branch November 22, 2026 18:10
dezren39 added a commit that referenced this pull request Nov 23, 2026
The broker parsed its tailnet egress once at startup. A broker
auto-spawned while tailscaled was down (or before bootstrap wrote
fleet-proxy.env) kept the ambient egress value — or none — for
its whole life, so queue/shell tailnet tunnels kept failing
after the tailnet recovered until a manual restart. That is the
startup-cache half of the #12426 failure mode, left after the
read-time preference landed for #12555 in #12645.

Tunnel opens now resolve fresh via egress_from_env (recorded
tailnet proxy first, ambient env second), falling back to the
startup parse when fresh resolution fails. Opens are pooled
and recovery-gated, so the re-read costs one small file read
per new tunnel, not per request. The Cloudflare leg's egress
is unchanged: the ambient platform proxy is its correct source.

Oracle: the resolve_tailnet_egress preference — a fresh
resolution wins, the startup parse is the fallback, and with
neither the resolution error surfaces. Three unit tests cover
the three branches; the fleet-proxy suite passes 113/113.
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.

2 participants