Skip to content

Commit 23b1188

Browse files
t3dotggmaria-rcksZherueljuliusmarmingeonly21mil
committed
feat(tailscale): your own devices find and connect to your boxes with no pairing code
Squashed onto the latest main. Tailscale sign-in now follows the managed policy: without remote clients the desktop app keeps it off, `t3 up` refuses it, the server will not start with it, and Tailscale sessions are signed out at startup. Serve off uses main's per-path command, and the device block migration moves to 78. Folds in #25529, #24849, #23605, #24943, #25351, #15027, #26170 and #24638. Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Tin Zeljar <[email protected]> Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: Victor <[email protected]> Co-authored-by: tiliakoos <[email protected]> Co-authored-by: Srivishal Sivasubramanian <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 30654b3 commit 23b1188

169 files changed

Lines changed: 14626 additions & 1197 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/desktop/src/app/DesktopConnectionCatalogStore.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ const migrateSavedEnvironmentRecords = Effect.fn(
372372
credentials,
373373
remoteDpopTokens: [],
374374
disabledEnvironmentIds: [],
375+
dismissedEnvironmentIds: [],
375376
};
376377
});
377378

‎apps/desktop/src/backend/DesktopBackendConfiguration.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ const layerServerExposure = Layer.succeed(DesktopServerExposure.DesktopServerExp
3939
httpBaseUrl: new URL("http://127.0.0.1:4888"),
4040
tailscaleServeEnabled: true,
4141
tailscaleServePort: 8443,
42+
tailscaleSignInEnabled: false,
43+
tailscaleOnly: false,
4244
}),
4345
configureFromSettings: () => Effect.die("unexpected configureFromSettings"),
4446
setMode: () => Effect.die("unexpected setMode"),
4547
setTailscaleServeEnabled: () => Effect.die("unexpected setTailscaleServeEnabled"),
48+
setTailscaleSignInEnabled: () => Effect.die("unexpected setTailscaleSignInEnabled"),
4649
getAdvertisedEndpoints: Effect.succeed([]),
4750
} satisfies DesktopServerExposure.DesktopServerExposure["Service"]);
4851

@@ -245,6 +248,9 @@ describe("DesktopBackendConfiguration", () => {
245248
assert.isUndefined(first.env.T3CODE_PORT);
246249
assert.isUndefined(first.env.T3CODE_MODE);
247250
assert.isUndefined(first.env.T3CODE_DESKTOP_LAN_HOST);
251+
// Removed from what the backend inherits, so the desktop's own switch decides.
252+
assert.property(first.env, "T3CODE_TAILSCALE_SIGN_IN");
253+
assert.isUndefined(first.env.T3CODE_TAILSCALE_SIGN_IN);
248254

249255
assert.equal(first.bootstrap.mode, "desktop");
250256
assert.equal(first.bootstrap.noBrowser, true);

‎apps/desktop/src/backend/DesktopBackendConfiguration.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ const DESKTOP_BACKEND_ENV_NAMES = [
7878
"T3CODE_DESKTOP_HTTPS_ENDPOINTS",
7979
"T3CODE_TAILSCALE_SERVE",
8080
"T3CODE_TAILSCALE_SERVE_PORT",
81+
"T3CODE_TAILSCALE_SIGN_IN",
82+
"T3CODE_TAILSCALE_OWNER",
8183
] as const;
8284

8385
// Windows forwards these variables into WSL only through WSLENV.
@@ -507,6 +509,8 @@ const resolvePrimaryStartConfig = Effect.fn("desktop.backendConfiguration.resolv
507509
shellEnvironmentPrepared: input.shellEnvironmentPrepared,
508510
tailscaleServeEnabled: backendExposure.tailscaleServeEnabled,
509511
tailscaleServePort: backendExposure.tailscaleServePort,
512+
...(backendExposure.tailscaleSignInEnabled ? { tailscaleSignInEnabled: true } : {}),
513+
...(backendExposure.tailscaleOnly ? { tailscaleOnly: true } : {}),
510514
desktopTelemetryFd: 4,
511515
desktopTelemetryControlFd: 5,
512516
desktopBrowserFd: 6,

‎apps/desktop/src/backend/DesktopServerExposure.test.ts‎

Lines changed: 138 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ import * as Layer from "effect/Layer";
1010
import * as Option from "effect/Option";
1111
import * as Sink from "effect/Sink";
1212
import * as Stream from "effect/Stream";
13+
import { HttpClient, HttpClientResponse } from "effect/http";
1314
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
1415

1516
import * as DesktopEnvironment from "../app/DesktopEnvironment.ts";
1617
import * as DesktopConfig from "../app/DesktopConfig.ts";
1718
import * as DesktopManagedPolicy from "../app/DesktopManagedPolicy.ts";
1819
import * as DesktopNetworkInterfaces from "./DesktopNetworkInterfaces.ts";
1920
import * as DesktopServerExposure from "./DesktopServerExposure.ts";
21+
import * as DesktopTailscaleStatus from "./DesktopTailscaleStatus.ts";
2022
import * as DesktopAppSettings from "../settings/DesktopAppSettings.ts";
2123

2224
const encoder = new TextEncoder();
@@ -93,6 +95,7 @@ function layer(input: {
9395
readonly spawnerLayer?: Layer.Layer<ChildProcessSpawner.ChildProcessSpawner>;
9496
readonly desktopSettingsLayer?: Layer.Layer<DesktopAppSettings.DesktopAppSettings>;
9597
readonly managedPolicyLayer?: Layer.Layer<DesktopManagedPolicy.DesktopManagedPolicy>;
98+
readonly httpClientLayer?: Layer.Layer<HttpClient.HttpClient>;
9699
}) {
97100
const env = { T3CODE_HOME: input.baseDir, ...input.env };
98101
const layerEnvironment = layerEnvironmentFor(input.baseDir, env);
@@ -101,10 +104,11 @@ function layer(input: {
101104
});
102105

103106
return DesktopServerExposure.layer.pipe(
107+
Layer.provideMerge(DesktopTailscaleStatus.layer),
104108
Layer.provideMerge(input.desktopSettingsLayer ?? DesktopAppSettings.layer),
105109
Layer.provideMerge(input.managedPolicyLayer ?? DesktopManagedPolicy.layerTest()),
106110
Layer.provideMerge(NodeFileSystem.layer),
107-
Layer.provideMerge(NodeHttpClient.layerUndici),
111+
Layer.provideMerge(input.httpClientLayer ?? NodeHttpClient.layerUndici),
108112
Layer.provideMerge(input.spawnerLayer ?? layerMockSpawner()),
109113
Layer.provideMerge(layerNetwork),
110114
Layer.provideMerge(DesktopConfig.layerTest(env)),
@@ -127,6 +131,7 @@ const withHarness = <A, E, R>(
127131
spawnerLayer?: Layer.Layer<ChildProcessSpawner.ChildProcessSpawner>,
128132
desktopSettingsLayer?: Layer.Layer<DesktopAppSettings.DesktopAppSettings>,
129133
managedPolicyLayer?: Layer.Layer<DesktopManagedPolicy.DesktopManagedPolicy>,
134+
httpClientLayer?: Layer.Layer<HttpClient.HttpClient>,
130135
) =>
131136
Effect.gen(function* () {
132137
const fileSystem = yield* FileSystem.FileSystem;
@@ -142,6 +147,7 @@ const withHarness = <A, E, R>(
142147
...(spawnerLayer ? { spawnerLayer } : {}),
143148
...(desktopSettingsLayer ? { desktopSettingsLayer } : {}),
144149
...(managedPolicyLayer ? { managedPolicyLayer } : {}),
150+
...(httpClientLayer ? { httpClientLayer } : {}),
145151
}),
146152
),
147153
);
@@ -197,39 +203,46 @@ describe("DesktopServerExposure", () => {
197203
),
198204
);
199205

200-
it.effect("starts local-only, Serve off, when a managed policy keeps clients local", () =>
201-
withHarness(
202-
lanNetworkInterfaces,
203-
Effect.gen(function* () {
204-
const serverExposure = yield* DesktopServerExposure.DesktopServerExposure;
205-
const settings = yield* DesktopAppSettings.DesktopAppSettings;
206-
yield* settings.setServerExposureMode("network-accessible");
207-
yield* settings.setTailscaleServe({ enabled: true, port: Option.none() });
208-
209-
const state = yield* serverExposure.configureFromSettings({ port: 4173 });
210-
assert.equal(state.mode, "local-only");
211-
const backendConfig = yield* serverExposure.backendConfig;
212-
assert.equal(backendConfig.bindHost, "127.0.0.1");
213-
assert.isFalse(backendConfig.tailscaleServeEnabled);
214-
// Choosing them again while the policy applies does not widen the backend either.
215-
yield* serverExposure.setMode("network-accessible");
216-
yield* serverExposure.setTailscaleServeEnabled({ enabled: true });
217-
assert.equal((yield* serverExposure.backendConfig).bindHost, "127.0.0.1");
218-
assert.isFalse((yield* serverExposure.backendConfig).tailscaleServeEnabled);
219-
// The saved choice returns once the policy allows it.
220-
const saved = yield* settings.get;
221-
assert.equal(saved.serverExposureMode, "network-accessible");
222-
assert.isTrue(saved.tailscaleServeEnabled);
223-
}),
224-
{},
225-
undefined,
226-
undefined,
227-
DesktopManagedPolicy.layerTest({
228-
schemaVersion: 1,
229-
organization: "Example Corp",
230-
limits: { clients: ["desktop"] },
231-
}),
232-
),
206+
it.effect(
207+
"starts local-only, Serve and sign-in off, when a managed policy keeps clients local",
208+
() =>
209+
withHarness(
210+
lanNetworkInterfaces,
211+
Effect.gen(function* () {
212+
const serverExposure = yield* DesktopServerExposure.DesktopServerExposure;
213+
const settings = yield* DesktopAppSettings.DesktopAppSettings;
214+
yield* settings.setServerExposureMode("network-accessible");
215+
yield* settings.setTailscaleServe({ enabled: true, port: Option.none() });
216+
yield* settings.setTailscaleSignIn(true);
217+
218+
const state = yield* serverExposure.configureFromSettings({ port: 4173 });
219+
assert.equal(state.mode, "local-only");
220+
const backendConfig = yield* serverExposure.backendConfig;
221+
assert.equal(backendConfig.bindHost, "127.0.0.1");
222+
assert.isFalse(backendConfig.tailscaleServeEnabled);
223+
assert.isFalse(backendConfig.tailscaleSignInEnabled);
224+
// Choosing them again while the policy applies does not widen the backend either.
225+
yield* serverExposure.setMode("network-accessible");
226+
yield* serverExposure.setTailscaleServeEnabled({ enabled: true });
227+
yield* serverExposure.setTailscaleSignInEnabled(true);
228+
assert.equal((yield* serverExposure.backendConfig).bindHost, "127.0.0.1");
229+
assert.isFalse((yield* serverExposure.backendConfig).tailscaleServeEnabled);
230+
assert.isFalse((yield* serverExposure.backendConfig).tailscaleSignInEnabled);
231+
// The saved choice returns once the policy allows it.
232+
const saved = yield* settings.get;
233+
assert.equal(saved.serverExposureMode, "network-accessible");
234+
assert.isTrue(saved.tailscaleServeEnabled);
235+
assert.isTrue(saved.tailscaleSignInEnabled);
236+
}),
237+
{},
238+
undefined,
239+
undefined,
240+
DesktopManagedPolicy.layerTest({
241+
schemaVersion: 1,
242+
organization: "Example Corp",
243+
limits: { clients: ["desktop"] },
244+
}),
245+
),
233246
);
234247

235248
it.effect("persists network-accessible mode and updates backend binding state", () =>
@@ -250,6 +263,8 @@ describe("DesktopServerExposure", () => {
250263
advertisedHost: "192.168.1.20",
251264
tailscaleServeEnabled: false,
252265
tailscaleServePort: 443,
266+
tailscaleSignInEnabled: false,
267+
port: 4173,
253268
});
254269

255270
const backendConfig = yield* serverExposure.backendConfig;
@@ -338,6 +353,47 @@ describe("DesktopServerExposure", () => {
338353
),
339354
);
340355

356+
it.effect(
357+
"listens on the tailnet only while Tailscale sign-in is on and Network access is off",
358+
() =>
359+
withHarness(
360+
{ ...tailnetNetworkInterfaces, ...lanNetworkInterfaces },
361+
Effect.gen(function* () {
362+
const serverExposure = yield* DesktopServerExposure.DesktopServerExposure;
363+
yield* (yield* DesktopAppSettings.DesktopAppSettings).load;
364+
yield* serverExposure.configureFromSettings({ port: 3773 });
365+
366+
const signIn = yield* serverExposure.setTailscaleSignInEnabled(true);
367+
assert.equal(signIn.requiresRelaunch, true);
368+
assert.equal(signIn.state.tailscaleSignInEnabled, true);
369+
assert.equal(signIn.state.port, 3773);
370+
assert.deepInclude(yield* serverExposure.backendConfig, {
371+
bindHost: "0.0.0.0",
372+
tailscaleSignInEnabled: true,
373+
tailscaleOnly: true,
374+
});
375+
assert.deepEqual(
376+
(yield* serverExposure.getAdvertisedEndpoints).map((endpoint) => endpoint.httpBaseUrl),
377+
["http://127.0.0.1:3773/", "http://100.90.1.2:3773/"],
378+
);
379+
380+
yield* serverExposure.setMode("network-accessible");
381+
assert.deepInclude(yield* serverExposure.backendConfig, {
382+
bindHost: "0.0.0.0",
383+
tailscaleOnly: false,
384+
});
385+
386+
yield* serverExposure.setMode("local-only");
387+
yield* serverExposure.setTailscaleSignInEnabled(false);
388+
assert.deepInclude(yield* serverExposure.backendConfig, {
389+
bindHost: "127.0.0.1",
390+
tailscaleSignInEnabled: false,
391+
tailscaleOnly: false,
392+
});
393+
}),
394+
),
395+
);
396+
341397
it.effect("keeps a Tailscale Serve change made while a mode change is saving", () =>
342398
Effect.gen(function* () {
343399
const modeWriteStarted = yield* Deferred.make<void>();
@@ -489,6 +545,54 @@ describe("DesktopServerExposure", () => {
489545
},
490546
);
491547

548+
it.effect("reads this backend's environment ID once it answers, then keeps it", () => {
549+
let localReads = 0;
550+
const httpClientLayer = Layer.succeed(
551+
HttpClient.HttpClient,
552+
HttpClient.make((request) =>
553+
Effect.sync(() => {
554+
const local = request.url.startsWith("http://127.0.0.1:4173/");
555+
if (local) localReads += 1;
556+
// The backend is still starting on the first read.
557+
const body =
558+
local && localReads === 1
559+
? new Response("starting", { status: 503 })
560+
: Response.json({ environmentId: "this-desktop" });
561+
return HttpClientResponse.fromWeb(request, body);
562+
}),
563+
),
564+
);
565+
const serveStatus = () =>
566+
withHarness(
567+
tailnetNetworkInterfaces,
568+
Effect.gen(function* () {
569+
const serverExposure = yield* DesktopServerExposure.DesktopServerExposure;
570+
yield* serverExposure.configureFromSettings({ port: 4173 });
571+
yield* serverExposure.setTailscaleServeEnabled({ enabled: true });
572+
const statuses: Array<string> = [];
573+
for (let call = 0; call < 3; call += 1) {
574+
const endpoints = yield* serverExposure.getAdvertisedEndpoints;
575+
statuses.push(
576+
endpoints.find((endpoint) => endpoint.httpBaseUrl.startsWith("https://"))?.status ??
577+
"missing",
578+
);
579+
}
580+
return statuses;
581+
}),
582+
{},
583+
layerMockSpawner(
584+
`{"Self":{"DNSName":"desktop.tail.ts.net.","TailscaleIPs":["100.90.1.2"]}}`,
585+
),
586+
undefined,
587+
undefined,
588+
httpClientLayer,
589+
);
590+
return Effect.gen(function* () {
591+
assert.deepEqual(yield* serveStatus(), ["unavailable", "available", "available"]);
592+
assert.equal(localReads, 2);
593+
});
594+
});
595+
492596
it.effect("preserves explicit Tailscale exposure overrides", () =>
493597
withHarness(
494598
lanNetworkInterfaces,

0 commit comments

Comments
 (0)