openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
78 lines (77 loc) • 3.97 kB
JavaScript
import { _ as resolveSecretInputRef } from "./types.secrets-BmNLLnHp.mjs";
import { n as isRedactedSecretValue } from "./redact-sentinel-Db2p5Put.mjs";
import { n as getTrustedProxyPasswordRedactionWarning, r as isInvalidGatewaySecret } from "./known-weak-gateway-secrets-DrP6ACfl.mjs";
import { r as resolveGatewayAuth } from "./auth-resolve-C6_i-P4T.mjs";
import "./auth-dV1bLOjr.mjs";
import { t as resolveGatewayAuthToken } from "./auth-token-resolution-CUaXbu3r.mjs";
import { t as getSkippedExecRefStaticError } from "./exec-resolution-policy-DTeP4tsd.mjs";
//#region src/flows/doctor-gateway-auth.ts
function buildGatewayTokenSecretRefUnavailableMessage(e) {
if (e.unresolvedRefReason) return `Gateway token SecretRef could not be resolved: ${e.unresolvedRefReason}`;
if (e.ref.source === "exec") {
const t = getSkippedExecRefStaticError({
ref: e.ref,
config: e.cfg
});
if (t) return `Gateway token SecretRef could not be verified: ${t}`;
return "Gateway token SecretRef uses an exec provider and did not resolve.";
}
return "Gateway token is managed via SecretRef and is currently unavailable.";
}
/** Shared auth diagnostics keep doctor's read-only and repair paths on the same policy. */
async function detectGatewayAuthHealth(e) {
if (e.cfg.gateway?.mode === "remote") return [];
const t = resolveGatewayAuth({
authConfig: e.cfg.gateway?.auth,
tailscaleMode: e.cfg.gateway?.tailscale?.mode ?? "off",
env: e.env
});
const n = getTrustedProxyPasswordRedactionWarning(t);
if (n) return [{
checkId: "core/doctor/gateway-auth",
severity: "warning",
message: n,
path: "gateway.auth.password",
fixHint: "Replace or remove the optional password; keep trusted-proxy authentication configured."
}];
if (t.mode !== "token") return [];
const r = resolveSecretInputRef({
value: e.cfg.gateway?.auth?.token,
defaults: e.cfg.secrets?.defaults
}).ref;
const i = r?.source === "exec" && getSkippedExecRefStaticError({
ref: r,
config: e.cfg
});
if (r?.source === "exec" && e.allowExecSecretRefs !== true && !i) return [];
const a = i ? { secretRefConfigured: true } : await resolveGatewayAuthToken({
cfg: e.cfg,
env: e.env ?? process.env,
unresolvedReasonStyle: "detailed",
...r ? { envFallback: "never" } : {}
});
const o = a.unresolvedRefCode === "SECRET_REF_REDACTED_VALUE" || isRedactedSecretValue(a.token) || !r && isRedactedSecretValue(e.cfg.gateway?.auth?.token);
if (a.token && !isInvalidGatewaySecret(a.token) && !o) return [];
if (r) return [{
checkId: "core/doctor/gateway-auth",
severity: o ? "error" : "warning",
...o ? { requirement: "SECRET_REF_REDACTED_VALUE" } : {},
message: buildGatewayTokenSecretRefUnavailableMessage({
cfg: e.cfg,
ref: r,
unresolvedRefReason: isInvalidGatewaySecret(a.token) ? "the resolved token is blank or the literal string undefined/null" : a.unresolvedRefReason
}),
path: "gateway.auth.token",
fixHint: o && r.source === "store" ? `Run \`openclaw doctor --fix\` to regenerate secret store entry "${r.id}", then restart the Gateway and reconnect or re-pair devices with the new token.` : r.source === "exec" ? "Run `openclaw doctor --allow-exec` to verify exec SecretRefs during doctor, or `openclaw secrets audit --allow-exec` to audit all exec SecretRefs." : "Resolve or rotate the external secret source, then rerun doctor."
}];
const s = o || isInvalidGatewaySecret(a.token) || isInvalidGatewaySecret(e.cfg.gateway?.auth?.token);
return [{
checkId: "core/doctor/gateway-auth",
severity: s ? "error" : "warning",
message: o ? "Gateway token is a known redaction sentinel, not a usable secret." : s ? "Gateway token is blank or the literal string undefined/null, not a usable secret." : "Gateway auth is off or missing a token.",
path: "gateway.auth.token",
fixHint: "Run `openclaw doctor --fix --generate-gateway-token` to generate a token, then restart the Gateway."
}];
}
//#endregion
export { detectGatewayAuthHealth as t };