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:
Guilhem Lemouel
2026-10-29 12:21:13 -07:00
co-authored by Claude Opus 5.5
parent 62ebe343e1
commit 4c72597dcf
2 changed files with 9 additions and 7 deletions
@@ -134,11 +134,13 @@ export async function createPendingServiceAccount(
const account = getPendingServiceAccount(workspace, permissionedAs)
if (!account || !permissionedAs) return undefined
const { username } = account
const exists = await UserService.getUser({ workspace, username }).then(
() => true,
() => false
)
if (!exists) {
const existing = await UserService.getUser({ workspace, username }).catch(() => undefined)
// Someone may have taken the name since it was picked: granting to it would hand a person, or
// a disabled account, what was meant for the new one.
if (existing && (!existing.is_service_account || existing.disabled)) {
throw new Error(`${username} is already taken by a user that is not an enabled service account`)
}
if (!existing) {
await WorkspaceService.createServiceAccount({
workspace,
requestBody: { username, operator: true }
@@ -184,7 +186,7 @@ export async function createPolicyServiceAccount(
if (email) policy.on_behalf_of_email = email
return true
} catch (e) {
sendUserToast(`Could not create ${policy.on_behalf_of}: ${e?.body ?? e}`, true)
sendUserToast(`Could not create ${policy.on_behalf_of}: ${e?.body ?? e?.message ?? e}`, true)
return false
}
}
@@ -89,7 +89,7 @@
const created = await createPendingServiceAccount(targetWorkspace, runsAs)
if (created) email = created
} catch (e) {
sendUserToast(`Could not create ${runsAs}: ${e?.body ?? e}`, true)
sendUserToast(`Could not create ${runsAs}: ${e?.body ?? e?.message ?? e}`, true)
return
} finally {
deploying = false