refactor(client-runtime): decide learned routes and session reuse in one place #20445
main fromrefs/pull/20445/head·merged by juliusmarminge View on GitHubWhat changed#
- Learned routes and plain HTTP.
mergeLearnedRoutesinpackages/client-runtime/src/connection/routes.tsonly learns a plain-HTTP address outside the tailnet when the paired credential it borrows was itself paired over plain HTTP to a LAN or public address. Relay credentials are unchanged. - SSH session reuse. The SSH route's bearer token is saved in the connection catalog (
SshConnectionRegistrationcarries it,storageDocumentstores it, and removing the route drops it). The resolver's SSH broker passes the saved token toSshEnvironmentGateway.prepareand saves the token that comes back. The desktop gateway (prepareDesktopSshEnvironmentinapps/web/src/connection/platform.ts) brings up the tunnel, checks the host's environment id, then checks the saved session through the existingfetchSshSessionStateIPC. It reuses the session if it is valid and holds every standard client scope. Otherwise it pairs again through the add-environment path. - Docs.
docs/user/remote-access.mddescribes one session per desktop per SSH route and how to revoke unused ones, including the CLI.docs/internals/remote.mdnotes the plain-HTTP rule for learned routes.
The server and packages/ssh are unchanged.
Behavior changes#
- A token paired over HTTPS, loopback, or the tailnet no longer gets copied to a learned plain-HTTP LAN or public address. Tailnet plain-HTTP addresses are still learned.
- SSH reconnects and app restarts reuse one host session per desktop instead of creating a new 30-day session on every connect. Adding an environment and its first connect share that session.
- If the saved session is revoked, expired, or missing a standard scope, the next connect pairs once and saves the new token. Errors from the session check (network, 5xx) fail the attempt so the supervisor retries. They never pair.
- If a saved SSH route now reaches a different environment, the connect fails before pairing or sending the saved token.
- Older catalogs have no saved SSH token, so each desktop pairs once on its first connect after updating.
Testing#
tsc-rs --noEmitinpackages/client-runtimeandapps/web: both pass.vp test run src/connectioninpackages/client-runtime: 9 files, 176 tests passed.vp test run --project unit src/connection/platform.test.tsinapps/web: 18 tests passed.- The full suite was not run locally. CI covers it.
🤖 Generated with Claude Code
Closes #20288
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
juliusmarminge added labelsmacroscope-review
- apps/web/src/connection/platform.ts line 181OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -178,3 +178,4 @@178178 });179179 }180180181+function differentSshMachineError(label: string) {
This helper only constructs
Posted via Macroscope — Effect Service ConventionsConnectionBlockedError, which the convention asks to construct at the failure boundary. Could you inline the error at both mismatch checks and remove this helper? This requires changes at multiple locations, so no single-hunk suggestion applies.Inlined in 0b6daa5b196: removed
differentSshMachineErrorand constructConnectionBlockedErrordirectly at both mismatch checks (provision and prepare). Message text is unchanged. Approvability#
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — This PR changes production connection and authentication behavior by persisting/reusing SSH bearer sessions and restricting how credentials are propagated to learned HTTP routes. The cross-component, security-sensitive runtime impact warrants human review beyond a routine refactor.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Team
- Run ID:
b4debc49-9da6-4ae7-92f4-7f7a75e696c8
📥 Commits
-
Reviewing files that changed from the base of the PR and between f6e4fd48cf3221e6a2adf7a69a57e94ef5a7fc5e and 0b6daa5b19646c581c81e71d5278129322046556.
📒 Files selected for processing: 1
-
apps/web/src/connection/platform.ts
Limit details: You’ve used all 10 included reviews currently available.
-
📝 Walkthrough
-
SSH registrations now persist paired bearer credentials. Reconnection reuses a saved token when the host accepts it with standard scopes, or pairs again otherwise. Learned plain-HTTP routes use rules based on the saved route for the shared credential.
Changes: SSH credential reuse and learned routes
Layer / File(s) Summary Persist paired SSH credentials
packages/client-runtime/src/connection/catalog.ts,packages/client-runtime/src/connection/onboarding.ts,packages/client-runtime/src/connection/onboarding.test.ts,packages/client-runtime/src/platform/storageDocument.ts,packages/client-runtime/src/platform/storageDocument.test.ts,packages/client-runtime/src/connection/registry.test.tsSSH registrations now include the paired bearer credential. Catalog storage saves it with the SSH profile and removes it when the environment is removed. Registration and storage tests cover the credential. Reuse credentials during SSH preparation
packages/client-runtime/src/platform/capabilities.ts,packages/client-runtime/src/connection/resolver.ts,packages/client-runtime/src/connection/resolver.test.ts,apps/web/src/connection/platform.ts,apps/web/src/connection/platform.test.ts,docs/user/remote-access.mdThe SSH broker passes a saved token to preparation and stores a changed returned token. Desktop preparation checks the environment ID and session scopes before reuse, and pairs again when needed. Tests cover reuse, re-pairing, and environment mismatch. The remote-access guide describes session reuse and revocation. Restrict learned plain-HTTP routes
packages/client-runtime/src/connection/routes.ts,packages/client-runtime/src/connection/routes.test.ts,docs/internals/remote.mdLearned plain-HTTP endpoints are accepted only when the insecure-route setting is enabled and the endpoint is tailnet or the shared credential’s saved route qualifies. Tests and remote architecture documentation describe the route behavior. Generated router metadata
Layer / File(s) Summary Mark generated route tree
apps/web/src/routeTree.gen.tsThe file now identifies TanStack Router as its generator and warns that manual edits are overwritten. Priority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix · Severity of issue fixed: Medium
Sequence Diagram(s)#
sequenceDiagram participant SSHBroker participant CredentialStore participant SshEnvironmentGateway participant SSHHost SSHBroker->>CredentialStore: Read saved bearer credential SSHBroker->>SshEnvironmentGateway: Prepare with saved token SshEnvironmentGateway->>SSHHost: Check environment and token session SSHHost-->>SshEnvironmentGateway: Return authentication and scopes SshEnvironmentGateway-->>SSHBroker: Return reused or newly paired token SSHBroker->>CredentialStore: Save changed bearer credentialSuggested reviewers:
maria-rcks
Merge Risk: ⚪ Minimal · up to
0b6da-
The change reuses saved SSH sessions and restricts learned plain-HTTP routes. No concrete merge-blocking risk was identified in the supplied material.
Pre-merge checks:
2 · 2-
Failed checks: 2 warningsCheck name Status Explanation Resolution Description check The description explains the changes, behavior, testing, and linked issue. It does not use the required Problem, Change, Scope and approval, and Verification headings. It also does not document mainta… Add the required sections: Problem, Change, Scope and approval, and Verification. Include the triaged issue or explicit maintainer approval with its approval comment, or explain why this focused change qualifies for an exemption. Preserve t… Out of Scope Changes check [Issue #20288] The learned-route changes inpackages/client-runtime/src/connection/routes.tsandroutes.test.tschange plain-HTTP credential propagation. They do not address stale SSH sessions. `d…Remove the learned-route implementation, its tests, and its documentation from this PR, and remove the unrelated generated header change. Alternatively, link the learned-route work to a separate active issue and split it into a separate pul… Passed checks: 2 passed-
Check name Status Explanation Title check The title clearly identifies both primary changes: learned-route decisions and SSH session reuse. It is concise, specific, and uses a valid conventional commit format. Linked Issues check [Issue #20288] The PR stores the SSH bearer token in the connection catalog and credential store.resolver.tspasses the saved token tossh.prepareand saves a replacement token.platform.tsche…Full details: Linked Issues check
-
Explanation
[Issue
#20288] The PR stores the SSH bearer token in the connection catalog and credential store.resolver.tspasses the saved token tossh.prepareand saves a replacement token.platform.tschecks the environment ID before token use, reuses a session only when it is authenticated and has allAuthStandardClientScopes, and pairs again when the session is invalid or incomplete. The reported tests cover reuse, re-pairing, and environment mismatch behavior.
-
Full details: Description check
-
Explanation
The description explains the changes, behavior, testing, and linked issue. It does not use the required Problem, Change, Scope and approval, and Verification headings. It also does not document maintainer approval or explain why the change qualifies without prior approval.
Resolution
Add the required sections: Problem, Change, Scope and approval, and Verification. Include the triaged issue or explicit maintainer approval with its approval comment, or explain why this focused change qualifies for an exemption. Preserve the existing test commands and results under Verification.
Full details: Out of Scope Changes check
-
Explanation
[Issue
#20288] The learned-route changes inpackages/client-runtime/src/connection/routes.tsandroutes.test.tschange plain-HTTP credential propagation. They do not address stale SSH sessions.docs/internals/remote.mddocuments that unrelated behavior. The generated header change inapps/web/src/routeTree.gen.tsalso has no connection to SSH session reuse. The SSH documentation and related SSH tests remain in scope.Resolution
Remove the learned-route implementation, its tests, and its documentation from this PR, and remove the unrelated generated header change. Alternatively, link the learned-route work to a separate active issue and split it into a separate pull request.
-
- Fix all pre-merge checks with AI
✨ Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Usage-based review receipt#
- Mode: Continue automatically
- Reviewed files: 1
- Charged: $0.25
- View usage details
Comment `@coderabbitai help` to get the list of available commands.Note
This review was completed with usage-based billing: files reviewed beyond your plan's included limits are billed at $0.25/file. View usage-based billing.
-
- @@ -252,9 +251,14 @@252251 ];253252 }254253 if (url === null || !reported.has(normalized(url)) || known.has(normalized(url))) return [];254+ if (sendsTokenInClear(saved, route, tailscaleOrigins.has(normalized(url)))) return [];255255 known.add(normalized(url));256256 return [withNetwork(route, tailscaleOrigins.has(normalized(url)))];257257 });258258 let next: ReadonlyArray<ConnectionRoute> = kept;259259 for (const url of reported.values()) {260260 if (known.has(url.origin)) continue;261+ if (262+ url.protocol === "http:" &&263+ sharedCredential !== undefined &&264+ !tailscaleOrigins.has(url.origin) &&
🟡 Medium
connection/routes.ts:264A reported
*.ts.netor Tailscale IPv6 endpoint withoutkind: "tailnet"is dropped for an HTTPS-paired credential, and a saved learned route withoutprofile.networkis filtered out byusableRoutes. Both checks rely only on explicit tailnet markers, so they reject hosts thatconnectionRouteKindrecognizes as tailnet; includeisTailnetHostrecognition in both checks.🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @packages/client-runtime/src/connection/routes.ts around line 264: A reported `*.ts.net` or Tailscale IPv6 endpoint without `kind: "tailnet"` is dropped for an HTTPS-paired credential, and a saved learned route without `profile.network` is filtered out by `usableRoutes`. Both checks rely only on explicit tailnet markers, so they reject hosts that `connectionRouteKind` recognizes as tailnet; include `isTailnetHost` recognition in both checks. juliusmarminge merged thisc9b8f21
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed