Skip to content

Commit 7ecdef6

Browse files
authored
fix: prefer Crabbox inspect SSH host (#120611)
1 parent 18dd70c commit 7ecdef6

2 files changed

Lines changed: 46 additions & 5 deletions

File tree

‎scripts/e2e/telegram-user-crabbox-proof.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type CrabboxInspect = {
3838
host?: string;
3939
id?: string;
4040
slug?: string;
41+
sshHost?: string;
4142
sshKey?: string;
4243
sshPort?: string;
4344
sshUser?: string;
@@ -2035,7 +2036,8 @@ async function inspectCrabbox(opts: Options, root: string, leaseId: string) {
20352036
}
20362037

20372038
function sshArgs(inspect: CrabboxInspect) {
2038-
if (!inspect.host || !inspect.sshKey || !inspect.sshUser) {
2039+
const sshHost = inspect.sshHost || inspect.host;
2040+
if (!sshHost || !inspect.sshKey || !inspect.sshUser) {
20392041
throw new Error("Crabbox inspect output is missing SSH details.");
20402042
}
20412043
return {
@@ -2067,7 +2069,7 @@ function sshArgs(inspect: CrabboxInspect) {
20672069
"-o",
20682070
"ConnectTimeout=15",
20692071
],
2070-
target: `${inspect.sshUser}@${inspect.host}`,
2072+
target: `${inspect.sshUser}@${sshHost}`,
20712073
};
20722074
}
20732075

‎test/scripts/telegram-user-crabbox-proof.test.ts‎

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ describe("telegram user Crabbox proof log polling", () => {
502502
gatewayPort: 19042,
503503
inspect: {
504504
host: "proof.example",
505+
sshHost: "",
505506
sshKey: "/tmp/proof-key",
506507
sshPort: "2222",
507508
sshUser: "proof",
@@ -519,9 +520,9 @@ describe("telegram user Crabbox proof log polling", () => {
519520
env,
520521
});
521522
expect(allowed.status).toBe(0);
522-
expect(JSON.parse(fs.readFileSync(argvPath, "utf8"))).toContain(
523-
"'tailscale' 'funnel' '--bg' '--yes' '19042'",
524-
);
523+
const fallbackArgv = JSON.parse(fs.readFileSync(argvPath, "utf8"));
524+
expect(fallbackArgv).toContain("[email protected]");
525+
expect(fallbackArgv).toContain("'tailscale' 'funnel' '--bg' '--yes' '19042'");
525526

526527
const rejected = spawnSync(proxyPath, ["serve", "--bg", "19042"], {
527528
encoding: "utf8",
@@ -531,6 +532,44 @@ describe("telegram user Crabbox proof log polling", () => {
531532
expect(rejected.stderr).toContain("unsupported proof Tailscale command");
532533
});
533534

535+
posixIt("prefers the inspect SSH host over the public host", () => {
536+
const root = makeTempDir();
537+
const sshPath = path.join(root, "ssh");
538+
const argvPath = path.join(root, "ssh-argv.json");
539+
const proxyPath = path.join(root, "tailscale");
540+
writeExecutable(
541+
sshPath,
542+
`#!/usr/bin/env node\nimport fs from "node:fs";\nfs.writeFileSync(process.env.ARGV_PATH, JSON.stringify(process.argv.slice(2)));\n`,
543+
);
544+
writeExecutable(
545+
proxyPath,
546+
renderTailscaleSshProxy({
547+
gatewayPort: 19042,
548+
inspect: {
549+
host: "public.example",
550+
sshHost: "ssh.example",
551+
sshKey: "/tmp/proof-key",
552+
sshPort: "2222",
553+
sshUser: "proof",
554+
},
555+
}),
556+
);
557+
558+
const result = spawnSync(proxyPath, ["status", "--json"], {
559+
encoding: "utf8",
560+
env: {
561+
...process.env,
562+
ARGV_PATH: argvPath,
563+
PATH: `${root}${path.delimiter}${process.env.PATH ?? ""}`,
564+
},
565+
});
566+
567+
expect(result.status).toBe(0);
568+
const argv = JSON.parse(fs.readFileSync(argvPath, "utf8"));
569+
expect(argv).toContain("[email protected]");
570+
expect(argv).not.toContain("[email protected]");
571+
});
572+
534573
it("reads only the requested log tail", () => {
535574
const logPath = path.join(makeTempDir(), "gateway.log");
536575
fs.writeFileSync(logPath, `${"old\n".repeat(2000)}ready\n`, "utf8");

0 commit comments

Comments
 (0)