Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 52 additions & 9 deletions dashboard/e2e/selfhost.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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&param_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 }) => {
Expand Down
3 changes: 3 additions & 0 deletions dashboard/src/app/settings/system/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -315,6 +316,8 @@ function System() {
onSkipModel={() => start("update", true)}
next={next}
/>
<NativeRecoveryCard recovery={data.native?.recovery} />
<NativeAccessCard access={data.native?.access} />
{!busyUpdating && data.current.version && <ReleaseCheck data={data} onChecked={setData} />}
<SettingsMore summary="Technical details">
<VersionDetails version={data} autoUpdates={!!data.settings?.auto} failure={failure} />
Expand Down
121 changes: 121 additions & 0 deletions dashboard/src/components/native-access.tsx
Original file line number Diff line number Diff line change
@@ -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-<name>-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 (
<div data-testid="native-access" data-state="pending">
<Callout variant="info" title="Permissions: optional, for an AWS admin">
<p>
{access.version ?? "This release"} can do more once this install&apos;s permission limit allows it. Updates don&apos;t wait for this:
what needs it says so where you use it.
</p>
{lines.length ? (
<ul className="mt-2 list-disc space-y-1 pl-5" data-testid="native-access-summary">
{lines.map((l) => <li key={l}>{l.charAt(0).toUpperCase() + l.slice(1)}.</li>)}
</ul>
) : null}
<p className="mt-2">
Coderhelm can&apos;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.
</p>
{access.existing ? (
<p className="mt-2" data-testid="native-access-existing">
The stack <Code className="text-xs">{access.stack}</Code> exists from an earlier change: delete it first (that changes nothing), then open the link.{" "}
{existing ? <a href={existing} target="_blank" rel="noopener noreferrer" className={linkButton}>Open {access.stack}</a> : null}
</p>
) : null}
{link ? (
<p className="mt-3">
<a href={link} target="_blank" rel="noopener noreferrer" className={primaryButton} data-testid="native-access-link">Open in the AWS console</a>
</p>
) : null}
</Callout>
</div>
);
}

/** 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 (
<div data-testid="native-recovery" data-state={recovery.status}>
<Callout
variant={stuck ? "warning" : "info"}
title={stuck ? "The last update's rollback stopped, and Coderhelm couldn't finish it safely" : "Finishing the last update's rollback…"}
>
<p>
{recovery.at ? <>Since <Time iso={recovery.at} />. </> : null}
{stuck
? `Coderhelm keeps running, but no update can start until the rollback finishes. ${capital(recovery.reason)}.`
: `${capital(recovery.reason)}. No update can start until it finishes; this page follows it by itself.`}
</p>
{stuck && link ? (
<p className="mt-2">
<a href={link} target="_blank" rel="noopener noreferrer" className={linkButton} data-testid="native-recovery-link">See the stack&apos;s events in the AWS console</a>
</p>
) : null}
</Callout>
</div>
);
}

function capital(s: string | null | undefined): string {
const t = (s ?? "").trim().replace(/\.$/, "");
return t ? t.charAt(0).toUpperCase() + t.slice(1) : "";
}
9 changes: 6 additions & 3 deletions dashboard/src/components/native-update.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,17 @@ export function NativeUpdateCard({
</p>
) : waiting ? (
<p className="mt-2" data-testid="native-update-hold">
{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."}
</p>
) : phase === "preparing" ? (
<p className="mt-2">Nothing to do yet. It applies by itself once prepared; it only stops to ask if it would replace or remove data.</p>
) : null}
{rolesLine}
{p.held?.length ? (
<p className="mt-2 text-zinc-400" data-testid="native-update-held">
This install&apos;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.
</p>
) : null}
{waiting ? <UpdateSteps at="apply" waiting={canApply ? "waits for your OK" : "waits for an AWS admin"} /> : null}
{p.reason && !waiting ? <p className="mt-2 text-zinc-400">{p.reason}</p> : null}
{next}
Expand Down
39 changes: 38 additions & 1 deletion dashboard/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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). */
Expand All @@ -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 ──────────────────────────────────────────────────────────
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/lib/openapi-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading