Skip to content

feat(planning): lease and route the shared interview's named tunnel - #10832

Merged
kyle-sexton merged 9 commits into
mainfrom
feat/8607-shared-interview-named-tunnel
Oct 29, 2026
Merged

kyle-sexton merged 9 commits into
mainfrom
feat/8607-shared-interview-named-tunnel

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Refs: #8607

Summary

Shared /planning:interview sessions get one stable guest link, https://<tunnel_hostname>, usable from any machine in the owner's fleet on any local guest port. The issue closes separately once the fleet settings land.

Fix

  • Before starting the named tunnel, ensure-running probes the link itself (/api/tunnel-probe/<nonce>). Another live interview answering means this session falls back to a quick tunnel and reports why in tunnelFallback; Cloudflare's 530 / error 1033 no-connector page means the link is free. This is a best-effort check, not an atomic lease (see Known limits).
  • New tunnel_api_token_file option: a Cloudflare account API token with "Cloudflare One Connector: cloudflared Write". With it, the session checks the tunnel's connectors and merges its hostname's ingress rule to its own guest port, so the fixed-8765 rule no longer applies. Without it the guest port stays fixed at 8765.
  • A missing or unusable token file falls back to a quick tunnel instead of failing; an unexpanded option token reads as unset.
  • Docs: shared/README.md (named tunnel lease and setup), lane-shared.md, plugin options, changelog fragment.

Verification

  • test_share, test_tunnel, test_cfdns, test_server: 478 tests pass, 1 Windows-only skip. Ruff (pinned wrapper) clean. validate-plugin-contracts, sync-plugin-options-docs --check and interview-defenses.test.sh (172 pass) green. 4 mutants killed, plus 3 on the review fixes (regression fix removed, bare-1033 match, exception naming), each failing a new test.
  • Live run on 2026-10-29 against the real named tunnel and its public hostname:
    1. Session A with --guest-port 8790 plus hostname, run-token and API-token files: "tunnel": "named", public URL HTTP 200, tunnel ingress read back as http://127.0.0.1:8790, one connector.
    2. Session B (separate data dir, port 8791) started while A ran: stderr "another interview session already serves https://; a quick tunnel serves this session instead", "tunnel": "quick", tunnelFallback set.
    3. A stopped: public /api/state returned HTTP 530. B's ensure-running re-run: "tunnel": "named", shareChanged: true, same #join key kept, public URL HTTP 200, ingress read back as http://127.0.0.1:8791.
    4. Both stopped, ingress reset to 8765.
  • Ready-time reviews: both CI review lanes were stopped by the lanes kill switch on this head, so a local code review and a local security review ran over the PR diff in their place. Their findings and dispositions are listed below.
  • Known limits:
    • The lease is not atomic. A machine that connects, or writes the route, after this session's post-start check is not seen; the route is one tunnel-wide setting, so in that window the last write wins. The README's "The lease" section says so.
    • Reading HTTP 530 plus "Error 1033" as "no connector" rests on two Cloudflare pages (error 530, error 1033) and on the page body read from a stopped quick tunnel's hostname on 2026-10-29, which holds <span>Error</span> <span>1033</span>; the match strips tags first.
  • Review findings (owner chose to fix all in this PR), with dispositions:
    • Security, fail-open probe: fixed in 294fb8b. Only the no-connector page counts as free; DNS failure, refused connection, timeout and TLS errors count as held. Tests cover each branch in-process.
    • Security, connectors before the route: fixed in 294fb8b. With the API token, a session lists the tunnel's connections and falls back to a quick tunnel when any other connector has an open connection (its own is matched by the Connector ID cloudflared logs, recorded as connector).
    • Security, watchdog restart: fixed in 294fb8b. The server's restart runs the same probe, connector check and route (the record now keeps apiTokenFile). A certain holder gets a quick tunnel (guests on the named link then reach the other machine, so no page can learn the new link); an unclear answer leaves the tunnel down and retries after the backoff.
    • Security, simultaneous starts: fixed in 294fb8b within the window above. After starting, the session re-reads the connectors and reads the route back; another connector or a route naming another port ends its named tunnel at once (never kept as a retired tunnel) and runs a quick one. Both machines may fall back, which is the safe outcome.
    • Security, token reach: fixed in b3a6eb6. Setup step 1 and the option descriptions say the connector token cannot touch DNS but can change every tunnel in the account, and recommend keeping the account's tunnels to this use or a dedicated account.
    • Whole-config PUT: fixed in 294fb8b. The session GETs the configuration, changes only the service of its hostname's rule (one with no path; a per-rule originRequest stays), inserts the rule before the catch-all when absent, keeps originRequest, warp-routing and other rules, and PUTs only on a change.
    • Regression, unusable token file on a running session: fixed in 294fb8b. A session whose own named tunnel runs keeps it, exit 0, and says on stderr that its running tunnel keeps serving. The test failed before the fix (exit 1, refused switch).
    • Small: fixed in 294fb8b and b3a6eb6. "Error 1033" is matched apart from its markup (a literal Error 1033 would never match Cloudflare's real page); str(exc) or type(exc).__name__ names a bare TimeoutError; the --tunnel-token-file help, README step 5, and the stale set tunnel_api_token_file hint on a re-run without flags are fixed.
    • Added on request: both token file options accept a path starting with ~/, expanded before the checks; cloudflared gets the expanded absolute path.
    • Found while fixing, a crashed cloudflared of this session: fixed in 9a7506c. Cloudflare can still list the connector of this session's crashed cloudflared, so the connector check now counts the Connector IDs of the running record and of the session's last record for the hostname as its own; the server's restart passes both. New tests in test_share and test_server; the four suites pass (1 Windows-only skip).
    • Review round 2 on 9a7506c, both fixed in 7c62aa5 with a test that failed on 9a7506c: a named start that loses the post-start race now keeps the quick tunnel guests still hold (tunnel.fall_back), instead of ending it for a new link no page can learn; and confirm treats a lone listed connector as unclear when its own cloudflared logged no Connector ID.
    • Windows CI: the ~/ expansion now normalizes the path (os.path.normpath), so cloudflared gets native separators; test_token_files_may_start_with_a_tilde_and_resolve_under_home failed on Windows before it. The ConnectionAbortedError in test_unknown_routes_are_404 on b3a6eb6's Windows run did not recur on 9a7506c.
  • Left out: a strict, atomic lease; the configurations update reference documents no version precondition to build one on.

Related

🤖 Generated with Claude Code

kyle-sexton and others added 4 commits October 28, 2026 21:43
Before this machine starts the named tunnel, ensure-running asks
https://<hostname> itself: a live interview server or another connector
answering means the link is held, so the session falls back to a quick
tunnel and says why (stderr and tunnelFallback). With the new
--tunnel-api-token-file, it points the tunnel's ingress at this
session's actual guest port, so any free port works. A token file that
cannot be used falls back instead of refusing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nel lease

Adds the tunnel_api_token_file option to plugin.json, the options table,
the interview skill's Variables line and lane-shared.md's ensure-running
command. The shared README replaces "one machine per tunnel" with the
lease and route behavior, names the tunnel-only token's permission, and
fixes setup step 1's permission naming. Changelog fragment included.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An unset userConfig key can reach the skill as its literal token; a
named tunnel then keeps today's fixed-port behavior instead of falling
back to a quick tunnel. Neutral wording for a link answer that is not
the no-connector page, and no unsourced claim about the connections list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review October 29, 2026 01:57
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T02:03:42.754017Z c5a9e6d Draft marked ready
ℹ️ 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: c5a9e6dc9b

ℹ️ 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 thread plugins/planning/shared/share.py Resolved
@kyle-sexton kyle-sexton added the do-not-merge Hard merge gate: do not merge while applied. label Oct 29, 2026

@github-actions github-actions Bot 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.

claude-security-review: 3 inline finding(s) on c5a9e6dc9b0d6719a03a3305a0f7f3b406522de3; the summary is in this lane's pull request comment.

claude-lane: claude-security-review

Comment thread plugins/planning/shared/share.py Resolved
Comment thread plugins/planning/shared/share.py Resolved
Comment thread plugins/planning/shared/README.md Resolved
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed a4015180910030b5e56abd3dafadaafe32ef6b81: 1 finding(s), 1 as inline comments.

Security review of #10832 (named-tunnel lease and route for the shared interview). I read the whole diff and PR context, and checked the changed share.py, server.py and tunnel.py paths. I found no exploitable path and no widened trust control.

critical-findings: 0

Manifest

  • manifest userConfig tunnel_api_token_file: flag, IMPORTANT. See the inline comment.
  • manifest userConfig tunnel_hostname / tunnel_token_file description: pass (inert).
  • Nothing was added or changed in hooks, mcpServers, lspServers, monitors, dependencies or marketplace.json.

Checked, no finding

  • API token handling. tunnel_api_token_file is read only by share.py and the server's restart. It goes through cfdns.api_token / cfdns.request to Cloudflare's API and is never put on a command line or in a record. The record keeps only the path. run_token_ids decodes the tunnel token for the account and tunnel ids and discards the secret, and its errors do not quote the token.
  • Fail-closed lease probe. link_holder (share.py) counts only HTTP 530 plus the "Error 1033" text as free. A DNS failure, refused connection, timeout, TLS error or any other status counts as held, and the session falls back to a quick tunnel. The only way to redirect the probe is the SHARED_LEASE_ORIGIN environment variable, which lease_target limits to an http loopback origin.
  • Fallback to a quick tunnel. A missing or unusable token file now falls back to a quick tunnel instead of refusing to start. A quick tunnel is the plugin's default, and the fallback is reported on stderr and in tunnelFallback. This exposes no more than the default does.
  • Route rewrite. routed changes only the service of the hostname's own rule and keeps the other rules, originRequest and warp-routing. It PUTs only when the configuration changed.
  • Shell command in lane-shared.md. The new --tunnel-api-token-file '${user_config...}' argument follows the existing quoting pattern for owner-set options. The value is owner-controlled, not untrusted input.
  • Instruction surfaces. The SKILL.md and lane-shared.md edits add an option and soften no guardrail.
  • Cost. No billed resource or plan change. I did not read the test-file hunks beyond a skim, and they are not shipped code.

Note, not counted: the API token's permission ("Cloudflare One Connector: cloudflared Write") can change every tunnel in the account. The PR documents this in the README, the option descriptions and the changelog. The option is opt-in, with an empty default.

@github-actions github-actions Bot 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.

claude-review: 5 inline finding(s) on c5a9e6dc9b0d6719a03a3305a0f7f3b406522de3; the summary is in this lane's pull request comment.

claude-lane: claude-review

Comment thread plugins/planning/shared/share.py Resolved
Comment thread plugins/planning/shared/share.py Resolved
Comment thread plugins/planning/shared/share.py Resolved
Comment thread plugins/planning/shared/share.py Resolved
Comment thread plugins/planning/shared/share.py Resolved
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed a4015180910030b5e56abd3dafadaafe32ef6b81: 0 finding(s), 0 as inline comments.

No blocking or advisory findings on a4015180. I read the whole diff (15 files) and the PR context. I ran no tests and no code, and the PR's test counts and live-run results are author-claimed and unverified by me.

What I checked

  • share.py named-tunnel start (bring_up, named_config). I traced the fallback, settled (own running tunnel), route and confirm paths against tunnel.ensure, tunnel.fall_back and the fields plumbing for apiTokenFile. State handling is consistent:
    • A fallback clears hostname, token_file and fixed together.
    • tunnelFallback is only set when a fallback happened.
    • confirm is skipped when the same cloudflared pid is kept.
  • server.py restart_tunnel. It uses the same share_cli.lease and confirm as the CLI. The detached.stop(pid, marker, start) call matches the detached.stop signature. A certain holder gets a quick tunnel, and an unclear answer raises TunnelDown, so the existing backoff retries. share_cli, tunnel, detached and loggable are all already imported or defined there.
  • Probe fail-closed. link_holder treats only HTTP 530 with "Error 1033" in the tag-stripped body as free. Every other answer, and every error, counts as held. That matches the PR's stated fix.
  • Token handling.
    • run_token_ids and cfdns.api_token never put the token in an error message.
    • Token files are checked for permissions before use.
    • ~/ paths are expanded and normalized before the checks.
    • An unexpanded ${user_config. token reads as unset.
  • Route merge. routed changes only the service of the hostname's pathless rule, or inserts one before the catch-all. It keeps other rules and the rest of the config, and route PUTs only when the result differs.
  • Docs and skill wiring. lane-shared.md, SKILL.md, the plugin README options table and shared/README.md agree with the code on the new flag, tunnelFallback, the apiTokenFile and connector record fields, and the removed "run on one machine" reminder.

Manifest (plugins/planning/.claude-plugin/plugin.json)

  • manifest userConfig defaults: pass. The new tunnel_api_token_file defaults to "", and no existing default changed.
  • manifest userConfig options: pass. No field gained or changed options.
  • manifest new field read by code: pass. SKILL.md passes ${user_config.tunnel_api_token_file} to --tunnel-api-token-file, and share.py reads it.
  • manifest version bump: pass. The bump: minor fragment fits a new option plus a behavior change to a fallback.
  • manifest description, keywords and docs: pass. The option descriptions and the plugin README table are updated.

Minor, not counted as a finding. others_up takes one listed connector as its own (up[1:]) when no Connector ID is known and its own cloudflared runs. That relies on list order only in the no-ID case. The README documents the case, and confirm treats it as unclear after the start.

Spend. Nothing here can start a real charge. The new API-token option calls Cloudflare's tunnel endpoints with the owner's own token, and the PR changes no plan or billing setting.

Closing issue. The PR says "Refs #8607" and closes nothing, so there are no acceptance criteria to check. No embedded instructions appeared in the PR text.

kyle-sexton and others added 2 commits October 28, 2026 22:42
Only Cloudflare's no-connector page (HTTP 530 whose text reads
"Error 1033", matched apart from its <span> markup) leaves the link free;
a DNS failure, refused connection, timeout or TLS error now counts as
held. With the API token file, a session refuses the tunnel while another
machine's connector is connected (matched against the Connector ID
cloudflared logs), merges only its hostname's rule into the tunnel's
configuration (GET, merge, PUT on a change) instead of replacing it, and
after starting re-reads the connectors and the route, ending its named
tunnel at once when a second machine started alongside. The server's
restart of an exited named tunnel goes through the same lease and route:
a certain holder gets a quick tunnel, an unclear answer a retry.

A session whose own named tunnel runs keeps it when a token file turns
unusable, the record keeps apiTokenFile so a re-run without the flags
stays routed, both token file options accept ~/, and a bare exception
names its type in the probe's reason.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…checks

The connector API token can change every tunnel in the account, not only
this one: the setup step and option descriptions say so and recommend
keeping the account's tunnels to this use. The README's lease section
covers the connector check, the merged route, the restart path and the
window the lease cannot see; setup step 5 no longer limits the options to
one machine; both token file options document ~/ paths.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@github-actions github-actions Bot 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.

claude-security-review: 1 inline finding(s) on b3a6eb624d8f7869d364c7bb01eedb576f70c342; the summary is in this lane's pull request comment.

claude-lane: claude-security-review

Comment thread plugins/planning/shared/share.py Resolved

@github-actions github-actions Bot 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.

claude-review: 1 inline finding(s) on b3a6eb624d8f7869d364c7bb01eedb576f70c342; the summary is in this lane's pull request comment.

claude-lane: claude-review

Comment thread plugins/planning/shared/share.py Resolved
kyle-sexton and others added 3 commits October 28, 2026 23:00
… the lease

The connector check now takes the Connector IDs from both the running record
and the last record for the link, so a dead cloudflared of this session still
listed by Cloudflare is not read as another machine. The server's tunnel watch
passes its record the same way; a test covers the routed restart through it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… race

A named start that confirm ended after a race restarted through tunnel.ensure
with no verify, which ended the quick tunnel guests still held. tunnel.fall_back
ends the named tunnel and makes the retired quick tunnel live again when it still
runs; ensure-running and the server's restart use it.

confirm now answers uncertain when this cloudflared logged no Connector ID and
any connector is listed, instead of taking a lone connector as its own.

A ~/ token path is normalized, so Windows gets native separators.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@github-actions github-actions Bot 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.

claude-security-review: 1 inline finding(s) on a4015180910030b5e56abd3dafadaafe32ef6b81; the summary is in this lane's pull request comment.

claude-lane: claude-security-review

@kyle-sexton kyle-sexton removed the do-not-merge Hard merge gate: do not merge while applied. label Oct 29, 2026
@kyle-sexton
kyle-sexton added this pull request to the merge queue Oct 29, 2026
Merged via the queue into main with commit 2ee7687 Oct 29, 2026
154 of 158 checks passed
@kyle-sexton
kyle-sexton deleted the feat/8607-shared-interview-named-tunnel branch October 29, 2026 12:48
@github-actions

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

Killed 0, survived 0, timeout 0, no coverage 0, invalid 0, not run 7.
Covered-code score n/a; mutation score n/a.

File Killed Survived Timeout No coverage Invalid Not run
plugins/planning/shared/server.py 0 0 0 0 0 1
plugins/planning/shared/share.py 0 0 0 0 0 4
plugins/planning/shared/tunnel.py 0 0 0 0 0 2

The run's summary has the full report.

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.

1 participant