feat(aws): fail-closed overwrite check, name local connections, disclose removals in import preview

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Opus 5.5 committed 2026-11-14 15:46:05 -08:00
1 parent 664697b151
commit 2dea30f4fb
7 files changed
+165 -31

No files matched your search

@@ -38,6 +38,7 @@ const samplePreview: SettingsImportPreview = {
marketplace_account_token_count: 0,
aws_connections: [],
aws_connection_key_count: 0,
removed_aws_connections: [],
};
function outcome(settings: AppSettings, secretRestoreWarnings: string[] = []): SettingsImportOutcome {
@@ -93,6 +94,8 @@ describe("ImportSettingsModal", () => {
default_region: "us-west-2",
overwrites_existing: true,
overwrites_keys: true,
keys_check_failed: false,
local: { name: "Real Prod", auth: "keys", profile_name: null, default_region: "us-east-1" },
},
{
name: "Dev",
@@ -101,9 +104,14 @@ describe("ImportSettingsModal", () => {
default_region: "eu-west-1",
overwrites_existing: false,
overwrites_keys: false,
keys_check_failed: true,
local: null,
},
],
aws_connection_key_count: 1,
removed_aws_connections: [
{ name: "Old", auth: "profile", profile_name: "old-p", default_region: "ap-south-1" },
],
});
render(<ImportSettingsModal onClose={vi.fn()} onImported={vi.fn()} />);
@@ -113,8 +121,10 @@ describe("ImportSettingsModal", () => {
expect(await screen.findByText(/AWS connection "Prod" \(access keys, us-west-2\)/)).toBeInTheDocument();
expect(screen.getByText(/AWS connection "Dev" \(profile dev-profile, eu-west-1\)/)).toBeInTheDocument();
expect(screen.getByText(/1 AWS access key set$/)).toBeInTheDocument();
expect(screen.getByText(/Overwrites the AWS access keys stored for "Prod"/)).toBeInTheDocument();
expect(screen.getByText(/Replaces your existing AWS connection.*"Prod"/)).toBeInTheDocument();
expect(screen.getByText(/Overwrites the AWS access keys stored for your connection "Real Prod"/)).toBeInTheDocument();
expect(screen.getByText(/Replaces your connection "Real Prod" \(access keys, us-east-1\) with "Prod"/)).toBeInTheDocument();
expect(screen.getByText(/Could not check whether keys are stored for "Dev".*may overwrite them/)).toBeInTheDocument();
expect(screen.getByText(/Removes your AWS connection "Old" \(profile old-p, ap-south-1\)/)).toBeInTheDocument();
});
it("warns about a custom Docker image every time, not just on change", async () => {
@@ -26,6 +26,7 @@ function preview(overrides: Partial<SettingsImportPreview> = {}): SettingsImport
marketplace_account_token_count: 0,
aws_connections: [],
aws_connection_key_count: 0,
removed_aws_connections: [],
...overrides,
};
}
+24 -4
View File
@@ -1,4 +1,4 @@
import type { SettingsImportPreview } from "./types";
import type { AwsConnectionSummary, SettingsImportPreview } from "./types";
/** Named things a `SettingsImportPreview` says an import will change, for
* `ImportSettingsModal`'s confirmation list. Does not include anything
@@ -91,12 +91,27 @@ export function describeImportWarnings(preview: SettingsImportPreview): string[]
);
}
for (const c of preview.aws_connections) {
if (c.overwrites_existing) {
warnings.push(`Replaces your existing AWS connection with different settings: "${c.name}".`);
const localDesc = c.local ? describeAws(c.local) : null;
if (c.overwrites_existing && c.local) {
warnings.push(`Replaces your connection ${localDesc} with "${c.name}" (${c.auth === "keys" ? "access keys" : "profile " + (c.profile_name ?? "")}, ${c.default_region}).`);
}
if (c.overwrites_keys) {
warnings.push(`Overwrites the AWS access keys stored for "${c.name}".`);
warnings.push(
c.local
? `Overwrites the AWS access keys stored for your connection ${localDesc} (imported as "${c.name}").`
: `Overwrites AWS access keys already stored for the imported connection "${c.name}".`,
);
}
if (c.keys_check_failed) {
warnings.push(
`Could not check whether keys are stored for "${c.name}"${c.local ? ` (your connection ${localDesc})` : ""}; importing may overwrite them.`,
);
}
}
for (const r of preview.removed_aws_connections) {
warnings.push(
`Removes your AWS connection ${describeAws(r)}, which is not in the file. Any access keys stored for it stay in your keychain.`,
);
}
if (preview.image_source === "custom") {
warnings.push(
@@ -105,3 +120,8 @@ export function describeImportWarnings(preview: SettingsImportPreview): string[]
}
return warnings;
}
function describeAws(c: AwsConnectionSummary): string {
const auth = c.auth === "keys" ? "access keys" : `profile ${c.profile_name ?? ""}`.trim();
return `"${c.name}" (${auth}, ${c.default_region})`;
}
+13
View File
@@ -429,6 +429,15 @@ export interface SettingsImportPreview {
aws_connections: AwsConnectionPreview[];
/** AWS access-key entries the import restores to the keychain. */
aws_connection_key_count: number;
/** Local AWS connections the import drops (it replaces the whole list). */
removed_aws_connections: AwsConnectionSummary[];
}
export interface AwsConnectionSummary {
name: string;
auth: "profile" | "keys";
profile_name: string | null;
default_region: string;
}
export interface AwsConnectionPreview {
@@ -440,6 +449,10 @@ export interface AwsConnectionPreview {
overwrites_existing: boolean;
/** The import carries keys for an id that already has keys stored here. */
overwrites_keys: boolean;
/** The keychain could not be asked whether keys are already stored. */
keys_check_failed: boolean;
/** The local connection with this id, when the import replaces it. */
local: AwsConnectionSummary | null;
}
/** What `apply_settings_import` returns: the settings that were actually