mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-29 08:06:46 +00:00
fixup! feat: create a service account from the run-as picker at deploy
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
8df61c7576
commit
9ad95a2b09
@@ -5,7 +5,6 @@
|
||||
import TextInput from '$lib/components/text_input/TextInput.svelte'
|
||||
import { FolderService, UserService } from '$lib/gen'
|
||||
import { Database, Folder, Info, KeyRound } from 'lucide-svelte'
|
||||
import DeployersPicker from './DeployersPicker.svelte'
|
||||
import { detectNeeds, type NeedsSource, type RunnableKind } from './detectNeeds'
|
||||
import { setPendingServiceAccount, type Grant } from './serviceAccounts.svelte'
|
||||
|
||||
@@ -41,8 +40,6 @@
|
||||
|
||||
let name = $state('')
|
||||
let rows: Row[] = $state([])
|
||||
let deployers: string[] = $state([])
|
||||
let setDefault = $state(false)
|
||||
/** Whether the item's folder already names default users; unknown until loaded. */
|
||||
let folderHasDefaults: boolean | undefined = $state(undefined)
|
||||
let usernames: string[] = $state([])
|
||||
@@ -71,7 +68,6 @@
|
||||
checked: true
|
||||
}
|
||||
]
|
||||
deployers = [`f/${itemFolder}`]
|
||||
FolderService.getFolder({ workspace, name: itemFolder }).then(
|
||||
(f) => (folderHasDefaults = !!f.default_permissioned_as?.length),
|
||||
() => (folderHasDefaults = true)
|
||||
@@ -115,7 +111,6 @@
|
||||
)
|
||||
const principal = $derived(`u/${name}`)
|
||||
const chosen = $derived(rows.filter((r) => r.checked))
|
||||
const reads = $derived(chosen.map((r) => (r.kind === 'folder' ? `f/${r.path}` : r.path)))
|
||||
const addableFolders = $derived(
|
||||
folderNames
|
||||
.filter((f) => !rows.some((r) => r.kind === 'folder' && r.path === f))
|
||||
@@ -126,9 +121,7 @@
|
||||
if (nameError) return
|
||||
setPendingServiceAccount(workspace, {
|
||||
username: name,
|
||||
grants: chosen.map(({ kind, path }) => ({ kind, path })),
|
||||
deployers,
|
||||
defaultFor: setDefault ? itemFolder : undefined
|
||||
grants: chosen.map(({ kind, path }) => ({ kind, path }))
|
||||
})
|
||||
onUse(principal)
|
||||
}
|
||||
@@ -217,39 +210,11 @@
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
<div class="flex flex-col">
|
||||
<span class="text-xs font-semibold text-emphasis">Who can deploy as it</span>
|
||||
<span class="text-2xs text-secondary">
|
||||
They can make what they deploy run as {name || 'it'}. Anyone else who redeploys this
|
||||
{itemKind} makes it run as themselves.
|
||||
</span>
|
||||
</div>
|
||||
<DeployersPicker {principal} bind:deployers {reads} />
|
||||
</div>
|
||||
|
||||
{#if itemFolder && folderHasDefaults}
|
||||
<span class="text-2xs text-secondary">
|
||||
<code>f/{itemFolder}</code> already sets who new items in it run as. Change that in the
|
||||
folder's settings on the <a href="/folders">Folders</a> page.
|
||||
</span>
|
||||
{:else if itemFolder && folderHasDefaults === false}
|
||||
<label class="flex items-start gap-2 cursor-pointer">
|
||||
<Checkbox
|
||||
class="mt-0.5"
|
||||
checked={setDefault}
|
||||
onChange={() => (setDefault = !setDefault)}
|
||||
/>
|
||||
<span class="flex flex-col">
|
||||
<span class="text-xs text-primary">
|
||||
Also run new items in <code>f/{itemFolder}</code> as {name || 'it'}
|
||||
</span>
|
||||
<span class="text-2xs text-secondary">
|
||||
Sets the folder's default user: a new script, flow or app there runs as {name || 'it'}
|
||||
when the person creating it can deploy as it.
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
{/if}
|
||||
|
||||
<div class="flex items-center justify-between gap-2 border-t pt-3">
|
||||
|
||||
@@ -3,14 +3,12 @@
|
||||
import Modal from '$lib/components/common/modal/Modal.svelte'
|
||||
import Portal from '$lib/components/Portal.svelte'
|
||||
import {
|
||||
canDeployAs,
|
||||
canPreserveOnBehalfOf,
|
||||
WM_DEPLOYERS_GROUP
|
||||
} from '$lib/components/itemSettings/onBehalfOf'
|
||||
import { useOperatingUser } from '$lib/components/operatingWorkspace.svelte'
|
||||
import { enterpriseLicense } from '$lib/stores'
|
||||
import { Bot, Folder, Users } from 'lucide-svelte'
|
||||
import { useDeployAs } from './deployAs.svelte'
|
||||
import { Bot, Folder } from 'lucide-svelte'
|
||||
import type { NeedsSource } from './detectNeeds'
|
||||
import NewServiceAccountForm from './NewServiceAccountForm.svelte'
|
||||
import {
|
||||
@@ -47,27 +45,19 @@
|
||||
const me = $derived(
|
||||
operatingUser.current?.username ? `u/${operatingUser.current.username}` : undefined
|
||||
)
|
||||
const deployAs = useDeployAs(() => targetWorkspace)
|
||||
const serviceAccounts = useServiceAccounts(() => targetWorkspace)
|
||||
|
||||
const pending = $derived(getPendingServiceAccount(targetWorkspace, runsAs))
|
||||
const itemFolder = $derived(
|
||||
itemPath?.startsWith('f/') ? itemPath.split('/')[1] || undefined : undefined
|
||||
)
|
||||
const canPick = $derived(
|
||||
canPreserveOnBehalfOf(operatingUser.current) || deployAs.current.length > 0
|
||||
)
|
||||
const canPick = $derived(canPreserveOnBehalfOf(operatingUser.current))
|
||||
const canCreate = $derived(!!$enterpriseLicense && !!operatingUser.current?.is_admin)
|
||||
// An account that already reads the item's folder, which the deployer may deploy as.
|
||||
const folderAccount = $derived(
|
||||
itemFolder
|
||||
itemFolder && canPick
|
||||
? serviceAccounts.current
|
||||
.filter(
|
||||
(a) =>
|
||||
!a.pending &&
|
||||
a.folders.includes(itemFolder) &&
|
||||
canDeployAs(operatingUser.current, `u/${a.username}`, deployAs.current)
|
||||
)
|
||||
.filter((a) => !a.pending && a.folders.includes(itemFolder))
|
||||
.sort((a, b) => a.username.localeCompare(b.username))[0]
|
||||
: undefined
|
||||
)
|
||||
@@ -84,7 +74,7 @@
|
||||
!isNew &&
|
||||
!!savedPermissionedAs &&
|
||||
runsAs !== savedPermissionedAs &&
|
||||
!canDeployAs(operatingUser.current, savedPermissionedAs, deployAs.current) &&
|
||||
!canPreserveOnBehalfOf(operatingUser.current) &&
|
||||
serviceAccounts.current.some((a) => `u/${a.username}` === savedPermissionedAs)
|
||||
)
|
||||
|
||||
@@ -140,30 +130,13 @@
|
||||
</span>
|
||||
</span>
|
||||
{/if}
|
||||
{#if pending.deployers.length}
|
||||
<span class="flex items-start gap-2">
|
||||
<Users size={14} class="mt-0.5 shrink-0 text-secondary" />
|
||||
<span>
|
||||
Lets {pending.deployers
|
||||
.map((d) => (d.startsWith('f/') ? `writers of ${d}` : d))
|
||||
.join(', ')} deploy as it
|
||||
</span>
|
||||
</span>
|
||||
{/if}
|
||||
{#if pending.defaultFor}
|
||||
<span class="flex items-start gap-2">
|
||||
<Folder size={14} class="mt-0.5 shrink-0 text-secondary" />
|
||||
<span>Makes it the default user of new items in f/{pending.defaultFor}</span>
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if dropsAccount}
|
||||
<Alert type="warning" size="xs" title={`This takes ${savedPermissionedAs} off the ${kind}`}>
|
||||
Only the people on {savedPermissionedAs}'s deploy list, workspace admins and members of
|
||||
{WM_DEPLOYERS_GROUP} can deploy as it. The {kind} will run with your access, and stop working for
|
||||
everyone if you leave.
|
||||
Only workspace admins and members of {WM_DEPLOYERS_GROUP} can deploy as it. The {kind} will run with
|
||||
your access, and stop working for everyone if you leave.
|
||||
</Alert>
|
||||
{/if}
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { resource } from 'runed'
|
||||
import { SvelteMap } from 'svelte/reactivity'
|
||||
import { FolderService, GranularAclService, UserService, WorkspaceService } from '$lib/gen'
|
||||
import { FolderService, UserService, WorkspaceService } from '$lib/gen'
|
||||
import { setGrant } from './access'
|
||||
import { forgetDeployAs } from './deployAs.svelte'
|
||||
import { sendUserToast } from '$lib/toast'
|
||||
|
||||
export type ServiceAccount = {
|
||||
@@ -23,9 +22,6 @@ export type PendingServiceAccount = {
|
||||
username: string
|
||||
/** Read access, folders by name. */
|
||||
grants: Grant[]
|
||||
deployers: string[]
|
||||
/** Folder whose default user becomes the account for every new item in it. */
|
||||
defaultFor?: string
|
||||
}
|
||||
|
||||
// The deploy dialog's run-as field needs an email for the account before it exists; the deploy
|
||||
@@ -149,28 +145,9 @@ export async function createPendingServiceAccount(
|
||||
for (const grant of account.grants) {
|
||||
await setGrant(workspace, grant.kind, grant.path, permissionedAs, 'read')
|
||||
}
|
||||
await GranularAclService.setServiceAccountDeployers({
|
||||
workspace,
|
||||
requestBody: { principal: permissionedAs, deployers: account.deployers }
|
||||
})
|
||||
if (account.defaultFor) {
|
||||
const folder = await FolderService.getFolder({ workspace, name: account.defaultFor })
|
||||
const rules = folder.default_permissioned_as ?? []
|
||||
if (!rules.some((r) => r.permissioned_as === permissionedAs)) {
|
||||
// Appended: a rule the folder already has for some of its paths keeps precedence.
|
||||
await FolderService.updateFolder({
|
||||
workspace,
|
||||
name: account.defaultFor,
|
||||
requestBody: {
|
||||
default_permissioned_as: [...rules, { path_glob: '**', permissioned_as: permissionedAs }]
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
const { email } = await UserService.getUser({ workspace, username })
|
||||
pending.delete(key(workspace, permissionedAs))
|
||||
asked.delete(workspace)
|
||||
forgetDeployAs(workspace)
|
||||
return email
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user