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
77 changes: 23 additions & 54 deletions dashboard/e2e/aws-install-options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,60 +175,29 @@ async function shot(page: Page, name: string) {
await page.setViewportSize({ width: 1280, height: 800 });
}

test("a permission the next release adds: Update now to add it, then it arrives with the update installing now", async ({ page }) => {
const db = await backend(page, { missing: ["logs:StopQuery"], latest: "v1.5.0" });
await page.goto("/settings/integrations/aws/");
const panel = page.getByTestId(`aws-perms-${INSTALL}`);
await expect(panel.getByRole("heading", { name: "1 permission arrives with the next update" })).toBeVisible();
await expect(panel.locator("section")).toHaveAttribute("data-case", "install");
// Needed now is only the missing permission; the optional reads are apart and collapsed.
const needed = panel.getByTestId(`aws-needed-${INSTALL}`);
await expect(needed).toContainText("logs:StopQuery");
await expect(needed).not.toContainText("Amazon Inspector");
const optional = panel.getByTestId(`aws-optional-${INSTALL}`);
await expect(optional).toContainText("Optional, off: 2 reads");
await expect(optional.getByTestId("aws-optional-inspector")).toBeHidden();
// Never "go to another page and figure it out": the update is right here.
await expect(panel.getByRole("link", { name: /Open Version and updates/ })).toHaveCount(0);
await expect(panel.getByTestId("install-needed-update")).toContainText("v1.5.0 adds it");
await shot(page, "aws-install-update-available");

await panel.getByRole("button", { name: "Update now to add it" }).click();
const press = db.calls.find((c) => c.path === "/api/system/update");
expect(press?.body).toEqual({ accept_permissions: true });
await expect(panel.getByRole("heading", { name: "1 permission arrives with the update installing now" })).toBeVisible();
await expect(panel.getByTestId("install-needed-running")).toContainText("Arrives with the update to v1.5.0 installing now");
await shot(page, "aws-install-update-running");
});

test("this version already grants it: the card says exactly why and offers the fix", async ({ page }) => {
await backend(page, {
missing: ["logs:StopQuery"],
problem: { code: "install_boundary", message: "This install's permission limit doesn't allow 1 of these read-only permissions yet.", fix: "An AWS admin applies the install's access update once (Settings, System, Version, Permissions: one link to the AWS console). No version update can change the limit." },
access: { state: "pending", link: "https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/quickcreate?stackName=coderhelm-prod-access" },
});
await page.goto("/settings/integrations/aws/");
const panel = page.getByTestId(`aws-perms-${INSTALL}`);
await expect(panel.getByRole("heading", { name: "1 permission is blocked by this install's permission limit" })).toBeVisible();
const why = panel.getByTestId("install-needed-boundary");
await expect(why).toContainText("v1.4.0 grants it, but this install's permission limit doesn't allow 1");
await expect(why.getByRole("link", { name: /Open the access update in AWS/ })).toHaveAttribute("href", /stackName=coderhelm-prod-access/);
await expect(panel.getByRole("button", { name: "Update now to add it" })).toHaveCount(0);
await shot(page, "aws-install-current-boundary");
});

test("no newer version and nothing blocks it: what IAM says is missing, on which role, never a claim about the stack", async ({ page }) => {
await backend(page, { missing: ["logs:StopQuery"] });
await page.goto("/settings/integrations/aws/");
const panel = page.getByTestId(`aws-perms-${INSTALL}`);
await expect(panel.getByRole("heading", { name: "1 permission missing from this install's read role" })).toBeVisible();
const why = panel.getByTestId("install-needed-current");
await expect(why).toContainText("IAM's policy simulator says coderhelm-prod-ServiceRole-0a1b2c3d isn't allowed logs:StopQuery");
await expect(why).toContainText("no newer version is out yet");
// Nothing it didn't read: no "your stack grants it", no drift.
await expect(why).not.toContainText(/grants it, yet|drift|changed in AWS/);
await expect(why.getByRole("button", { name: "Check again" })).toBeVisible();
await shot(page, "aws-install-missing-no-update");
test("the install's own account: it updates with the release, and there is nothing to do", async ({ page }) => {
// Whatever is out (a newer version, none) and whatever the check says: never an action.
for (const latest of ["v1.5.0", null]) {
await backend(page, { missing: ["logs:StopQuery"], latest });
await page.goto("/settings/integrations/aws/");
const panel = page.getByTestId(`aws-perms-${INSTALL}`);
await expect(panel.getByRole("heading", { name: "Updates with the release" })).toBeVisible();
await expect(panel.locator("section").first()).toHaveAttribute("data-case", "install");
await expect(panel.getByTestId(`aws-install-reads-${INSTALL}`)).toContainText("Each version update brings it to");
await expect(panel.getByTestId(`aws-install-reads-${INSTALL}`)).toContainText("so there is nothing to do");
// What arrives is listed; the optional reads stay apart and collapsed.
const needed = panel.getByTestId(`aws-needed-${INSTALL}`);
await expect(needed).toContainText("logs:StopQuery");
await expect(needed).not.toContainText("Amazon Inspector");
await expect(panel.getByTestId(`aws-optional-${INSTALL}`)).toContainText("Optional, off: 2 reads");
// Nothing to press and nowhere to go: no update stack, no update button, no warning.
const card = panel.locator("section").first();
await expect(card.getByRole("button")).toHaveCount(0);
await expect(card.getByRole("link")).toHaveCount(0);
await expect(panel.getByRole("link", { name: /Update in AWS/ })).toHaveCount(0);
await expect(panel.getByRole("heading", { name: /Update needed/ })).toHaveCount(0);
await shot(page, latest ? "aws-install-updates-with-release" : "aws-install-updates-with-release-no-newer");
}
});

test("an optional read switches on the install's own stack: review of exactly what it adds, confirm, progress, result", async ({ page }) => {
Expand Down
8 changes: 5 additions & 3 deletions dashboard/e2e/integrations-page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ test("an AWS role without the permissions offers the one-click stack", async ({
await expect(aws.getByRole("switch", { name: "Let agents read Airflow" })).toBeDisabled();
});

test("a self-hosted install's own account never asks for a stack in AWS: the version update brings the permissions", async ({ page }) => {
test("a self-hosted install's own account never asks for anything: the release brings the permissions", async ({ page }) => {
const list = items().map((i) =>
i.id === `aws-${ACCOUNT}`
? {
Expand All @@ -391,8 +391,10 @@ test("a self-hosted install's own account never asks for a stack in AWS: the ver
const aws = row(page, `aws-${ACCOUNT}`);
await control(page, `aws-${ACCOUNT}`, `AWS account ${ACCOUNT}`).click();
const panel = aws.getByTestId(`aws-panel-${ACCOUNT}`);
await expect(panel.getByText(/read-only permissions? arrives? with the next update/)).toBeVisible();
await expect(panel.getByRole("link", { name: "Update from the AWS page" })).toHaveAttribute("href", /\/settings\/integrations\/aws\/?#aws-account-/);
await expect(panel.getByText(/Updates with the release: 12 read-only permissions arrive with the next update/)).toBeVisible();
await expect(panel.getByText(/^Nothing to do\./)).toBeVisible();
// Nothing to press: no update stack, no "update from the AWS page".
await expect(panel.getByRole("link", { name: "Update from the AWS page" })).toHaveCount(0);
await expect(panel.getByText("the install's own AWS account", { exact: false })).toBeVisible();
await expect(aws.getByRole("link", { name: "Update in AWS" })).toHaveCount(0);
await expect(panel.getByText("CoderHelmLogReader")).toHaveCount(0);
Expand Down
69 changes: 42 additions & 27 deletions dashboard/src/components/aws-permissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Callout } from "./callout";
import { CheckIcon, ExternalLinkIcon, WarningIcon, AlertCircleIcon } from "./icons";
import { buttonClass, primaryButton, secondaryButton } from "./ui";
import { Code } from "./settings/code";
import { InstallNeededNow, OptionalReads, installHeader, useInstallStatus } from "./aws-install-options";
import { OptionalReads, useInstallStatus } from "./aws-install-options";

// Whether each connected AWS account's read-only role has every permission
// this release uses, checked live (IAM's policy simulator on the role, or one
Expand Down Expand Up @@ -115,8 +115,8 @@ export function stateLabel(s: AccountPermissions): string {
if (!v) return s.checking ? "Checking permissions" : s.error ? "Couldn't check permissions" : "Not checked yet";
if (v.status === "up_to_date") return "Permissions up to date";
if (v.status === "error") return "Can't check: Coderhelm can't take on the role";
// The install's own account: nothing to do in AWS, its next update brings them.
if (v.install_account) return `${v.missing_count} permission${v.missing_count === 1 ? "" : "s"} ${v.missing_count === 1 ? "arrives" : "arrive"} with the next update`;
// The install's own account: the release brings them to its reader by itself.
if (v.install_account) return "Updates with the release";
return `Update needed: ${v.missing_count} new read-only permission${v.missing_count === 1 ? "" : "s"}`;
}

Expand Down Expand Up @@ -269,13 +269,47 @@ export function PermissionsPanel({ account, perms, canEdit }: { account: string;

const neededGroups = v.abilities.filter((a) => !a.optional && a.missing.length > 0);
const waiting = !!s.pressedAt && !v.problem;
const title = install ? installHeader(v.missing_count, status, v.problem?.code) : stateLabel(s);

// The install's own account: each version update brings this release's
// reads to its CoderHelmLogReader (the access stack's reader update), so
// there is nothing to do here: no update stack, no button, no warning.
if (install) {
const n = v.missing_count;
return (
<div className="flex flex-col gap-3" data-testid={`aws-perms-${account}`}>
<section aria-labelledby={`aws-perms-title-${account}`} className="rounded-lg border border-zinc-800 bg-zinc-900/40" data-case="install">
<div className="flex flex-col gap-3 px-4 py-3">
<div className="min-w-0">
<h3 id={`aws-perms-title-${account}`} className="text-sm font-medium text-zinc-100">
Updates with the release
</h3>
<p className="mt-1 text-sm text-zinc-400" data-testid={`aws-install-reads-${account}`}>
This install&apos;s own account. This release reads a little more from it: {n} read-only permission{n === 1 ? "" : "s"}. Each version
update brings {n === 1 ? "it" : "them"} to <Code>{v.role || "CoderHelmLogReader"}</Code> here by itself, so there is nothing to do. Until
then, Coderhelm skips what needs {n === 1 ? "it" : "them"} and keeps working with the rest.
</p>
</div>
<p className="flex flex-wrap gap-1.5" data-testid={`aws-needed-${account}`}>
{v.missing.map((m) => (
<Code key={m.action} className="!text-xs">
{m.action}
</Code>
))}
</p>
</div>
</section>
{optional}
</div>
);
}

const title = stateLabel(s);
return (
<div className="flex flex-col gap-3" data-testid={`aws-perms-${account}`}>
<section
aria-labelledby={`aws-perms-title-${account}`}
className="overflow-hidden rounded-lg border border-amber-500/30 bg-amber-500/[0.04]"
data-case={install ? "install" : "account"}
data-case="account"
>
<div className="flex flex-col gap-4 p-4 sm:p-5">
<div className="flex items-start gap-3">
Expand All @@ -287,9 +321,7 @@ export function PermissionsPanel({ account, perms, canEdit }: { account: string;
{title}
</h3>
<p className="mt-1 text-sm text-zinc-300">
{install
? "This install's own account. This release reads a little more from it; everything stays read-only, and nothing is needed in AWS."
: `This release reads a little more from account ${v.account}. Everything stays read-only: Coderhelm can list, describe and query, never change anything.`}{" "}
{`This release reads a little more from account ${v.account}. Everything stays read-only: Coderhelm can list, describe and query, never change anything.`}{" "}
Until the role has it, Coderhelm skips what needs it and keeps working with the rest.
</p>
</div>
Expand All @@ -314,23 +346,7 @@ export function PermissionsPanel({ account, perms, canEdit }: { account: string;
</ul>
</div>

{install ? (
<div className="sm:pl-8">
{canEdit ? (
<InstallNeededNow
s={status}
problem={v.problem}
onCheck={() => perms.check(account, true)}
checking={s.checking}
role={v.role}
missing={v.missing.map((m) => m.action)}
/>
) : (
<p className="text-sm text-zinc-400">An admin adds it from this card with the install&apos;s next version update.</p>
)}
</div>
) : (
<>
<>
{v.problem && (
<div className="sm:pl-8">
<Callout variant="error" title={v.problem.message}>
Expand Down Expand Up @@ -377,8 +393,7 @@ export function PermissionsPanel({ account, perms, canEdit }: { account: string;
</div>
)}
{!canEdit && <p className="text-sm text-zinc-400 sm:pl-8">An admin can update the role in one click from this page.</p>}
</>
)}
</>
</div>
</section>
{optional}
Expand Down
9 changes: 2 additions & 7 deletions dashboard/src/components/connections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -422,15 +422,10 @@ export function AwsAbilitiesPanel({
{a.install_account && (missing.length > 0 || a.permissions?.status === "update_needed") && (
<Callout
variant="neutral"
title={`${a.permissions?.missing_count || missing.length || 1} read-only permission${(a.permissions?.missing_count || missing.length || 1) === 1 ? " arrives" : "s arrive"} with the next update`}
title={`Updates with the release: ${a.permissions?.missing_count || missing.length || 1} read-only permission${(a.permissions?.missing_count || missing.length || 1) === 1 ? " arrives" : "s arrive"} with the next update`}
live={false}
>
<p>Nothing is needed in AWS. The AWS page updates Coderhelm in one press, and the install&apos;s own role has them once it finishes.</p>
<p className="mt-2">
<Link href={`/settings/integrations/aws#aws-account-${a.account}`} className={linkButton}>
Update from the AWS page
</Link>
</p>
<p>Nothing to do. Each version update brings this release&apos;s read-only permissions to this account&apos;s read role by itself.</p>
</Callout>
)}
{!a.install_account && (missing.length > 0 || a.permissions?.status === "update_needed") && a.update_url && (
Expand Down
Loading