Files
windmill/frontend/src/lib/components/JobTokenScopesSetting.svelte
T
0249bb94ac refactor: harmonize flow and script settings layout (#12013)
* refactor: harmonize flow and script settings layout

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: keep the priority input open while it is edited

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: keep settings rows open while edited and name the deploying user for non-admins

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: write a setting before its row opens and show its real state while edited

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: slide settings rows open to their full height

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: remount a settings row's fields when its toggle turns it on

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: put the AI prompt behind a settings toggle

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

* feat: summarize active runtime and permission settings on the metadata tab

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

* refactor: move the active settings chips into the settings header

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

* fix: bring back the active setting icons on the settings tabs

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

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Ruben Fiszel <ruben@windmill.dev>
2026-10-27 01:24:09 +01:00

77 lines
3.0 KiB
Svelte

<script lang="ts">
import ToggleButtonGroup from './common/toggleButton-v2/ToggleButtonGroup.svelte'
import ToggleButton from './common/toggleButton-v2/ToggleButton.svelte'
import ScopeSelector from './settings/ScopeSelector.svelte'
import SettingToggle from './itemSettings/SettingToggle.svelte'
interface Props {
/** `null`/`undefined`: the job token has the full permissions of the identity it runs as. */
value: string[] | null | undefined
kind: 'script' | 'flow' | 'step'
}
let { value = $bindable(), kind }: Props = $props()
const OIDC_ONLY = ['oidc:write']
type Mode = 'oidc_only' | 'no_api' | 'custom'
function modeOf(scopes: string[]): Mode {
if (scopes.length === 0) return 'no_api'
if (scopes.length === 1 && scopes[0] === OIDC_ONLY[0]) return 'oidc_only'
return 'custom'
}
// Derived from `value` so an edit made elsewhere (the flow YAML) shows here; the flag only
// keeps "Custom" selected while a custom list happens to equal a preset.
let customPicked = $state(false)
const mode: Mode = $derived(customPicked ? 'custom' : modeOf(value ?? OIDC_ONLY))
function setMode(next: Mode) {
customPicked = next === 'custom'
value = next === 'oidc_only' ? [...OIDC_ONLY] : next === 'no_api' ? [] : [...(value ?? [])]
}
</script>
<SettingToggle
setting="job-token"
label="Restrict the job token"
tooltip={`Limit what the WM_TOKEN of this ${kind}'s jobs can do through the API, e.g. only mint an OIDC token. Use it for code that handles untrusted input, such as AI agents.`}
checked={value != null}
onchange={(on) => {
if (on) {
setMode('oidc_only')
} else {
value = null
}
}}
>
<ToggleButtonGroup selected={mode} onSelected={(v) => setMode(v)}>
{#snippet children({ item })}
<ToggleButton value="oidc_only" label="OIDC token only" {item} />
<ToggleButton value="no_api" label="No API access" {item} />
<ToggleButton value="custom" label="Custom" {item} />
{/snippet}
</ToggleButtonGroup>
{#if mode === 'custom'}
<ScopeSelector
bind:selectedScopes={() => value ?? [], (scopes) => (value = [...scopes])}
emptyLabel="No scopes selected. The job token can only reach its own job."
/>
{/if}
<p class="text-2xs text-secondary">
{#if kind === 'step'}
The <code>WM_TOKEN</code> of every job this step runs can only do what these scopes allow, on top
of the flow's own restriction. Loop and branch bodies, and AI agent tools, inherit it.
{:else}
The <code>WM_TOKEN</code> of every job of this {kind} can only do what these scopes allow. Jobs
it starts, {kind === 'flow' ? 'its steps, ' : ''}and AI agent tools inherit the restriction.
{/if}
Variables and resources passed as <code>$var:</code>/<code>$res:</code> inputs, an AI agent's
provider resource, relative imports and object storage each need a read scope, and script state
(<code>getState</code>/<code>setState</code>) needs <code>resources:write</code>. Write scopes
on scripts, flows, schedules or triggers let a job escape the restriction. Jobs with a
restricted token never run on dedicated workers.
</p>
</SettingToggle>