mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 10:01:11 +00:00
Gateway: add SecretRef support for gateway.auth.token with auth-mode guardrails (#35094)
This commit is contained in:
@@ -4,13 +4,13 @@ import { formatCliCommand } from "../cli/command-format.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { readConfigFileSnapshot, resolveGatewayPort, writeConfigFile } from "../config/config.js";
|
||||
import { logConfigUpdated } from "../config/logging.js";
|
||||
import { normalizeSecretInputString } from "../config/types.secrets.js";
|
||||
import { ensureControlUiAssetsBuilt } from "../infra/control-ui-assets.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import { defaultRuntime } from "../runtime.js";
|
||||
import { note } from "../terminal/note.js";
|
||||
import { resolveUserPath } from "../utils.js";
|
||||
import { createClackPrompter } from "../wizard/clack-prompter.js";
|
||||
import { resolveOnboardingSecretInputString } from "../wizard/onboarding.secret-input.js";
|
||||
import { WizardCancelledError } from "../wizard/prompts.js";
|
||||
import { removeChannelConfigWizard } from "./configure.channels.js";
|
||||
import { maybeInstallDaemon } from "./configure.daemon.js";
|
||||
@@ -48,6 +48,23 @@ import { setupSkills } from "./onboard-skills.js";
|
||||
|
||||
type ConfigureSectionChoice = WizardSection | "__continue";
|
||||
|
||||
async function resolveGatewaySecretInputForWizard(params: {
|
||||
cfg: OpenClawConfig;
|
||||
value: unknown;
|
||||
path: string;
|
||||
}): Promise<string | undefined> {
|
||||
try {
|
||||
return await resolveOnboardingSecretInputString({
|
||||
config: params.cfg,
|
||||
value: params.value,
|
||||
path: params.path,
|
||||
env: process.env,
|
||||
});
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
async function runGatewayHealthCheck(params: {
|
||||
cfg: OpenClawConfig;
|
||||
runtime: RuntimeEnv;
|
||||
@@ -61,10 +78,22 @@ async function runGatewayHealthCheck(params: {
|
||||
});
|
||||
const remoteUrl = params.cfg.gateway?.remote?.url?.trim();
|
||||
const wsUrl = params.cfg.gateway?.mode === "remote" && remoteUrl ? remoteUrl : localLinks.wsUrl;
|
||||
const token = params.cfg.gateway?.auth?.token ?? process.env.OPENCLAW_GATEWAY_TOKEN;
|
||||
const configuredToken = await resolveGatewaySecretInputForWizard({
|
||||
cfg: params.cfg,
|
||||
value: params.cfg.gateway?.auth?.token,
|
||||
path: "gateway.auth.token",
|
||||
});
|
||||
const configuredPassword = await resolveGatewaySecretInputForWizard({
|
||||
cfg: params.cfg,
|
||||
value: params.cfg.gateway?.auth?.password,
|
||||
path: "gateway.auth.password",
|
||||
});
|
||||
const token =
|
||||
process.env.OPENCLAW_GATEWAY_TOKEN ?? process.env.CLAWDBOT_GATEWAY_TOKEN ?? configuredToken;
|
||||
const password =
|
||||
normalizeSecretInputString(params.cfg.gateway?.auth?.password) ??
|
||||
process.env.OPENCLAW_GATEWAY_PASSWORD;
|
||||
process.env.OPENCLAW_GATEWAY_PASSWORD ??
|
||||
process.env.CLAWDBOT_GATEWAY_PASSWORD ??
|
||||
configuredPassword;
|
||||
|
||||
await waitForGatewayReachable({
|
||||
url: wsUrl,
|
||||
@@ -305,18 +334,37 @@ export async function runConfigureWizard(
|
||||
}
|
||||
|
||||
const localUrl = "ws://127.0.0.1:18789";
|
||||
const baseLocalProbeToken = await resolveGatewaySecretInputForWizard({
|
||||
cfg: baseConfig,
|
||||
value: baseConfig.gateway?.auth?.token,
|
||||
path: "gateway.auth.token",
|
||||
});
|
||||
const baseLocalProbePassword = await resolveGatewaySecretInputForWizard({
|
||||
cfg: baseConfig,
|
||||
value: baseConfig.gateway?.auth?.password,
|
||||
path: "gateway.auth.password",
|
||||
});
|
||||
const localProbe = await probeGatewayReachable({
|
||||
url: localUrl,
|
||||
token: baseConfig.gateway?.auth?.token ?? process.env.OPENCLAW_GATEWAY_TOKEN,
|
||||
token:
|
||||
process.env.OPENCLAW_GATEWAY_TOKEN ??
|
||||
process.env.CLAWDBOT_GATEWAY_TOKEN ??
|
||||
baseLocalProbeToken,
|
||||
password:
|
||||
normalizeSecretInputString(baseConfig.gateway?.auth?.password) ??
|
||||
process.env.OPENCLAW_GATEWAY_PASSWORD,
|
||||
process.env.OPENCLAW_GATEWAY_PASSWORD ??
|
||||
process.env.CLAWDBOT_GATEWAY_PASSWORD ??
|
||||
baseLocalProbePassword,
|
||||
});
|
||||
const remoteUrl = baseConfig.gateway?.remote?.url?.trim() ?? "";
|
||||
const baseRemoteProbeToken = await resolveGatewaySecretInputForWizard({
|
||||
cfg: baseConfig,
|
||||
value: baseConfig.gateway?.remote?.token,
|
||||
path: "gateway.remote.token",
|
||||
});
|
||||
const remoteProbe = remoteUrl
|
||||
? await probeGatewayReachable({
|
||||
url: remoteUrl,
|
||||
token: normalizeSecretInputString(baseConfig.gateway?.remote?.token),
|
||||
token: baseRemoteProbeToken,
|
||||
})
|
||||
: null;
|
||||
|
||||
@@ -374,10 +422,6 @@ export async function runConfigureWizard(
|
||||
baseConfig.agents?.defaults?.workspace ??
|
||||
DEFAULT_WORKSPACE;
|
||||
let gatewayPort = resolveGatewayPort(baseConfig);
|
||||
let gatewayToken: string | undefined =
|
||||
normalizeSecretInputString(nextConfig.gateway?.auth?.token) ??
|
||||
normalizeSecretInputString(baseConfig.gateway?.auth?.token) ??
|
||||
process.env.OPENCLAW_GATEWAY_TOKEN;
|
||||
|
||||
const persistConfig = async () => {
|
||||
nextConfig = applyWizardMetadata(nextConfig, {
|
||||
@@ -486,7 +530,6 @@ export async function runConfigureWizard(
|
||||
const gateway = await promptGatewayConfig(nextConfig, runtime);
|
||||
nextConfig = gateway.config;
|
||||
gatewayPort = gateway.port;
|
||||
gatewayToken = gateway.token;
|
||||
}
|
||||
|
||||
if (selected.includes("channels")) {
|
||||
@@ -505,7 +548,7 @@ export async function runConfigureWizard(
|
||||
await promptDaemonPort();
|
||||
}
|
||||
|
||||
await maybeInstallDaemon({ runtime, port: gatewayPort, gatewayToken });
|
||||
await maybeInstallDaemon({ runtime, port: gatewayPort });
|
||||
}
|
||||
|
||||
if (selected.includes("health")) {
|
||||
@@ -541,7 +584,6 @@ export async function runConfigureWizard(
|
||||
const gateway = await promptGatewayConfig(nextConfig, runtime);
|
||||
nextConfig = gateway.config;
|
||||
gatewayPort = gateway.port;
|
||||
gatewayToken = gateway.token;
|
||||
didConfigureGateway = true;
|
||||
await persistConfig();
|
||||
}
|
||||
@@ -564,7 +606,6 @@ export async function runConfigureWizard(
|
||||
await maybeInstallDaemon({
|
||||
runtime,
|
||||
port: gatewayPort,
|
||||
gatewayToken,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -598,12 +639,29 @@ export async function runConfigureWizard(
|
||||
});
|
||||
// Try both new and old passwords since gateway may still have old config.
|
||||
const newPassword =
|
||||
normalizeSecretInputString(nextConfig.gateway?.auth?.password) ??
|
||||
process.env.OPENCLAW_GATEWAY_PASSWORD;
|
||||
process.env.OPENCLAW_GATEWAY_PASSWORD ??
|
||||
process.env.CLAWDBOT_GATEWAY_PASSWORD ??
|
||||
(await resolveGatewaySecretInputForWizard({
|
||||
cfg: nextConfig,
|
||||
value: nextConfig.gateway?.auth?.password,
|
||||
path: "gateway.auth.password",
|
||||
}));
|
||||
const oldPassword =
|
||||
normalizeSecretInputString(baseConfig.gateway?.auth?.password) ??
|
||||
process.env.OPENCLAW_GATEWAY_PASSWORD;
|
||||
const token = nextConfig.gateway?.auth?.token ?? process.env.OPENCLAW_GATEWAY_TOKEN;
|
||||
process.env.OPENCLAW_GATEWAY_PASSWORD ??
|
||||
process.env.CLAWDBOT_GATEWAY_PASSWORD ??
|
||||
(await resolveGatewaySecretInputForWizard({
|
||||
cfg: baseConfig,
|
||||
value: baseConfig.gateway?.auth?.password,
|
||||
path: "gateway.auth.password",
|
||||
}));
|
||||
const token =
|
||||
process.env.OPENCLAW_GATEWAY_TOKEN ??
|
||||
process.env.CLAWDBOT_GATEWAY_TOKEN ??
|
||||
(await resolveGatewaySecretInputForWizard({
|
||||
cfg: nextConfig,
|
||||
value: nextConfig.gateway?.auth?.token,
|
||||
path: "gateway.auth.token",
|
||||
}));
|
||||
|
||||
let gatewayProbe = await probeGatewayReachable({
|
||||
url: links.wsUrl,
|
||||
|
||||
Reference in New Issue
Block a user