Skip to content
Open
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
33 changes: 27 additions & 6 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 26 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from "./logging";
import type { LogMode } from "./logging";

const tailscaledLogPath = path.join(os.homedir(), "tailscaled.log");
const cmdTailscale = "tailscale";
const cmdTailscaleFullPath = "/usr/local/bin/tailscale";
const cmdTailscaled = "tailscaled";
Expand Down Expand Up @@ -770,11 +771,7 @@ async function startTailscaleDaemon(config: TailscaleConfig): Promise<void> {
// Start daemon in background
const daemon = spawn("sudo", ["-E", cmdTailscaled, ...args], {
detached: true,
stdio: [
"ignore",
"ignore",
fs.openSync(path.join(os.homedir(), "tailscaled.log"), "w"),
],
stdio: ["ignore", "ignore", fs.openSync(tailscaledLogPath, "w")],
});

// Store PID for cleaning up daemon process in logout.ts.
Expand Down Expand Up @@ -824,10 +821,33 @@ async function waitForDaemonReady(logMode: LogMode): Promise<void> {
}

throw new Error(
`tailscaled daemon did not become ready within timeout, last error: ${lastErr}`,
`tailscaled daemon did not become ready within timeout, last error: ${lastErr}${tailscaledLogHint()}`,
);
}

// tailscaledLogHint returns the end of tailscaled's log when debug logging
// is enabled, and otherwise a note on how to get it.
function tailscaledLogHint(maxLines = 20): string {
if (!core.isDebug()) {
return "\nRe-run with debug logging enabled to include the tailscaled log in this error.";
}
try {
const lines = fs
.readFileSync(tailscaledLogPath, "utf8")
.split("\n")
.filter((line) => line.trim() !== "");
if (lines.length === 0) return "";
// tailscaled logs proxy URLs, which can carry credentials.
const tail = lines
.slice(-maxLines)
.join("\n")
.replace(/(\w+:\/\/)[^\/\s@]+@/g, "$1REDACTED@");
return `\ntailscaled log (last ${Math.min(lines.length, maxLines)} lines of ${tailscaledLogPath}):\n${tail}`;
} catch {
return "";
}
}

async function connectToTailscale(
config: TailscaleConfig,
runnerOS: string,
Expand Down