fix: require gateway auth by default
This commit is contained in:
@@ -249,7 +249,7 @@ describe("gateway-cli coverage", () => {
|
||||
programInvalidPort.exitOverride();
|
||||
registerGatewayCli(programInvalidPort);
|
||||
await expect(
|
||||
programInvalidPort.parseAsync(["gateway", "--port", "0"], {
|
||||
programInvalidPort.parseAsync(["gateway", "--port", "0", "--token", "test-token"], {
|
||||
from: "user",
|
||||
}),
|
||||
).rejects.toThrow("__exit__:1");
|
||||
@@ -263,7 +263,7 @@ describe("gateway-cli coverage", () => {
|
||||
registerGatewayCli(programForceFail);
|
||||
await expect(
|
||||
programForceFail.parseAsync(
|
||||
["gateway", "--port", "18789", "--force", "--allow-unconfigured"],
|
||||
["gateway", "--port", "18789", "--token", "test-token", "--force", "--allow-unconfigured"],
|
||||
{ from: "user" },
|
||||
),
|
||||
).rejects.toThrow("__exit__:1");
|
||||
@@ -276,9 +276,12 @@ describe("gateway-cli coverage", () => {
|
||||
const beforeSigterm = new Set(process.listeners("SIGTERM"));
|
||||
const beforeSigint = new Set(process.listeners("SIGINT"));
|
||||
await expect(
|
||||
programStartFail.parseAsync(["gateway", "--port", "18789", "--allow-unconfigured"], {
|
||||
from: "user",
|
||||
}),
|
||||
programStartFail.parseAsync(
|
||||
["gateway", "--port", "18789", "--token", "test-token", "--allow-unconfigured"],
|
||||
{
|
||||
from: "user",
|
||||
},
|
||||
),
|
||||
).rejects.toThrow("__exit__:1");
|
||||
for (const listener of process.listeners("SIGTERM")) {
|
||||
if (!beforeSigterm.has(listener)) process.removeListener("SIGTERM", listener);
|
||||
@@ -304,7 +307,7 @@ describe("gateway-cli coverage", () => {
|
||||
registerGatewayCli(program);
|
||||
|
||||
await expect(
|
||||
program.parseAsync(["gateway", "--allow-unconfigured"], {
|
||||
program.parseAsync(["gateway", "--token", "test-token", "--allow-unconfigured"], {
|
||||
from: "user",
|
||||
}),
|
||||
).rejects.toThrow("__exit__:1");
|
||||
@@ -327,7 +330,7 @@ describe("gateway-cli coverage", () => {
|
||||
|
||||
startGatewayServer.mockRejectedValueOnce(new Error("nope"));
|
||||
await expect(
|
||||
program.parseAsync(["gateway", "--allow-unconfigured"], {
|
||||
program.parseAsync(["gateway", "--token", "test-token", "--allow-unconfigured"], {
|
||||
from: "user",
|
||||
}),
|
||||
).rejects.toThrow("__exit__:1");
|
||||
|
||||
@@ -203,6 +203,10 @@ async function runGatewayCommand(opts: GatewayRunOpts) {
|
||||
const resolvedAuthMode = resolvedAuth.mode;
|
||||
const tokenValue = resolvedAuth.token;
|
||||
const passwordValue = resolvedAuth.password;
|
||||
const hasToken = typeof tokenValue === "string" && tokenValue.trim().length > 0;
|
||||
const hasPassword = typeof passwordValue === "string" && passwordValue.trim().length > 0;
|
||||
const hasSharedSecret =
|
||||
(resolvedAuthMode === "token" && hasToken) || (resolvedAuthMode === "password" && hasPassword);
|
||||
const authHints: string[] = [];
|
||||
if (miskeys.hasGatewayToken) {
|
||||
authHints.push('Found "gateway.token" in config. Use "gateway.auth.token" instead.');
|
||||
@@ -212,7 +216,7 @@ async function runGatewayCommand(opts: GatewayRunOpts) {
|
||||
'"gateway.remote.token" is for remote CLI calls; it does not enable local gateway auth.',
|
||||
);
|
||||
}
|
||||
if (resolvedAuthMode === "token" && !tokenValue) {
|
||||
if (resolvedAuthMode === "token" && !hasToken && !resolvedAuth.allowTailscale) {
|
||||
defaultRuntime.error(
|
||||
[
|
||||
"Gateway auth is set to token, but no token is configured.",
|
||||
@@ -225,7 +229,7 @@ async function runGatewayCommand(opts: GatewayRunOpts) {
|
||||
defaultRuntime.exit(1);
|
||||
return;
|
||||
}
|
||||
if (resolvedAuthMode === "password" && !passwordValue) {
|
||||
if (resolvedAuthMode === "password" && !hasPassword) {
|
||||
defaultRuntime.error(
|
||||
[
|
||||
"Gateway auth is set to password, but no password is configured.",
|
||||
@@ -238,11 +242,11 @@ async function runGatewayCommand(opts: GatewayRunOpts) {
|
||||
defaultRuntime.exit(1);
|
||||
return;
|
||||
}
|
||||
if (bind !== "loopback" && resolvedAuthMode === "none") {
|
||||
if (bind !== "loopback" && !hasSharedSecret) {
|
||||
defaultRuntime.error(
|
||||
[
|
||||
`Refusing to bind gateway to ${bind} without auth.`,
|
||||
"Set gateway.auth.token (or CLAWDBOT_GATEWAY_TOKEN) or pass --token.",
|
||||
"Set gateway.auth.token/password (or CLAWDBOT_GATEWAY_TOKEN/CLAWDBOT_GATEWAY_PASSWORD) or pass --token/--password.",
|
||||
...authHints,
|
||||
]
|
||||
.filter(Boolean)
|
||||
|
||||
Reference in New Issue
Block a user