mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-29 08:06:46 +00:00
fix: redact secrets in instance settings reads unless explicitly revealed (#12682)
* fix: redact secrets in instance settings reads unless explicitly revealed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(cli): compare redacted remote settings against unchanged local secrets Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: redact nuget, maven, cargo, webhook and otel header credentials too Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(cli): mask get-config secrets from servers that do not redact Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(cli): refuse a masked get-config export from a server that cannot restore it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(cli): word the get-config prompt for servers that do not redact Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c689d74505
commit
cc855e6fd9
@@ -54,6 +54,7 @@ export async function pull(opts: GlobalOptions) {
|
||||
if (hubBaseUrl !== DEFAULT_HUB_BASE_URL) {
|
||||
const hubSecret = (await wmill.getGlobal({
|
||||
key: "hub_api_secret",
|
||||
dangerouslyRevealSecrets: true,
|
||||
})) as string | undefined;
|
||||
log.info("Fetching resource types from private hub: " + hubBaseUrl);
|
||||
if (hubSecret) {
|
||||
|
||||
@@ -38,6 +38,7 @@ import {
|
||||
pullInstanceSettings,
|
||||
pushInstanceConfigs,
|
||||
pushInstanceSettings,
|
||||
REDACTED_SECRET_PREFIX,
|
||||
type SimplifiedSettings,
|
||||
} from "../../core/settings.ts";
|
||||
import { deepEqual, readTextFile } from "../../utils/utils.ts";
|
||||
@@ -183,6 +184,7 @@ export type InstanceSyncOptions = {
|
||||
yes?: boolean;
|
||||
prefix?: string;
|
||||
prefixSettings?: boolean;
|
||||
showSecrets?: boolean;
|
||||
};
|
||||
|
||||
export async function pickInstance(
|
||||
@@ -667,25 +669,42 @@ export async function getActiveInstance(opts: {
|
||||
|
||||
async function getConfig(opts: InstanceSyncOptions & { outputFile?: string; showSecrets?: boolean }) {
|
||||
await pickInstance(opts, false);
|
||||
const config = await wmill.getInstanceConfig() as any;
|
||||
|
||||
// In interactive mode, mask secrets by default and prompt
|
||||
const hasSecrets = config?.global_settings?.license_key || config?.global_settings?.jwt_secret;
|
||||
let showSecrets = opts.showSecrets ?? false;
|
||||
if (!showSecrets && hasSecrets && process.stdout.isTTY && !opts.outputFile) {
|
||||
log.warn("Config contains sensitive fields (license_key, jwt_secret). They are masked by default.");
|
||||
log.warn("Use --show-secrets to include them, or press Y to show them now.");
|
||||
showSecrets = await Confirm.prompt({ message: "Show secrets?", default: false });
|
||||
} else if (!process.stdout.isTTY || opts.outputFile) {
|
||||
// Non-interactive or writing to file: always include secrets
|
||||
showSecrets = true;
|
||||
}
|
||||
let config = await wmill.getInstanceConfig({ dangerouslyRevealSecrets: showSecrets }) as any;
|
||||
|
||||
if (!showSecrets && config?.global_settings) {
|
||||
const settings = config?.global_settings ?? {};
|
||||
const serverRedacted = JSON.stringify(settings).includes(REDACTED_SECRET_PREFIX);
|
||||
// A server without redaction ignores the parameter and returns its secrets in clear.
|
||||
const clearFromOlderServer =
|
||||
!showSecrets && !serverRedacted && Boolean(settings.license_key || settings.jwt_secret);
|
||||
const interactive = process.stdout.isTTY && !opts.outputFile;
|
||||
// Masking such an export is only safe on screen: applied back, that server would store the mask.
|
||||
if (clearFromOlderServer && !interactive) {
|
||||
throw new Error(
|
||||
"This server does not redact secrets, so a redacted export would overwrite them when applied back. Pass --show-secrets to export them."
|
||||
);
|
||||
}
|
||||
const redacted = !showSecrets && (serverRedacted || clearFromOlderServer);
|
||||
if (redacted && interactive) {
|
||||
log.warn(
|
||||
clearFromOlderServer
|
||||
? "Config contains sensitive fields (license_key, jwt_secret). They are masked by default. Use --show-secrets to include them, or press Y to show them now."
|
||||
: "Secrets (license key, passwords, tokens) are redacted. Use --show-secrets to include them, or press Y to show them now."
|
||||
);
|
||||
showSecrets = await Confirm.prompt({ message: "Show secrets?", default: false });
|
||||
if (showSecrets) {
|
||||
config = await wmill.getInstanceConfig({ dangerouslyRevealSecrets: true }) as any;
|
||||
}
|
||||
} else if (redacted) {
|
||||
log.infoStderr(
|
||||
"Secrets are redacted: pass --show-secrets to include them. Pushing this export back keeps the stored secrets, but it cannot set up another instance."
|
||||
);
|
||||
}
|
||||
if (!showSecrets && clearFromOlderServer) {
|
||||
if (config.global_settings.license_key) config.global_settings.license_key = "***";
|
||||
if (config.global_settings.jwt_secret) config.global_settings.jwt_secret = "***";
|
||||
}
|
||||
if (config?.global_settings && !config.global_settings.jwt_secret) {
|
||||
if (showSecrets && config?.global_settings && !config.global_settings.jwt_secret) {
|
||||
log.infoStderr(
|
||||
"jwt_secret, rsa_keys and the instance database secrets are not part of the export: the server withholds them (EXPORT_SERVER_SECRETS=false). This export cannot fully restore or migrate the instance."
|
||||
);
|
||||
@@ -778,6 +797,10 @@ const command = new Command()
|
||||
.option("--dry-run", "Perform a dry run without making changes")
|
||||
.option("--skip-users", "Skip pulling users")
|
||||
.option("--skip-settings", "Skip pulling settings")
|
||||
.option(
|
||||
"--show-secrets",
|
||||
"Pull secrets (license key, passwords, tokens) in clear instead of redacted",
|
||||
)
|
||||
.option("--skip-configs", "Skip pulling configs (worker groups)")
|
||||
.option("--skip-groups", "Skip pulling instance groups")
|
||||
.option("--include-workspaces", "Also pull workspaces")
|
||||
@@ -826,7 +849,7 @@ const command = new Command()
|
||||
.command("get-config")
|
||||
.description("Dump the current instance config (global settings + worker configs) as YAML")
|
||||
.option("-o, --output-file <file:string>", "Write YAML to a file instead of stdout")
|
||||
.option("--show-secrets", "Include sensitive fields (license key, JWT secret) without prompting")
|
||||
.option("--show-secrets", "Include secrets (license key, passwords, tokens) in clear without prompting")
|
||||
.option(
|
||||
"--instance <instance:string>",
|
||||
"Name of the instance, override the active instance",
|
||||
|
||||
@@ -103,6 +103,60 @@ export const SETTINGS_MANAGED_ONLY_WHEN_PRESENT = [
|
||||
* so a file that still carries one must not show as differing from the workspace. */
|
||||
export const RETIRED_SETTINGS = ["guest_access_enabled"] as const;
|
||||
|
||||
/** How the server's settings reads begin a secret they withheld (without `dangerouslyRevealSecrets`). */
|
||||
export const REDACTED_SECRET_PREFIX = "__REDACTED__";
|
||||
|
||||
function keepUnchangedLocalSecrets(redacted: any, revealed: any, local: any): any {
|
||||
if (typeof redacted === "string" && redacted.startsWith(REDACTED_SECRET_PREFIX)) {
|
||||
return local !== undefined && deepEqual(local, revealed) ? local : redacted;
|
||||
}
|
||||
if (Array.isArray(redacted)) {
|
||||
return redacted.map((v, i) =>
|
||||
keepUnchangedLocalSecrets(v, revealed?.[i], local?.[i])
|
||||
);
|
||||
}
|
||||
if (redacted && typeof redacted === "object") {
|
||||
return Object.fromEntries(
|
||||
Object.entries(redacted).map(([k, v]) => [
|
||||
k,
|
||||
keepUnchangedLocalSecrets(v, revealed?.[k], local?.[k]),
|
||||
])
|
||||
);
|
||||
}
|
||||
return redacted;
|
||||
}
|
||||
|
||||
/**
|
||||
* The remote settings as pull and push compare them with the local file. Unless
|
||||
* `showSecrets`, a remote secret stays redacted, except where the local file already holds
|
||||
* that same value: comparing against the redacted value alone would flag every secret as
|
||||
* changed on each sync, while the revealed one must not reach the printed diff or the file.
|
||||
*/
|
||||
async function remoteSettingsAgainstLocal(
|
||||
opts: InstanceSyncOptions,
|
||||
readLocal: () => Promise<GlobalSetting[]>
|
||||
): Promise<GlobalSetting[]> {
|
||||
if (opts.showSecrets) {
|
||||
return await wmill.listGlobalSettings({ dangerouslyRevealSecrets: true });
|
||||
}
|
||||
const redacted = await wmill.listGlobalSettings();
|
||||
if (!JSON.stringify(redacted).includes(REDACTED_SECRET_PREFIX)) {
|
||||
return redacted;
|
||||
}
|
||||
const revealed = await wmill.listGlobalSettings({
|
||||
dangerouslyRevealSecrets: true,
|
||||
});
|
||||
const local = await readLocal();
|
||||
return redacted.map((s) => ({
|
||||
...s,
|
||||
value: keepUnchangedLocalSecrets(
|
||||
s.value,
|
||||
revealed.find((r) => r.name === s.name)?.value,
|
||||
local.find((l) => l.name === s.name)?.value
|
||||
),
|
||||
}));
|
||||
}
|
||||
|
||||
// Legacy settings interface for reading old settings.yaml files
|
||||
interface LegacySimplifiedSettings {
|
||||
auto_invite_enabled?: boolean;
|
||||
@@ -708,7 +762,10 @@ export async function pushWorkspaceKey(
|
||||
}
|
||||
}
|
||||
|
||||
export async function readInstanceSettings(opts: InstanceSyncOptions) {
|
||||
export async function readInstanceSettings(
|
||||
opts: InstanceSyncOptions,
|
||||
silent = false
|
||||
) {
|
||||
let localSettings: GlobalSetting[] = [];
|
||||
|
||||
await checkInstanceSettingsPath(opts);
|
||||
@@ -718,7 +775,7 @@ export async function readInstanceSettings(opts: InstanceSyncOptions) {
|
||||
instanceSettingsPath
|
||||
)) as GlobalSetting[];
|
||||
} catch {
|
||||
log.warn(`No ${instanceSettingsPath} found`);
|
||||
if (!silent) log.warn(`No ${instanceSettingsPath} found`);
|
||||
}
|
||||
return localSettings;
|
||||
}
|
||||
@@ -781,7 +838,22 @@ export async function pullInstanceSettings(
|
||||
opts: InstanceSyncOptions,
|
||||
preview = false
|
||||
) {
|
||||
const remoteSettings = await wmill.listGlobalSettings();
|
||||
const remoteSettings = await remoteSettingsAgainstLocal(
|
||||
opts,
|
||||
async () =>
|
||||
await processInstanceSettings(
|
||||
await readInstanceSettings(opts, true),
|
||||
"decode"
|
||||
)
|
||||
);
|
||||
if (
|
||||
!preview &&
|
||||
JSON.stringify(remoteSettings).includes(REDACTED_SECRET_PREFIX)
|
||||
) {
|
||||
log.info(
|
||||
"Secrets are redacted in the pulled settings: pass --show-secrets to include them. Pushing them back keeps the stored secrets."
|
||||
);
|
||||
}
|
||||
|
||||
await checkInstanceSettingsPath(opts);
|
||||
|
||||
@@ -818,9 +890,12 @@ export async function pushInstanceSettings(
|
||||
opts: InstanceSyncOptions,
|
||||
preview: boolean = false
|
||||
) {
|
||||
const remoteSettings = await wmill.listGlobalSettings();
|
||||
let localSettings: GlobalSetting[] = await readInstanceSettings(opts);
|
||||
localSettings = await processInstanceSettings(localSettings, "decode");
|
||||
const remoteSettings = await remoteSettingsAgainstLocal(
|
||||
opts,
|
||||
async () => localSettings
|
||||
);
|
||||
|
||||
if (opts.baseUrl) {
|
||||
localSettings = localSettings.filter((s) => s.name !== "base_url");
|
||||
|
||||
Generated
+2
-1
@@ -9205,6 +9205,7 @@ sync local with a remote instance or the opposite (push or pull)
|
||||
- \`--dry-run\` - Perform a dry run without making changes
|
||||
- \`--skip-users\` - Skip pulling users
|
||||
- \`--skip-settings\` - Skip pulling settings
|
||||
- \`--show-secrets\` - Pull secrets (license key, passwords, tokens) in clear instead of redacted
|
||||
- \`--skip-configs\` - Skip pulling configs (worker groups)
|
||||
- \`--skip-groups\` - Skip pulling instance groups
|
||||
- \`--include-workspaces\` - Also pull workspaces
|
||||
@@ -9227,7 +9228,7 @@ sync local with a remote instance or the opposite (push or pull)
|
||||
- \`instance whoami\` - Display information about the currently logged-in user
|
||||
- \`instance get-config\` - Dump the current instance config (global settings + worker configs) as YAML
|
||||
- \`-o, --output-file <file:string>\` - Write YAML to a file instead of stdout
|
||||
- \`--show-secrets\` - Include sensitive fields (license key, JWT secret) without prompting
|
||||
- \`--show-secrets\` - Include secrets (license key, passwords, tokens) in clear without prompting
|
||||
- \`--instance <instance:string>\` - Name of the instance, override the active instance
|
||||
- \`instance connect-slack\` - Non-interactively connect Slack at the instance level using a pre-minted bot token (xoxb-...). Produces the same artifacts as the UI OAuth flow: global_settings 'slack' row + encrypted f/slack_bot/global_bot_token variable and resource in the admins workspace.
|
||||
- \`--bot-token <bot_token:string>\` - Slack bot token (xoxb-...)
|
||||
|
||||
Reference in New Issue
Block a user