From 90fae8451f9d3f3d9a69dc0c9dadc7da2a19ffad Mon Sep 17 00:00:00 2001 From: Josh Knapp Date: Tue, 17 Nov 2026 12:19:04 -0800 Subject: [PATCH] fix(aws): review fixes for hosts settings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Runs carry an explicit kind (deploy, follow, repair, update, destroy, onboard, push, boundary); the admin-bundle offer after an AWS refusal keys on kind deploy/onboard, not the label, so a refused follow of an existing environment's deploy no longer offers a new-environment bundle. - looksDenied no longer matches a bare "explicit deny" (SCP and bucket policy denies aren't fixed by a bundle); the hint says it may need an admin. - The aws sso login hint breaks long profile names. - The "Not an admin?" disclosure shows a ▸/▾ marker like the Environments toggle. - Note: the previous commit's Modal footer flex-wrap is app-wide (every modal's buttons now wrap when the dialog is narrow); kept deliberately. Co-Authored-By: Claude Opus 5.5 --- app/src/components/settings/HostsSettings.tsx | 2 +- .../settings/hosts/DeployEnvironmentModal.tsx | 2 +- .../settings/hosts/DeployProgress.test.tsx | 11 ++-- .../settings/hosts/DeployProgress.tsx | 18 +++++- .../settings/hosts/EnvironmentsPanel.test.tsx | 37 ++++++++++++ .../settings/hosts/EnvironmentsPanel.tsx | 58 ++++++++++++------- app/src/lib/aws-error.test.ts | 1 + app/src/lib/aws-error.ts | 6 +- 8 files changed, 102 insertions(+), 33 deletions(-) diff --git a/app/src/components/settings/HostsSettings.tsx b/app/src/components/settings/HostsSettings.tsx index 9a70a49..267d9c6 100644 --- a/app/src/components/settings/HostsSettings.tsx +++ b/app/src/components/settings/HostsSettings.tsx @@ -67,7 +67,7 @@ function ErrorLine({ {awsErrorMessage(failure.error)} {failure.error.kind === "sso_expired" && !onSignIn && ( - Sign in with aws sso login --profile {failure.error.profile} and try again. + Sign in with aws sso login --profile {failure.error.profile} and try again. )} {failure.error.kind === "sso_expired" && onSignIn && ( diff --git a/app/src/components/settings/hosts/DeployEnvironmentModal.tsx b/app/src/components/settings/hosts/DeployEnvironmentModal.tsx index c748ff0..681a56e 100644 --- a/app/src/components/settings/hosts/DeployEnvironmentModal.tsx +++ b/app/src/components/settings/hosts/DeployEnvironmentModal.tsx @@ -83,7 +83,7 @@ export default function DeployEnvironmentModal({ const createBoundary = async () => { setBoundaryError(null); - const err = await boundary.start(BOUNDARY_STATE_KEY, region, "Permissions boundary", () => + const err = await boundary.start(BOUNDARY_STATE_KEY, region, "boundary", "Permissions boundary", () => deployAwsPermissionsBoundary(connectionId, region), ); if (err?.kind === "access_denied") setBundle({ reason: awsErrorMessage(err) }); diff --git a/app/src/components/settings/hosts/DeployProgress.test.tsx b/app/src/components/settings/hosts/DeployProgress.test.tsx index 99c4065..aea4524 100644 --- a/app/src/components/settings/hosts/DeployProgress.test.tsx +++ b/app/src/components/settings/hosts/DeployProgress.test.tsx @@ -29,10 +29,10 @@ describe("useDeployRuns", () => { const onDone = vi.fn(); const { result } = renderHook(() => useDeployRuns(onDone)); await act(async () => { - await result.current.start(KEY, "eu-west-1", "Deploy of main", async () => "eu"); + await result.current.start(KEY, "eu-west-1", "deploy", "Deploy of main", async () => "eu"); }); await act(async () => { - await result.current.start(KEY, "us-east-1", "Deploy of main", async () => "us"); + await result.current.start(KEY, "us-east-1", "deploy", "Deploy of main", async () => "us"); }); expect(handlers.size).toBe(2); emit(progress({ op_id: "eu", state_key: KEY, events: [tofuEvent("eu line")] })); @@ -54,8 +54,8 @@ describe("useDeployRuns", () => { it("removes its progress listeners on unmount", async () => { const { result, unmount } = renderHook(() => useDeployRuns()); await act(async () => { - await result.current.start(KEY, "eu-west-1", "Deploy of main", async () => "a"); - await result.current.start("boundary/terraform.tfstate", "eu-west-1", "Boundary", async () => "b"); + await result.current.start(KEY, "eu-west-1", "deploy", "Deploy of main", async () => "a"); + await result.current.start("boundary/terraform.tfstate", "eu-west-1", "deploy", "Boundary", async () => "b"); }); expect(handlers.size).toBe(2); unmount(); @@ -66,7 +66,7 @@ describe("useDeployRuns", () => { const { result } = renderHook(() => useDeployRuns()); let err: unknown; await act(async () => { - err = await result.current.start(KEY, "eu-west-1", "Deploy of main", async () => { + err = await result.current.start(KEY, "eu-west-1", "deploy", "Deploy of main", async () => { throw { kind: "other", message: "A deployment is already running" }; }); }); @@ -84,6 +84,7 @@ describe("DeployProgress layout", () => { run={{ stateKey: KEY, region: "eu-west-1", + kind: "deploy", label: "Deploy of main", opId: "x", events: [], diff --git a/app/src/components/settings/hosts/DeployProgress.tsx b/app/src/components/settings/hosts/DeployProgress.tsx index f2008e4..2a12c61 100644 --- a/app/src/components/settings/hosts/DeployProgress.tsx +++ b/app/src/components/settings/hosts/DeployProgress.tsx @@ -13,10 +13,18 @@ import Button from "../../ui/Button"; import Modal from "../../ui/Modal"; import StatusIndicator from "../../ui/StatusIndicator"; +/** + * What a run does. Decisions about a run (such as offering an admin bundle + * when AWS refuses it) key on this, never on its label: a follow of an + * existing environment's deploy is labelled like a new deploy. + */ +export type RunKind = "deploy" | "follow" | "repair" | "update" | "destroy" | "onboard" | "push" | "boundary"; + /** One OpenTofu run this view is showing: a start, or a follow of one already running. */ export interface DeployRun { stateKey: string; region: string; + kind: RunKind; label: string; /** Null until the starting command resolves. */ opId: string | null; @@ -57,7 +65,13 @@ export function useDeployRuns( }, []); const start = useCallback( - async (stateKey: string, region: string, label: string, run: () => Promise): Promise => { + async ( + stateKey: string, + region: string, + kind: RunKind, + label: string, + run: () => Promise, + ): Promise => { const k = runKey(region, stateKey); subs.current.get(k)?.unlisten?.(); const sub: Subscription = { unlisten: null }; @@ -94,7 +108,7 @@ export function useDeployRuns( setRuns((prev) => ({ ...prev, - [k]: { stateKey, region, label, opId: null, events: [], done: false, cancellable: false, result: null }, + [k]: { stateKey, region, kind, label, opId: null, events: [], done: false, cancellable: false, result: null }, })); const unlisten = await listen(AWS_DEPLOY_PROGRESS_EVENT, ({ payload }) => { diff --git a/app/src/components/settings/hosts/EnvironmentsPanel.test.tsx b/app/src/components/settings/hosts/EnvironmentsPanel.test.tsx index 30b294b..51edb50 100644 --- a/app/src/components/settings/hosts/EnvironmentsPanel.test.tsx +++ b/app/src/components/settings/hosts/EnvironmentsPanel.test.tsx @@ -168,6 +168,43 @@ describe("EnvironmentsPanel", () => { expect(within(screen.getByRole("dialog")).getByRole("button", { name: "Save bundle to folder…" })).toBeInTheDocument(); }); + it("never offers a new-environment bundle for a refused follow of an existing deploy", async () => { + const key = "environments/dev/terraform.tfstate"; + backend( + () => scan({ environments: [env({ actions: ["follow"], state: { state: "ready" } })] }), + (cmd) => { + if (cmd === "follow_aws_deployment") return "f9"; + throw new Error(`unexpected ${cmd}`); + }, + ); + render(); + await open(); + await waitFor(() => expect(invoke.mock.calls.some((c) => c[0] === "follow_aws_deployment")).toBe(true)); + await screen.findByRole("region", { name: "Deploy of dev progress" }); + emit( + progress({ + op_id: "f9", + state_key: key, + events: [tofuEvent("AccessDenied: User is not authorized to perform ecs:UpdateService", { level: "error" })], + }), + ); + emit(progress({ op_id: "f9", state_key: key, done: true, cancellable: false, result: { ok: false, exit_code: 1, summary: null } })); + expect(await screen.findByText(/Failed \(exit 1\)/)).toBeInTheDocument(); + expect(screen.queryByTestId("denied-hint")).toBeNull(); + }); + + it("marks the not-an-admin disclosure open or closed like the Environments toggle", async () => { + backend(() => scan()); + render(); + await open(); + const options = await screen.findByTestId("not-admin-options"); + const summary = options.querySelector("summary")!; + expect(summary).toHaveTextContent("▸"); + (options as HTMLDetailsElement).open = true; + fireEvent(options, new Event("toggle")); + await waitFor(() => expect(summary).toHaveTextContent("▾")); + }); + it("shows a refused deploy's AWS message and offers the bundle", async () => { backend( () => scan(), diff --git a/app/src/components/settings/hosts/EnvironmentsPanel.tsx b/app/src/components/settings/hosts/EnvironmentsPanel.tsx index 7578a57..af7f80e 100644 --- a/app/src/components/settings/hosts/EnvironmentsPanel.tsx +++ b/app/src/components/settings/hosts/EnvironmentsPanel.tsx @@ -34,7 +34,7 @@ import AdminBundleModal from "./AdminBundleModal"; import UpdateEnvironmentModal from "./UpdateEnvironmentModal"; import DeployEnvironmentModal from "./DeployEnvironmentModal"; import JoinEnvironmentModal from "./JoinEnvironmentModal"; -import DeployProgress, { runKey, useDeployRuns, type DeployRun } from "./DeployProgress"; +import DeployProgress, { runKey, useDeployRuns, type DeployRun, type RunKind } from "./DeployProgress"; import PolicyFiles from "./PolicyFiles"; import { COMMON_REGIONS, @@ -134,18 +134,18 @@ const recordedEc2 = (e: DetectedEnvironment): UserCompute | null => const rowKey = (region: string, name: string) => `${region}:${name}`; /** - * A failed deploy or onboarding that AWS refused a permission for: the bundle - * for an admin is the way on. Repairs and updates of an existing environment - * aren't offered one (an admin bundle deploys a new environment). + * A failed new deploy or self-onboarding started here that AWS refused a + * permission for: the bundle for an admin is the way on. Only those two + * kinds: an environment bundle deploys a *new* environment, so a follow, + * repair or update of an existing one is never offered it. */ function deniedRun(r: DeployRun): "environment" | "user_onboard" | null { + if (r.kind !== "deploy" && r.kind !== "onboard") return null; if (!r.done || !r.result || r.result.ok) return null; const denied = looksDenied(r.result.summary) || r.events.some((e) => e.level === "error" && looksDenied(e.message)); if (!denied) return null; - if (r.stateKey.startsWith("users/")) return "user_onboard"; - if (r.stateKey.startsWith("environments/") && r.label.startsWith("Deploy of ")) return "environment"; - return null; + return r.kind === "deploy" ? "environment" : "user_onboard"; } /** The environment a run's state key belongs to, if any. */ @@ -195,6 +195,7 @@ export default function EnvironmentsPanel({ // onboarding that didn't finish has no record to start from. const lastEc2 = useRef(new Map()); const [copyNote, setCopyNote] = useState(null); + const [notAdminOpen, setNotAdminOpen] = useState(false); const request = useRef(0); const followed = useRef(new Set()); @@ -229,11 +230,18 @@ export default function EnvironmentsPanel({ /** Start a run in `runRegion` (always the region of the scan the action came from). */ const launch = useCallback( - async (runRegion: string, envName: string, stateKey: string, label: string, run: () => Promise) => { + async ( + runRegion: string, + envName: string, + stateKey: string, + kind: RunKind, + label: string, + run: () => Promise, + ) => { const rk = rowKey(runRegion, envName); setRowErrors(({ [rk]: _gone, ...rest }) => rest); setPending((p) => ({ ...p, [rk]: true })); - const err = await start(stateKey, runRegion, label, run); + const err = await start(stateKey, runRegion, kind, label, run); setPending(({ [rk]: _gone, ...rest }) => rest); if (err) setRowErrors((r) => ({ ...r, [rk]: err })); return err; @@ -249,7 +257,7 @@ export default function EnvironmentsPanel({ const seen = runKey(scan.region, key); if (!runs[seen] && !followed.current.has(seen)) { followed.current.add(seen); - void launch(scan.region, name, key, label, () => followAwsDeployment(connection.id, scan.region, key)); + void launch(scan.region, name, key, "follow", label, () => followAwsDeployment(connection.id, scan.region, key)); } }; for (const e of scan.environments) { @@ -280,16 +288,16 @@ export default function EnvironmentsPanel({ const stale = detecting || !current; const deploy = (runRegion: string, name: string, network: NetworkChoice, hours: number) => - launch(runRegion, name, environmentStateKey(name), `Deploy of ${name}`, () => + launch(runRegion, name, environmentStateKey(name), "deploy", `Deploy of ${name}`, () => deployAwsEnvironment(connection.id, runRegion, name, network, hours), ); // Without `hours`, the environment's recorded cap is kept. const repair = (runRegion: string, name: string, network?: NetworkChoice, hours?: number) => - launch(runRegion, name, environmentStateKey(name), `Repair of ${name}`, () => + launch(runRegion, name, environmentStateKey(name), "repair", `Repair of ${name}`, () => repairAwsEnvironment(connection.id, runRegion, name, network, hours), ); const update = (runRegion: string, name: string, hours: number) => - launch(runRegion, name, environmentStateKey(name), `Update of ${name}`, () => + launch(runRegion, name, environmentStateKey(name), "update", `Update of ${name}`, () => updateAwsEnvironment(connection.id, runRegion, name, hours), ); @@ -315,7 +323,7 @@ export default function EnvironmentsPanel({ const { kind: _kind, ...c } = ec2; lastEc2.current.set(key, c); } else lastEc2.current.delete(key); - return launch(j.region, j.name, j.stateKey, `Joining ${j.name}`, () => onboardAwsUser(connection.id, j.region, j.name, ec2)); + return launch(j.region, j.name, j.stateKey, "onboard", `Joining ${j.name}`, () => onboardAwsUser(connection.id, j.region, j.name, ec2)); }; const rowRuns = (name: string) => @@ -337,7 +345,7 @@ export default function EnvironmentsPanel({ {offer && (

- AWS refused a permission this run needs (its message is above).{" "} + AWS refused a permission this run needs (its message is above). This may need an admin:{" "} {denied === "environment" ? "An admin can deploy the environment for you from a bundle." : "An admin can onboard you from a bundle."} @@ -477,7 +485,7 @@ export default function EnvironmentsPanel({ disabled={busy} aria-label={`Follow my onboarding to ${e.name}`} onClick={() => - void launch(at, e.name, myKey, `Joining ${e.name}`, () => followAwsDeployment(connection.id, at, myKey)) + void launch(at, e.name, myKey, "follow", `Joining ${e.name}`, () => followAwsDeployment(connection.id, at, myKey)) } > Follow @@ -489,7 +497,7 @@ export default function EnvironmentsPanel({ disabled={busy} aria-label={`Push saved state of my onboarding to ${e.name}`} onClick={() => - void launch(at, e.name, myKey, `Push of the saved state of joining ${e.name}`, () => + void launch(at, e.name, myKey, "push", `Push of the saved state of joining ${e.name}`, () => pushAwsSavedState(connection.id, at, myKey), ) } @@ -515,7 +523,7 @@ export default function EnvironmentsPanel({ aria-label={`Push saved state of ${e.name}`} onClick={() => { const key = environmentStateKey(e.name); - void launch(at, e.name, key, `Push of the saved state of ${e.name}`, () => + void launch(at, e.name, key, "push", `Push of the saved state of ${e.name}`, () => pushAwsSavedState(connection.id, at, key), ); }} @@ -530,7 +538,7 @@ export default function EnvironmentsPanel({ aria-label={`Follow ${e.name}`} onClick={() => { const key = environmentStateKey(e.name); - void launch(at, e.name, key, `Deploy of ${e.name}`, () => followAwsDeployment(connection.id, at, key)); + void launch(at, e.name, key, "follow", `Deploy of ${e.name}`, () => followAwsDeployment(connection.id, at, key)); }} > Follow @@ -662,8 +670,14 @@ export default function EnvironmentsPanel({

)} {!isAdmin && ( -
- +
setNotAdminOpen(ev.currentTarget.open)} + > + + Not an admin? Ask one to deploy it
@@ -727,7 +741,7 @@ export default function EnvironmentsPanel({ confirmLabel="Destroy" onClose={() => setDestroyOf(null)} onConfirm={() => - launch(destroyOf.region, destroyOf.name, environmentStateKey(destroyOf.name), `Destroy of ${destroyOf.name}`, () => + launch(destroyOf.region, destroyOf.name, environmentStateKey(destroyOf.name), "destroy", `Destroy of ${destroyOf.name}`, () => destroyIncompleteAwsEnvironment(connection.id, destroyOf.region, destroyOf.name), ) } diff --git a/app/src/lib/aws-error.test.ts b/app/src/lib/aws-error.test.ts index 373b3b7..e143f3d 100644 --- a/app/src/lib/aws-error.test.ts +++ b/app/src/lib/aws-error.test.ts @@ -36,5 +36,6 @@ describe("access denied", () => { expect(looksDenied("api error UnauthorizedOperation: You are not authorized")).toBe(true); expect(looksDenied("Error: creating VPC: VpcLimitExceeded")).toBe(false); expect(looksDenied(null)).toBe(false); + expect(looksDenied("blocked by an explicit deny in a service control policy")).toBe(false); }); }); diff --git a/app/src/lib/aws-error.ts b/app/src/lib/aws-error.ts index 078af11..d8f64df 100644 --- a/app/src/lib/aws-error.ts +++ b/app/src/lib/aws-error.ts @@ -44,8 +44,10 @@ export function awsErrorMessage(e: AwsError): string { } } -// The codes `aws::error` maps to access_denied, and how AWS words a refusal in OpenTofu's output. -const DENIED = /AccessDenied|UnauthorizedOperation|not authorized to perform|explicit deny/i; +// The codes `aws::error` maps to access_denied, and how AWS words a refusal in +// OpenTofu's output. A bare "explicit deny" is left out: an SCP or bucket +// policy deny isn't something an admin bundle fixes. +const DENIED = /AccessDenied|UnauthorizedOperation|not authorized to perform/i; /** Whether a line of OpenTofu output (or a run's summary) reads as AWS refusing a permission. */ export function looksDenied(text: string | null | undefined): boolean {