The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 21:00 UTC
fix(server): advertise the tailnet name when sshd listens only on the tailnet address (#34745)
Julius Marminge committed
Nov 11, 2026 at 20:39 UTC
a41b8820607c2c7bf1efac4912532d0699fa2413
2 files changed
+41
-10
apps/server/src/environment/RemoteOpenTargets.test.ts
+28
-3
@@ -53,17 +53,28 @@ const layerSpawner = (input: { readonly status: CommandResult; readonly prefs: C
53
}),
54
);
55
56
-const layerNet = (input: { readonly ipv4: boolean; readonly ipv6: boolean }) =>
56
+const layerNet = (input: {
57
+ readonly ipv4: boolean;
58
+ readonly ipv6: boolean;
59
+ readonly tailnet?: boolean;
60
+}) =>
61
Layer.succeed(NetService.NetService, {
62
canListenOnHost: () => Effect.succeed(true),
63
isPortAvailableOnLoopback: () => Effect.succeed(true),
60
- hasListenerOnHost: (_port, host) => Effect.succeed(host === "::1" ? input.ipv6 : input.ipv4),
64
+ hasListenerOnHost: (_port, host) =>
65
+ Effect.succeed(
66
+ host === "127.0.0.1"
67
+ ? input.ipv4
68
+ : host === "::1"
69
+ ? input.ipv6
70
+ : (host === "100.64.1.2" || host === "bb-1.tail1234.ts.net") && input.tailnet === true,
71
+ ),
72
reserveLoopbackPort: () => Effect.succeed(40_000),
73
findAvailablePort: (preferred) => Effect.succeed(preferred),
74
});
75
76
const resolveTargets = (input: {
66
- readonly sshd: { readonly ipv4: boolean; readonly ipv6: boolean };
77
+ readonly sshd: { readonly ipv4: boolean; readonly ipv6: boolean; readonly tailnet?: boolean };
78
readonly tailscale: { readonly status: CommandResult; readonly prefs: CommandResult };
79
readonly hostname: string;
80
readonly username?: string | null;
@@ -125,6 +136,20 @@ describe("RemoteOpenTargets", () => {
136
}),
137
);
138
139
+ it.effect("advertises the tailnet name when sshd listens only on the tailnet address", () =>
140
+ Effect.gen(function* () {
141
+ const targets = yield* resolveTargets({
142
+ sshd: { ipv4: false, ipv6: false, tailnet: true },
143
+ tailscale: TAILSCALE_UP,
144
+ hostname: "bb-1",
145
+ username: "t3-user",
146
+ });
147
+ expect(targets).toEqual([
148
+ { kind: "tailscale", host: "bb-1.tail1234.ts.net", username: "t3-user" },
149
+ ]);
150
+ }),
151
+ );
152
+
153
it.effect("ignores a stored RunSSH after `tailscale down`", () =>
154
Effect.gen(function* () {
155
const targets = yield* resolveTargets({
apps/server/src/environment/RemoteOpenTargets.ts
+13
-7
@@ -33,23 +33,29 @@ export const make = Effect.gen(function* () {
33
);
34
const username = yield* HostProcess.Username;
35
36
- const magicDnsName = yield* readTailscaleStatus.pipe(
37
- Effect.map((status) => status.magicDnsName),
36
+ const tailscaleStatus = yield* readTailscaleStatus.pipe(
37
Effect.orElseSucceed(() => null),
38
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
39
);
40
+ const magicDnsName = tailscaleStatus?.magicDnsName ?? null;
41
42
const targets: Array<RemoteOpenTarget> = [];
43
44
if (!sshdListening) {
45
- // Tailscale SSH needs no local sshd; tailscaled alone does not prove an SSH route.
46
- if (
47
- magicDnsName !== null &&
45
+ // sshd may listen only on the tailnet address (ListenAddress), and Tailscale SSH
46
+ // needs no local sshd; tailscaled alone does not prove an SSH route.
47
+ if (magicDnsName === null) return targets;
48
+ const tailnetSshdListening = yield* Effect.forEach(
49
+ tailscaleStatus?.tailnetIpv4Addresses ?? [],
50
+ (address) => net.hasListenerOnHost(SSH_PORT, address),
51
+ ).pipe(Effect.map((listening) => listening.includes(true)));
52
+ const sshRoute =
53
+ tailnetSshdListening ||
54
(yield* readTailscaleSshEnabled.pipe(
55
Effect.orElseSucceed(() => false),
56
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
51
- ))
52
- ) {
57
+ ));
58
+ if (sshRoute) {
59
targets.push({
60
kind: "tailscale",
61
host: magicDnsName,