Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions apps/server/src/cli/pair.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,72 @@ describe("t3 pair", () => {
assert.include(String(error), "127.0.0.2");
}).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
);

// regression: #37459 - on Linux without an operator, tailscaled refuses Serve config
// from a normal user, and the CLI must say how to fix it.
it.effect("explains the operator fix when Tailscale denies the Serve config", () =>
Effect.gen(function* () {
const baseDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-pair-remote-"));
yield* persistServerRuntimeState({
path: NodePath.join(baseDir, "userdata", "server-runtime.json"),
state: yield* makePersistedServerRuntimeState({
config: { host: "127.0.0.1", devUrl: undefined },
port: 3773,
}),
});
const spawner = ChildProcessSpawner.make((command) => {
const { args } = command as unknown as { readonly args: ReadonlyArray<string> };
const serve = args[0] === "serve" && args[1] !== "status";
return Effect.succeed(
ChildProcessSpawner.makeHandle({
pid: ChildProcessSpawner.ProcessId(1),
exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(serve ? 1 : 0)),
isRunning: Effect.succeed(false),
kill: () => Effect.void,
unref: Effect.succeed(Effect.void),
stdin: Sink.drain,
stdout: Stream.make(
new TextEncoder().encode(
serve
? ""
: args[0] === "status"
? '{"Self":{"DNSName":"pair-test.tail.ts.net."}}'
: "{}",
),
),
stderr: Stream.make(
new TextEncoder().encode(
serve
? "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"
: "",
),
),
all: Stream.empty,
getInputFd: () => Sink.drain,
getOutputFd: () => Stream.empty,
}),
);
});

const error = yield* provideCliTestLayers(
runCli(["pair", "--base-dir", baseDir, "--tailscale"]).pipe(
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
Effect.provideService(HostProcess.Platform, "linux"),
Effect.provideService(FetchHttpClient.Fetch, async (input) => {
if (String(input) === "http://127.0.0.1:3773/.well-known/t3/environment") {
return Response.json(testDescriptor);
}
assert.equal(String(input), "https://pair-test.tail.ts.net/.well-known/t3/environment");
return new Response(null, { status: 503 });
}),
Effect.flip,
),
);

assert.include(String(error), "sudo tailscale set --operator=$USER");
assert.notInclude(String(error), "by hand to see why");
}).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
);
});

describe("auth scope options", () => {
Expand Down
29 changes: 22 additions & 7 deletions apps/server/src/cli/pair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ export class TailscaleServeFailedError extends Schema.TaggedError<TailscaleServe
}
}

export class TailscaleOperatorRequiredError extends Schema.TaggedError<TailscaleOperatorRequiredError>()(
"TailscaleOperatorRequiredError",
{ cause: Schema.Defect() },
) {
override get message(): string {
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.";
}
}

export class TailscaleServeTargetRefusedError extends Schema.TaggedError<TailscaleServeTargetRefusedError>()(
"TailscaleServeTargetRefusedError",
{ localHost: Schema.String },
Expand Down Expand Up @@ -425,6 +434,7 @@ const resolveTailscalePairingBase = Effect.fn("pair.resolveTailscalePairingBase"
}
// The probe above fails whenever this host cannot reach its own MagicDNS name, so the Serve
// config, not the probe, decides whether the port is free.
const platform = yield* HostProcess.Platform;
const holder = yield* readTailscaleServeRootHolder(input.servePort, {
host: (localTarget.localHost ?? "127.0.0.1").replace(/^\[|\]$/gu, ""),
port: localTarget.localPort,
Expand All @@ -437,13 +447,18 @@ const resolveTailscalePairingBase = Effect.fn("pair.resolveTailscalePairingBase"
servePort: input.servePort,
...(localTarget.localHost !== undefined ? { localHost: localTarget.localHost } : {}),
}).pipe(
Effect.mapError((cause) =>
cause._tag === "TailscaleCommandExitError" &&
cause.stderrDiagnostic === "unsupported-target" &&
localTarget.localHost !== undefined
? new TailscaleServeTargetRefusedError({ localHost: localTarget.localHost })
: new TailscaleServeFailedError({ servePort: input.servePort, cause }),
),
Effect.mapError((cause) => {
const diagnostic =
cause._tag === "TailscaleCommandExitError" ? cause.stderrDiagnostic : undefined;
if (diagnostic === "unsupported-target" && localTarget.localHost !== undefined) {
return new TailscaleServeTargetRefusedError({ localHost: localTarget.localHost });
}
// Only Linux tailscaled has an operator; elsewhere a denial needs another fix.
if (diagnostic === "permission-denied" && platform === "linux") {
return new TailscaleOperatorRequiredError({ cause });
}
return new TailscaleServeFailedError({ servePort: input.servePort, cause });
}),
);
notes.push(
`Tailscale Serve now maps ${baseUrl} to this server and persists across restarts. Remove it with \`tailscale serve --https=${String(input.servePort)} --set-path=/ off\`.`,
Expand Down
Loading