@devries-cameron20 / t3code Mirror · read-only / commits / ddb7fb3f50
Fork 0

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, 09:45 UTC

fix(cli): t3 pair --tailscale names the operator fix when Tailscale denies Serve (#37466)

Julius Marminge committed Nov 15, 2026 at 19:36 UTC ddb7fb3f50c5c8ddb6d495e3cee04ac677ca589e
2 files changed +88 -7
apps/server/src/cli/pair.test.ts
+66
@@ -623,6 +623,72 @@ describe("t3 pair", () => {
623 assert.include(String(error), "127.0.0.2");
624 }).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
625 );
626 +
627 + // regression: #37459 - on Linux without an operator, tailscaled refuses Serve config
628 + // from a normal user, and the CLI must say how to fix it.
629 + it.effect("explains the operator fix when Tailscale denies the Serve config", () =>
630 + Effect.gen(function* () {
631 + const baseDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-pair-remote-"));
632 + yield* persistServerRuntimeState({
633 + path: NodePath.join(baseDir, "userdata", "server-runtime.json"),
634 + state: yield* makePersistedServerRuntimeState({
635 + config: { host: "127.0.0.1", devUrl: undefined },
636 + port: 3773,
637 + }),
638 + });
639 + const spawner = ChildProcessSpawner.make((command) => {
640 + const { args } = command as unknown as { readonly args: ReadonlyArray<string> };
641 + const serve = args[0] === "serve" && args[1] !== "status";
642 + return Effect.succeed(
643 + ChildProcessSpawner.makeHandle({
644 + pid: ChildProcessSpawner.ProcessId(1),
645 + exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(serve ? 1 : 0)),
646 + isRunning: Effect.succeed(false),
647 + kill: () => Effect.void,
648 + unref: Effect.succeed(Effect.void),
649 + stdin: Sink.drain,
650 + stdout: Stream.make(
651 + new TextEncoder().encode(
652 + serve
653 + ? ""
654 + : args[0] === "status"
655 + ? '{"Self":{"DNSName":"pair-test.tail.ts.net."}}'
656 + : "{}",
657 + ),
658 + ),
659 + stderr: Stream.make(
660 + new TextEncoder().encode(
661 + serve
662 + ? "sending serve config: Access denied: serve config denied\n\nUse 'sudo tailscale serve --https=443 --bg http://127.0.0.1:3773'.\nTo not require root, use 'sudo tailscale set --operator=$USER' once.\n"
663 + : "",
664 + ),
665 + ),
666 + all: Stream.empty,
667 + getInputFd: () => Sink.drain,
668 + getOutputFd: () => Stream.empty,
669 + }),
670 + );
671 + });
672 +
673 + const error = yield* provideCliTestLayers(
674 + runCli(["pair", "--base-dir", baseDir, "--tailscale"]).pipe(
675 + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
676 + Effect.provideService(HostProcess.Platform, "linux"),
677 + Effect.provideService(FetchHttpClient.Fetch, async (input) => {
678 + if (String(input) === "http://127.0.0.1:3773/.well-known/t3/environment") {
679 + return Response.json(testDescriptor);
680 + }
681 + assert.equal(String(input), "https://pair-test.tail.ts.net/.well-known/t3/environment");
682 + return new Response(null, { status: 503 });
683 + }),
684 + Effect.flip,
685 + ),
686 + );
687 +
688 + assert.include(String(error), "sudo tailscale set --operator=$USER");
689 + assert.notInclude(String(error), "by hand to see why");
690 + }).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
691 + );
692 });
693
694 describe("auth scope options", () => {
apps/server/src/cli/pair.ts
+22 -7
@@ -143,6 +143,15 @@ export class TailscaleServeFailedError extends Schema.TaggedError<TailscaleServe
143 }
144 }
145
146 +export class TailscaleOperatorRequiredError extends Schema.TaggedError<TailscaleOperatorRequiredError>()(
147 + "TailscaleOperatorRequiredError",
148 + { cause: Schema.Defect() },
149 +) {
150 + override get message(): string {
151 + return "Tailscale refused the Serve config because this user is not its operator. Run `sudo tailscale set --operator=$USER` once, then run this command again.";
152 + }
153 +}
154 +
155 export class TailscaleServeTargetRefusedError extends Schema.TaggedError<TailscaleServeTargetRefusedError>()(
156 "TailscaleServeTargetRefusedError",
157 { localHost: Schema.String },
@@ -425,6 +434,7 @@ const resolveTailscalePairingBase = Effect.fn("pair.resolveTailscalePairingBase"
434 }
435 // The probe above fails whenever this host cannot reach its own MagicDNS name, so the Serve
436 // config, not the probe, decides whether the port is free.
437 + const platform = yield* HostProcess.Platform;
438 const holder = yield* readTailscaleServeRootHolder(input.servePort, {
439 host: (localTarget.localHost ?? "127.0.0.1").replace(/^\[|\]$/gu, ""),
440 port: localTarget.localPort,
@@ -437,13 +447,18 @@ const resolveTailscalePairingBase = Effect.fn("pair.resolveTailscalePairingBase"
447 servePort: input.servePort,
448 ...(localTarget.localHost !== undefined ? { localHost: localTarget.localHost } : {}),
449 }).pipe(
440 - Effect.mapError((cause) =>
441 - cause._tag === "TailscaleCommandExitError" &&
442 - cause.stderrDiagnostic === "unsupported-target" &&
443 - localTarget.localHost !== undefined
444 - ? new TailscaleServeTargetRefusedError({ localHost: localTarget.localHost })
445 - : new TailscaleServeFailedError({ servePort: input.servePort, cause }),
446 - ),
450 + Effect.mapError((cause) => {
451 + const diagnostic =
452 + cause._tag === "TailscaleCommandExitError" ? cause.stderrDiagnostic : undefined;
453 + if (diagnostic === "unsupported-target" && localTarget.localHost !== undefined) {
454 + return new TailscaleServeTargetRefusedError({ localHost: localTarget.localHost });
455 + }
456 + // Only Linux tailscaled has an operator; elsewhere a denial needs another fix.
457 + if (diagnostic === "permission-denied" && platform === "linux") {
458 + return new TailscaleOperatorRequiredError({ cause });
459 + }
460 + return new TailscaleServeFailedError({ servePort: input.servePort, cause });
461 + }),
462 );
463 notes.push(
464 `Tailscale Serve now maps ${baseUrl} to this server and persists across restarts. Remove it with \`tailscale serve --https=${String(input.servePort)} --set-path=/ off\`.`,