fix: show a pending service account by name and test as yourself until deploy

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Guilhem Lemouel
2026-11-02 01:42:42 -08:00
co-authored by Claude Opus 5.5
parent 4431711177
commit 3f02e71f8e
5 changed files with 19 additions and 3 deletions
@@ -221,6 +221,7 @@
{/if}
<span class="border-t pt-3 text-2xs text-secondary">
Created when you deploy, with the access above. Counts as half a seat.
Created when you deploy, with the access above. Until then, tests run as you. Counts as half a
seat.
</span>
</div>
@@ -28,6 +28,13 @@ export type PendingServiceAccount = {
// replaces it with the real one, which only the server's creation knows.
export const PENDING_EMAIL_DOMAIN = 'pending.sa.wm.dev'
/** A run-as email for display: the placeholder of an account the deploy creates is not one. */
export function runAsEmailLabel(email: string | undefined): string | undefined {
return email?.endsWith(`@${PENDING_EMAIL_DOMAIN}`)
? `${email.split('@')[0]} (created when you deploy)`
: email
}
const pending = new SvelteMap<string, PendingServiceAccount>()
const key = (workspace: string, permissionedAs: string) => `${workspace}:${permissionedAs}`
@@ -24,6 +24,7 @@
import HiddenComponent from '../components/helpers/HiddenComponent.svelte'
import RecomputeAllComponents from './RecomputeAllComponents.svelte'
import { BG_PREFIX } from './appUtilsCore'
import { runAsEmailLabel } from '$lib/components/access/serviceAccounts.svelte'
interface Props {
app: App
@@ -301,7 +302,9 @@
<h2 class="truncate">{summary}</h2>
<RecomputeAllComponents />
<div class="text-2xs text-secondary">
{policy.on_behalf_of ? `on behalf of ${policy.on_behalf_of_email}` : ''}
{policy.on_behalf_of
? `on behalf of ${runAsEmailLabel(policy.on_behalf_of_email)}`
: ''}
</div>
</div>
</div>
@@ -27,6 +27,7 @@
import Popover from '$lib/components/Popover.svelte'
import type { Policy } from '$lib/gen'
import { BG_PREFIX, findGridItem } from './appUtilsCore'
import { runAsEmailLabel } from '$lib/components/access/serviceAccounts.svelte'
interface Props {
policy: Policy
@@ -174,7 +175,7 @@
/>
</div>
<div>
{policy.on_behalf_of ? `Author ${policy.on_behalf_of_email}` : ''}
{policy.on_behalf_of ? `Author ${runAsEmailLabel(policy.on_behalf_of_email)}` : ''}
<Tooltip>
The scripts will be run on behalf of the author and a tight policy ensure security about
the possible inputs of the runnables.
@@ -1,3 +1,5 @@
import { PENDING_EMAIL_DOMAIN } from '$lib/components/access/serviceAccounts.svelte'
type ActingUser =
| { is_admin?: boolean; is_super_admin?: boolean; operator?: boolean; groups?: string[] }
| undefined
@@ -18,6 +20,8 @@ export function previewOnBehalfOf(
!user?.operator &&
(!!user?.is_admin || !!user?.is_super_admin || !!user?.groups?.includes('wm_deployers'))
if (!canPreserve) return undefined
// A service account created at deploy does not exist yet, so the server refuses to run as it.
if (onBehalfOfEmail?.endsWith(`@${PENDING_EMAIL_DOMAIN}`)) return undefined
return onBehalfOf || onBehalfOfEmail || undefined
}