fix(gateway): explain provider-object password bootstrap errors (#39230, thanks @ademczuk)

Co-authored-by: ademczuk <andrew.demczuk@gmail.com>
This commit is contained in:
Peter Steinberger
2026-03-07 22:44:11 +00:00
parent e45d62ba26
commit ab704b7aca
4 changed files with 33 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
import { describe, expect, it, vi } from "vitest";
import type { AuthRateLimiter } from "./auth-rate-limit.js";
import {
assertGatewayAuthConfigured,
authorizeGatewayConnect,
authorizeHttpGatewayConnect,
authorizeWsControlUiGatewayConnect,
@@ -367,7 +368,6 @@ describe("gateway auth", () => {
expect(limiter.check).toHaveBeenCalledWith(undefined, "custom-scope");
expect(limiter.recordFailure).toHaveBeenCalledWith(undefined, "custom-scope");
});
it("does not record rate-limit failure for missing token (misconfigured client, not brute-force)", async () => {
const limiter = createLimiterSpy();
const res = await authorizeGatewayConnect({
@@ -419,6 +419,27 @@ describe("gateway auth", () => {
expect(res.reason).toBe("password_mismatch");
expect(limiter.recordFailure).toHaveBeenCalled();
});
it("throws specific error when password is a provider reference object", () => {
const auth = resolveGatewayAuth({
authConfig: {
mode: "password",
password: { source: "exec", provider: "op", id: "pw" } as never,
},
});
expect(() =>
assertGatewayAuthConfigured(auth, {
mode: "password",
password: { source: "exec", provider: "op", id: "pw" } as never,
}),
).toThrow(/provider reference object/);
});
it("throws generic error when password mode has no password at all", () => {
const auth = resolveGatewayAuth({ authConfig: { mode: "password" } });
expect(() => assertGatewayAuthConfigured(auth, { mode: "password" })).toThrow(
"gateway auth mode is password, but no password was configured",
);
});
});
describe("trusted-proxy auth", () => {

View File

@@ -291,7 +291,10 @@ export function resolveGatewayAuth(params: {
};
}
export function assertGatewayAuthConfigured(auth: ResolvedGatewayAuth): void {
export function assertGatewayAuthConfigured(
auth: ResolvedGatewayAuth,
rawAuthConfig?: GatewayAuthConfig | null,
): void {
if (auth.mode === "token" && !auth.token) {
if (auth.allowTailscale) {
return;
@@ -301,6 +304,11 @@ export function assertGatewayAuthConfigured(auth: ResolvedGatewayAuth): void {
);
}
if (auth.mode === "password" && !auth.password) {
if (rawAuthConfig?.password != null && typeof rawAuthConfig.password !== "string") {
throw new Error(
"gateway auth mode is password, but gateway.auth.password contains a provider reference object instead of a resolved string — bootstrap secrets (gateway.auth.password) must be plaintext strings or set via the OPENCLAW_GATEWAY_PASSWORD environment variable because the secrets provider system has not initialised yet at gateway startup",
);
}
throw new Error("gateway auth mode is password, but no password was configured");
}
if (auth.mode === "trusted-proxy") {

View File

@@ -121,7 +121,7 @@ export async function resolveGatewayRuntimeConfig(params: {
const dangerouslyAllowHostHeaderOriginFallback =
params.cfg.gateway?.controlUi?.dangerouslyAllowHostHeaderOriginFallback === true;
assertGatewayAuthConfigured(resolvedAuth);
assertGatewayAuthConfigured(resolvedAuth, params.cfg.gateway?.auth);
if (tailscaleMode === "funnel" && authMode !== "password") {
throw new Error(
"tailscale funnel requires gateway auth mode=password (set gateway.auth.password or OPENCLAW_GATEWAY_PASSWORD)",