Files
windmill/frontend/src/lib/components/instanceSettings/ExternalSecretsConfig.svelte
T
e4671f7d3f feat: optional Vault AppRole secret_id setting, env var as fallback (#12276)
* feat: add an optional Vault AppRole secret_id setting

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: mask the AppRole secret_id in the instance settings YAML view

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: align secret storage panels with the form guidelines

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: use the card styles from the brand guidelines in the secret storage panels

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: update ee-repo-ref to 747a8896c7bd2490063ccfe0c0796aa14b57ab67

This commit updates the EE repository reference after PR #966 was merged in windmill-ee-private.

Previous ee-repo-ref: 450e839407e53540186523170127e5b17d110c5c

New ee-repo-ref: 747a8896c7bd2490063ccfe0c0796aa14b57ab67

Automated by sync-ee-ref workflow.

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
Co-authored-by: Ruben Fiszel <ruben@windmill.dev>
2026-11-09 17:45:03 +01:00

375 lines
12 KiB
Svelte

<script lang="ts">
import { Alert, Button } from '$lib/components/common'
import Password from '../Password.svelte'
import { SettingService, WorkspaceService } from '$lib/gen'
import { sendUserToast } from '$lib/toast'
import TextInput from '../text_input/TextInput.svelte'
import Toggle from '../Toggle.svelte'
import { Plus, Server, Trash2 } from 'lucide-svelte'
import type { Writable } from 'svelte/store'
import { enterpriseLicense } from '$lib/stores'
import ToggleButtonGroup from '../common/toggleButton-v2/ToggleButtonGroup.svelte'
import ToggleButton from '../common/toggleButton-v2/ToggleButton.svelte'
import EEOnly from '../EEOnly.svelte'
import MultiSelect from '../select/MultiSelect.svelte'
import { resource } from 'runed'
import Tooltip from '../meltComponents/Tooltip.svelte'
interface Props {
values: Writable<Record<string, any>>
disabled?: boolean
}
let { values, disabled = false }: Props = $props()
type AllowedPrefix = { prefix: string; workspaces: string[] }
let config = $derived(
$values['external_secrets'] as
| { vault?: Record<string, any>; allowed?: AllowedPrefix[] }
| undefined
)
let vault = $derived(config?.vault)
let backendVault = $derived(
$values['secret_backend']?.type === 'HashiCorpVault' ? $values['secret_backend'] : undefined
)
let workspaces = resource(
() => disabled,
async (disabled) =>
disabled
? []
: (await WorkspaceService.listWorkspacesAsSuperAdmin()).map((w) => ({
label: w.id,
value: w.id
}))
)
let allowed = $derived(config?.allowed ?? [])
let authMethod: 'token' | 'approle' | 'jwt' = $derived(
vault?.token != null ? 'token' : vault?.approle_role_id != null ? 'approle' : 'jwt'
)
let testing = $state(false)
function update(patch: { vault?: Record<string, any> | undefined; allowed?: AllowedPrefix[] }) {
const next = { ...(config ?? {}), ...patch }
$values['external_secrets'] = next.vault || next.allowed?.length ? next : undefined
}
function setConnection(mode: string | undefined) {
if (mode === 'same') {
update({ vault: undefined })
} else if (mode === 'separate' && backendVault && !vault) {
// The backend's storage location does not apply to references, only how to reach Vault.
const { type: _t, mount_path: _m, kv_secret_path_prefix: _p, ...conn } = backendVault
update({ vault: conn })
}
}
function setVaultField(field: string, value: any) {
update({ vault: { ...vault, [field]: value === '' ? undefined : value } })
}
function setAuthMethod(method: string | undefined) {
if (!vault || !method) return
const { token: _t, approle_role_id: _a, approle_secret_id: _s, jwt_role: _j, ...rest } = vault
update({
vault: {
...rest,
...(method === 'token' ? { token: vault.token ?? '' } : {}),
...(method === 'approle'
? {
approle_role_id: vault.approle_role_id ?? '',
approle_secret_id: vault.approle_secret_id
}
: {}),
...(method === 'jwt' ? { jwt_role: vault.jwt_role ?? 'windmill-secrets' } : {})
}
})
}
function setAllowed(i: number, patch: Partial<AllowedPrefix>) {
update({ allowed: allowed.map((a, j) => (i === j ? { ...a, ...patch } : a)) })
}
async function testConnection() {
if (!vault) return
testing = true
try {
await SettingService.testSecretBackend({
requestBody: { ...vault, address: vault.address, mount_path: '' }
})
sendUserToast('Successfully connected to HashiCorp Vault')
} catch (e: any) {
sendUserToast(`Connection failed: ${e.body ?? e.message}`, true)
} finally {
testing = false
}
}
</script>
<div class="flex flex-col gap-4">
{#if !$enterpriseLicense}
<EEOnly>External secret references require Enterprise Edition</EEOnly>
{/if}
<span class="text-xs text-secondary">
A secret variable can reference an existing secret, as
<code>$external:vault://&lt;path&gt;#&lt;key&gt;</code>, or the whole secret as JSON without
<code>#&lt;key&gt;</code>, instead of holding its value. The value is read from Vault each time
the variable is read.
</span>
<Alert type="info" size="xs" title="Prefer the Vault backend for secrets Windmill owns">
Use HashiCorp Vault as the secret backend for those. Use references for secrets that are managed
outside Windmill and must stay there.
</Alert>
{#if backendVault}
<div class="flex flex-col gap-1">
<span class="text-xs font-semibold text-emphasis">Vault connection</span>
<ToggleButtonGroup selected={vault ? 'separate' : 'same'} onSelected={setConnection}>
{#snippet children({ item })}
<ToggleButton
value="same"
label="Same as secret backend"
tooltip="Read references through the secret backend's Vault connection"
{item}
{disabled}
/>
<ToggleButton
value="separate"
label="Separate connection"
tooltip="Read references through their own Vault connection, for another Vault or a narrower identity"
{item}
{disabled}
/>
{/snippet}
</ToggleButtonGroup>
{#if !vault}
<span class="text-xs text-secondary">
References are read from {backendVault.address || 'the Vault address above'} with the secret
backend's authentication.
</span>
{/if}
</div>
{:else}
<Toggle
{disabled}
checked={!!vault}
on:change={(e) =>
update({ vault: e.detail ? { address: '', jwt_role: 'windmill-secrets' } : undefined })}
size="xs"
options={{ right: 'HashiCorp Vault connection' }}
/>
{/if}
{#if vault}
<div class="flex flex-col gap-4 p-4 border rounded-md bg-surface-tertiary">
<div class="flex flex-col gap-1">
<label for="ext_vault_address" class="text-xs font-semibold text-emphasis">
Vault address
</label>
<TextInput
inputProps={{
id: 'ext_vault_address',
placeholder: 'https://vault.company.com:8200',
disabled
}}
bind:value={() => vault?.address ?? '', (v) => setVaultField('address', v)}
/>
</div>
<div class="flex flex-col gap-1">
<span class="text-xs font-semibold text-emphasis">Authentication method</span>
<ToggleButtonGroup selected={authMethod} onSelected={(v) => setAuthMethod(v)}>
{#snippet children({ item })}
<ToggleButton
value="jwt"
label="JWT auth"
tooltip="Authenticate using Windmill-signed JWTs"
{item}
{disabled}
/>
<ToggleButton
value="approle"
label="AppRole"
tooltip="Log in with an AppRole role_id and secret_id"
{item}
{disabled}
/>
<ToggleButton
value="token"
label="Static token"
tooltip="Use a static Vault token"
{item}
{disabled}
/>
{/snippet}
</ToggleButtonGroup>
</div>
{#if authMethod === 'approle'}
<div class="flex flex-col gap-3 p-3 bg-surface-secondary rounded-md">
<div class="flex flex-col gap-1">
<label for="ext_vault_role_id" class="text-xs font-semibold text-emphasis"
>Role ID</label
>
<TextInput
inputProps={{ id: 'ext_vault_role_id', disabled }}
bind:value={
() => vault?.approle_role_id ?? '',
(v) => update({ vault: { ...vault, approle_role_id: v ?? '' } })
}
/>
</div>
<div class="flex flex-col gap-1">
<label for="ext_vault_secret_id" class="text-xs font-semibold text-emphasis">
Secret ID (optional)
</label>
<span class="text-xs text-secondary">
Leave blank to use <code>VAULT_APPROLE_SECRET_ID</code>. With neither set, no
secret_id is sent (<code>bind_secret_id=false</code> roles).
</span>
<Password
id="ext_vault_secret_id"
bind:password={
() => vault?.approle_secret_id ?? '', (v) => setVaultField('approle_secret_id', v)
}
small
{disabled}
/>
</div>
<div class="flex flex-col gap-1">
<label for="ext_vault_approle_mount" class="text-xs font-semibold text-emphasis">
AppRole mount path (optional) <Tooltip
>{#snippet text()}
Path where the AppRole auth method is enabled in Vault. Set it only for a
non-default path (<code>vault auth enable -path=&lt;mount&gt; approle</code>).
{/snippet}</Tooltip
>
</label>
<TextInput
inputProps={{ id: 'ext_vault_approle_mount', placeholder: 'approle', disabled }}
bind:value={
() => vault?.approle_mount_path ?? '', (v) => setVaultField('approle_mount_path', v)
}
/>
</div>
</div>
{:else if authMethod === 'jwt'}
<div class="flex flex-col gap-3 p-3 bg-surface-secondary rounded-md">
<div class="flex flex-col gap-1">
<label for="ext_vault_jwt_role" class="text-xs font-semibold text-emphasis">
JWT auth role
</label>
<TextInput
inputProps={{ id: 'ext_vault_jwt_role', placeholder: 'windmill-secrets', disabled }}
bind:value={
() => vault?.jwt_role ?? '',
(v) => update({ vault: { ...vault, jwt_role: v ?? '' } })
}
/>
</div>
<div class="flex flex-col gap-1">
<label for="ext_vault_jwt_mount" class="text-xs font-semibold text-emphasis">
JWT auth mount path (optional) <Tooltip
>{#snippet text()}
Path where the JWT auth method is enabled in Vault. Set it only for a non-default
path (<code>vault auth enable -path=&lt;mount&gt; jwt</code>).
{/snippet}</Tooltip
>
</label>
<TextInput
inputProps={{ id: 'ext_vault_jwt_mount', placeholder: 'jwt', disabled }}
bind:value={
() => vault?.jwt_mount_path ?? '', (v) => setVaultField('jwt_mount_path', v)
}
/>
</div>
</div>
{:else}
<div class="flex flex-col gap-1 p-3 bg-surface-secondary rounded-md">
<span class="text-xs font-semibold text-emphasis">Vault token</span>
<span class="text-xs text-secondary">Recommended only for testing.</span>
<Password
bind:password={
() => vault?.token ?? '', (v) => update({ vault: { ...vault, token: v ?? '' } })
}
small
{disabled}
/>
</div>
{/if}
<div class="flex flex-col gap-1">
<label for="ext_vault_namespace" class="text-xs font-semibold text-emphasis">
Namespace (optional)
</label>
<TextInput
inputProps={{ id: 'ext_vault_namespace', placeholder: 'admin/my-namespace', disabled }}
bind:value={() => vault?.namespace ?? '', (v) => setVaultField('namespace', v)}
/>
</div>
<Toggle
{disabled}
checked={!!vault?.skip_ssl_verify}
on:change={(e) => setVaultField('skip_ssl_verify', e.detail || undefined)}
size="xs"
options={{ right: 'Skip TLS certificate verification' }}
/>
<Button
unifiedSize="md"
variant="default"
onclick={testConnection}
disabled={disabled || !vault?.address || testing}
loading={testing}
startIcon={{ icon: Server }}>Test connection</Button
>
</div>
{/if}
<div class="flex flex-col gap-2">
<span class="text-xs font-semibold text-emphasis">Allowed prefixes</span>
<span class="text-xs text-secondary">
A reference resolves only under one of these prefixes, matched on whole path segments, for the
listed workspaces (all workspaces when empty). Any admin of a listed workspace can read every
secret under its prefixes, within what Windmill's Vault identity can read.
</span>
{#if allowed.length === 0}
<Alert type="warning" size="xs" title="No prefixes allowed yet">
References are refused until you add a prefix and choose its workspaces.
</Alert>
{/if}
{#each allowed as a, i (i)}
<div class="flex flex-row gap-2 items-center">
<TextInput
class="flex-1"
inputProps={{ placeholder: 'vault://secret/team', disabled }}
bind:value={() => a.prefix, (v) => setAllowed(i, { prefix: v ?? '' })}
/>
<MultiSelect
class="flex-1"
items={workspaces.current ?? []}
placeholder="All workspaces"
{disabled}
bind:value={() => a.workspaces, (v) => setAllowed(i, { workspaces: v })}
/>
<Button
unifiedSize="md"
variant="subtle"
iconOnly
startIcon={{ icon: Trash2 }}
{disabled}
aria-label="Remove prefix"
onclick={() => update({ allowed: allowed.filter((_, j) => j !== i) })}
/>
</div>
{/each}
<Button
unifiedSize="sm"
variant="default"
startIcon={{ icon: Plus }}
{disabled}
wrapperClasses="self-start"
onclick={() => update({ allowed: [...allowed, { prefix: 'vault://', workspaces: [] }] })}
>Add prefix</Button
>
</div>
</div>