diff --git a/dashboard/e2e/selfhost.spec.ts b/dashboard/e2e/selfhost.spec.ts index f1cf8a1a..76e8a3e2 100644 --- a/dashboard/e2e/selfhost.spec.ts +++ b/dashboard/e2e/selfhost.spec.ts @@ -608,21 +608,64 @@ test("System: a prepared update with nothing to confirm applies with one press", await expect(page.getByRole("dialog")).toHaveCount(0); }); -test("System: a change to the deploy role or a boundary is the one update that goes to the AWS console", async ({ page }) => { +const ACCESS_LINK = "https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/quickcreate?stackName=coderhelm-prod-access&templateURL=https%3A%2F%2Fcoderhelm-public.s3.amazonaws.com%2Flaunch%2Fv2.0.0%2Faccess.json¶m_Stage=prod"; + +test("System: newer permissions are a separate, optional item with one link; the update applies without them", async ({ page }) => { await setup(page, SELF, { signedIn: true, native: { stack: "coderhelm-prod", can_apply: true, auto_apply: true, - pending: { ...PREPARED, can_apply: false, confirm: "", hold: "it changes the deploy role", data_changes: [], permission_changes: [], admin_changes: ["DeployBoundary (Modify)"] } }, + pending: { ...PREPARED, can_apply: true, confirm: "", hold: "", data_changes: [], permission_changes: [], admin_changes: [], held: ["Boundary", "DeployBoundary"] }, + access: { state: "pending", version: "v2.0.0", summary: ["adds read access to Airflow, ECR and ECS (airflow:Get*, ecs:Describe*, ecr:List*)"], + resources: ["Boundary", "DeployBoundary"], link: ACCESS_LINK, stack: "coderhelm-prod-access", existing: null } }, }); await page.goto("/settings/system/"); const card = page.getByTestId("native-update"); - await expect(card).toContainText("v2.0.0 needs an AWS admin"); - await expect(card).toContainText("chooses Execute"); - await expect(page.getByTestId("native-update-apply")).toHaveCount(0); - await expect(page.getByRole("link", { name: "Open it in the AWS console" })).toHaveAttribute("href", CS_LINK); - // The prepared update is the one thing to do: no second Update button, and it never blocks itself. - await expect(page.getByRole("button", { name: "Update to v2.0.0" })).toHaveCount(0); - await expect(page.locator("#update-blocked")).toHaveCount(0); + await expect(card).toContainText("v2.0.0 is ready to apply"); + await expect(card).not.toContainText("needs an AWS admin"); + await expect(page.getByTestId("native-update-held")).toContainText("stay as they are"); + await expect(page.getByTestId("native-update-apply")).toBeVisible(); + const access = page.getByTestId("native-access"); + await expect(access).toContainText("Permissions: optional, for an AWS admin"); + await expect(page.getByTestId("native-access-summary")).toContainText("Adds read access to Airflow, ECR and ECS"); + await expect(page.getByTestId("native-access-link")).toHaveAttribute("href", ACCESS_LINK); + // Nobody is sent to execute the update's change set in the console: it would run as the deploy role there too. + await expect(page.getByRole("link", { name: "Open it in the AWS console" })).toHaveCount(0); +}); + +test("System: a permissions link that isn't the access stack's quick-create from the release bucket is never rendered", async ({ page }) => { + for (const link of [ + "https://evil.example.com/#/stacks/quickcreate?stackName=coderhelm-prod-access&templateURL=https%3A%2F%2Fcoderhelm-public.s3.amazonaws.com%2Flaunch%2Fv2.0.0%2Faccess.json", + "https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/quickcreate?stackName=coderhelm-prod-access&templateURL=https%3A%2F%2Fevil.s3.amazonaws.com%2Faccess.json", + "https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/quickcreate?stackName=anything&templateURL=https%3A%2F%2Fcoderhelm-public.s3.amazonaws.com%2Flaunch%2Fv2.0.0%2Faccess.json", + "javascript:alert(1)", + ]) { + await setup(page, SELF, { + signedIn: true, + native: { stack: "coderhelm-prod", can_apply: true, auto_apply: true, pending: null, + access: { state: "pending", version: "v2.0.0", summary: ["adds read access to Airflow"], link, stack: "coderhelm-prod-access", + existing: { link: "https://evil.example.com/" } } }, + }); + await page.goto("/settings/system/"); + await expect(page.getByTestId("native-access")).toBeVisible(); + await expect(page.getByTestId("native-access-link")).toHaveCount(0); + await expect(page.getByTestId("native-access-existing").locator("a")).toHaveCount(0); + } +}); + +test("System: an applied permission change shows nothing; a stuck rollback says what stopped it", async ({ page }) => { + await setup(page, SELF, { + signedIn: true, + native: { stack: "coderhelm-prod", can_apply: true, auto_apply: true, pending: null, + access: { state: "applied", version: "v2.0.0" }, + recovery: { status: "stuck", at: "2026-11-08T14:10:00Z", reason: "Boundary: its policy differs from the release it rolls back to", + link: "https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/events?stackId=x" } }, + }); + await page.goto("/settings/system/"); + await expect(page.getByTestId("native-access")).toHaveCount(0); + const rec = page.getByTestId("native-recovery"); + await expect(rec).toHaveAttribute("data-state", "stuck"); + await expect(rec).toContainText("Boundary: its policy differs from the release it rolls back to"); + await expect(page.getByTestId("native-recovery-link")).toBeVisible(); }); test("System: an older stack without the deploy role says its one console step adds it", async ({ page }) => { diff --git a/dashboard/src/app/settings/system/page.tsx b/dashboard/src/app/settings/system/page.tsx index 4e8e27ff..914df5c4 100644 --- a/dashboard/src/app/settings/system/page.tsx +++ b/dashboard/src/app/settings/system/page.tsx @@ -9,6 +9,7 @@ import { DomainSection } from "@/components/domain-section"; import { HybridSection } from "@/components/hybrid-section"; import { UninstallSection } from "@/components/uninstall-section"; import { NativeUpdateCard, UpdateSteps } from "@/components/native-update"; +import { NativeAccessCard, NativeRecoveryCard } from "@/components/native-access"; import { ModelsSection, UpdateNeedsAction } from "@/components/models-section"; import { CodeBlock } from "@/components/code-block"; import { Code } from "@/components/settings/code"; @@ -315,6 +316,8 @@ function System() { onSkipModel={() => start("update", true)} next={next} /> + + {!busyUpdating && data.current.version && } diff --git a/dashboard/src/components/native-access.tsx b/dashboard/src/components/native-access.tsx new file mode 100644 index 00000000..b8e2de94 --- /dev/null +++ b/dashboard/src/components/native-access.tsx @@ -0,0 +1,121 @@ +"use client"; + +import type { NativeAccess, NativeRecovery } from "@/lib/api"; +import { Callout } from "@/components/callout"; +import { Time } from "@/components/list"; +import { Code } from "@/components/settings/code"; +import { linkButton, primaryButton } from "@/components/ui"; + +/** + * The access stack's quick-create link, only as the updater makes it: the AWS + * console, a quick-create of coderhelm--access from a release's signed + * access.json in the release bucket. Anything else is not linked. + */ +export function safeAccessLink(link: string | null | undefined): string | null { + if (!link) return null; + let u: URL; + try { + u = new URL(link); + } catch { + return null; + } + if (u.protocol !== "https:" || u.hostname !== "console.aws.amazon.com" || u.pathname !== "/cloudformation/home") return null; + const [route, query = ""] = u.hash.replace(/^#/, "").split("?"); + if (route !== "/stacks/quickcreate") return null; + const q = new URLSearchParams(query); + if (!/^coderhelm-[a-z][a-z0-9]{0,19}-access$/.test(q.get("stackName") ?? "")) return null; + if (!/^https:\/\/coderhelm-public\.s3\.amazonaws\.com\/launch\/v\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?\/access\.json$/.test(q.get("templateURL") ?? "")) return null; + return u.toString(); +} + +/** A link to a stack in the CloudFormation console of the install's region, or null. */ +export function safeConsoleLink(link: string | null | undefined): string | null { + if (!link) return null; + let u: URL; + try { + u = new URL(link); + } catch { + return null; + } + if (u.protocol !== "https:" || !/^([a-z]{2}(-gov)?-[a-z]+-\d\.)?console\.aws\.amazon\.com$/.test(u.hostname) || u.pathname !== "/cloudformation/home") return null; + if (!/^#\/stacks\/(stackinfo|events)\?/.test(u.hash)) return null; + return u.toString(); +} + +/** + * A newer permission limit (boundary) or deploy role policy than the install + * has. No update can apply it: the deploy role that runs updates may never + * change itself or a boundary, and the stack runs every change as that role, + * even one an AWS admin executes in the console. So updates install without + * it, and it is its own optional item: one link that creates the install's + * access stack from the release's signed access.json, which runs with the + * AWS admin's own permissions. It never holds an update. + */ +export function NativeAccessCard({ access }: { access: NativeAccess | null | undefined }) { + if (!access || access.state !== "pending") return null; + const lines = access.summary ?? []; + const link = safeAccessLink(access.link); + const existing = safeConsoleLink(access.existing?.link); + return ( +
+ +

+ {access.version ?? "This release"} can do more once this install's permission limit allows it. Updates don't wait for this: + what needs it says so where you use it. +

+ {lines.length ? ( +
    + {lines.map((l) =>
  • {l.charAt(0).toUpperCase() + l.slice(1)}.
  • )} +
+ ) : null} +

+ Coderhelm can't apply this for itself. Someone with administrator rights in the AWS account opens the link, checks the box and + chooses Create stack; it runs with their own permissions and takes about a minute. Deleting that stack later changes nothing. +

+ {access.existing ? ( +

+ The stack {access.stack} exists from an earlier change: delete it first (that changes nothing), then open the link.{" "} + {existing ? Open {access.stack} : null} +

+ ) : null} + {link ? ( +

+ Open in the AWS console +

+ ) : null} +
+
+ ); +} + +/** A rollback AWS couldn't finish (UPDATE_ROLLBACK_FAILED), and what Coderhelm did about it. */ +export function NativeRecoveryCard({ recovery }: { recovery: NativeRecovery | null | undefined }) { + if (!recovery || recovery.status === "recovered" || recovery.status === "failed") return null; + const stuck = recovery.status === "stuck"; + const link = safeConsoleLink(recovery.link); + return ( +
+ +

+ {recovery.at ? <>Since

+ {stuck && link ? ( +

+ See the stack's events in the AWS console +

+ ) : null} +
+
+ ); +} + +function capital(s: string | null | undefined): string { + const t = (s ?? "").trim().replace(/\.$/, ""); + return t ? t.charAt(0).toUpperCase() + t.slice(1) : ""; +} diff --git a/dashboard/src/components/native-update.tsx b/dashboard/src/components/native-update.tsx index f7e59e10..2ec81fd3 100644 --- a/dashboard/src/components/native-update.tsx +++ b/dashboard/src/components/native-update.tsx @@ -173,14 +173,17 @@ export function NativeUpdateCard({

) : waiting ? (

- {p.admin_changes?.length - ? "It changes the deploy role or a permissions boundary, which Coderhelm can't apply for itself. Someone with administrator rights in the AWS account opens it in the AWS console and chooses Execute." - : "This install's stack doesn't have the deploy role yet, so this one update is executed in the AWS console by someone with administrator rights in the account. It adds the role; every update after it applies from here."} + {"This install's stack doesn't have the deploy role yet, so this one update is executed in the AWS console by someone with administrator rights in the account. It adds the role; every update after it applies from here."}

) : phase === "preparing" ? (

Nothing to do yet. It applies by itself once prepared; it only stops to ask if it would replace or remove data.

) : null} {rolesLine} + {p.held?.length ? ( +

+ This install's deploy role and permission limit stay as they are in this update (no update can change them). Any newer permissions are the separate Permissions item below. +

+ ) : null} {waiting ? : null} {p.reason && !waiting ?

{p.reason}

: null} {next} diff --git a/dashboard/src/lib/api.ts b/dashboard/src/lib/api.ts index 5e285379..e1de0983 100644 --- a/dashboard/src/lib/api.ts +++ b/dashboard/src/lib/api.ts @@ -4613,8 +4613,12 @@ export interface NativeChangeSet { data_changes?: string[]; /** Changes to who may do what. */ permission_changes?: string[]; - /** Changes to the deploy role or a boundary: only an AWS admin can apply those. */ + /** Changes to the deploy role or a boundary (an update made with the deploy role never runs them). */ admin_changes?: string[]; + /** IAM calls the deploy role would be refused, found before it ran ("Part.Id: action on arn (denied by Sid)"). */ + preflight?: string[]; + /** The install's own deploy role and boundaries, kept as they are in this update. */ + held?: string[]; /** Whether Coderhelm can apply it here (otherwise: in the AWS console). */ can_apply?: boolean; /** The token of exactly the data and permission changes to confirm ("" when none). */ @@ -4627,6 +4631,39 @@ export interface NativeUpdate { can_apply?: boolean; auto_apply: boolean; pending: NativeChangeSet | null; + /** A newer boundary or deploy role policy than the install has: optional, applied by an AWS admin. */ + access?: NativeAccess | null; + /** A stack whose rollback stopped (UPDATE_ROLLBACK_FAILED), and what the updater did. */ + recovery?: NativeRecovery | null; +} + +/** The install's permissions against its release's access.json (lambda/updater, access_compute). */ +export interface NativeAccess { + /** pending | applied | none (a release before access.json) | unknown */ + state: string; + version?: string; + /** What it adds, in plain words. */ + summary?: string[]; + resources?: string[]; + /** The AWS console's quick-create link for the access stack. */ + link?: string | null; + template_url?: string; + stack?: string; + /** The access stack exists from an earlier change (delete it first). */ + existing?: { status?: string; link?: string } | null; + reason?: string; + error?: string; +} + +export interface NativeRecovery { + /** continuing | recovered | stuck | failed */ + status: string; + at?: string; + reason?: string; + skipped?: string[]; + failed?: string[]; + target?: string; + link?: string; } // ── Deliveries ────────────────────────────────────────────────────────── diff --git a/dashboard/src/lib/openapi-fields.ts b/dashboard/src/lib/openapi-fields.ts index 86ad22ee..1263c3bb 100644 --- a/dashboard/src/lib/openapi-fields.ts +++ b/dashboard/src/lib/openapi-fields.ts @@ -2,7 +2,7 @@ // docs/api/openapi.json. Do not edit; run `npm run openapi:fields` instead. /** The platform commit this was generated from. */ -export const OPENAPI_REF = "5f361c3ff7c755e6f015ad0869df4fde5fd985e5"; +export const OPENAPI_REF = "57cf0414f53f3bcf44f718adec33b8114e7499bf"; /** The fields each public API schema has. */ export interface OpenApiFields {