fix(aws): review fixes for hosts settings
Secret Scan / scan (push) Successful in 8s
Build App (Preview) / compute-version (pull_request) Successful in 6s
Secret Scan / scan (pull_request) Successful in 14s
Build App (Preview) / create-release (pull_request) Successful in 2s
Build App (Preview) / test (pull_request) Successful in 9m36s
Build App (Preview) / build-macos (pull_request) Successful in 6m14s
Build App (Preview) / build-windows (pull_request) Successful in 11m11s
Build App (Preview) / build-linux (pull_request) Successful in 21m26s
Build App (Preview) / prune-previews (pull_request) Successful in 3s

- 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 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Opus 5.5 committed 2026-11-17 12:19:04 -08:00
1 parent a93a8135be
commit 90fae8451f
8 files changed
+102 -33

No files matched your search

@@ -67,7 +67,7 @@ function ErrorLine({
<span className="min-w-0 break-words">{awsErrorMessage(failure.error)}</span>
{failure.error.kind === "sso_expired" && !onSignIn && (
<span>
Sign in with <code>aws sso login --profile {failure.error.profile}</code> and try again.
Sign in with <code className="break-all">aws sso login --profile {failure.error.profile}</code> and try again.
</span>
)}
{failure.error.kind === "sso_expired" && onSignIn && (
@@ -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) });
@@ -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: [],
@@ -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<string>): Promise<AwsError | null> => {
async (
stateKey: string,
region: string,
kind: RunKind,
label: string,
run: () => Promise<string>,
): Promise<AwsError | null> => {
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<ProgressPayload>(AWS_DEPLOY_PROGRESS_EVENT, ({ payload }) => {
@@ -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(<EnvironmentsPanel connection={conn} tier="workspace_user" />);
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(<EnvironmentsPanel connection={conn} tier="workspace_user" />);
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(),
@@ -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<string, Ec2Compute>());
const [copyNote, setCopyNote] = useState<string | null>(null);
const [notAdminOpen, setNotAdminOpen] = useState(false);
const request = useRef(0);
const followed = useRef(new Set<string>());
@@ -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<string>) => {
async (
runRegion: string,
envName: string,
stateKey: string,
kind: RunKind,
label: string,
run: () => Promise<string>,
) => {
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 && (
<div className="space-y-1.5 text-xs text-[var(--text-secondary)] leading-snug" data-testid="denied-hint">
<p className="break-words">
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({
</p>
)}
{!isAdmin && (
<details className="text-xs min-w-0" data-testid="not-admin-options">
<summary className="cursor-pointer text-[var(--text-primary)] break-words">
<details
className="text-xs min-w-0"
data-testid="not-admin-options"
open={notAdminOpen}
onToggle={(ev) => setNotAdminOpen(ev.currentTarget.open)}
>
<summary className="cursor-pointer list-none [&::-webkit-details-marker]:hidden text-[var(--text-primary)] break-words">
<span aria-hidden="true" className="mr-1">{notAdminOpen ? "▾" : "▸"}</span>
Not an admin? Ask one to deploy it
</summary>
<div className="mt-1.5 space-y-2 min-w-0">
@@ -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),
)
}
+1
View File
@@ -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);
});
});
+4 -2
View File
@@ -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 {