Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update bucket ownership message #127

Merged
merged 7 commits into from
Oct 10, 2024
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
18 changes: 17 additions & 1 deletion lib/private/handlers/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,23 @@ export class FileAssetHandler implements IAssetHandler {
case BucketOwnership.SOMEONE_ELSES_AND_HAVE_ACCESS:
if (!allowCrossAccount) {
throw new Error(
`Bucket named '${destination.bucketName}' exists, but not in account ${await account()}. Wrong account?`
`❗❗ UNEXPECTED BUCKET OWNER DETECTED ❗❗

We've detected that the S3 bucket ${destination.bucketName} was
originally created in account ${await account()} as part of the CloudFormation stack CDKToolkit,
but now resides in a different AWS account. To prevent cross-account asset bucket access of your
deployments, CDK will stop now.

If this situation is intentional and you own the AWS account that the bucket has moved to, remove the
resource named StagingBucket from the template of CloudFormation stack CDKToolkit and try again.

If this situation is not intentional, we strongly recommend auditing your account to make sure all
resources are configured the way you expect them [1]. For questions or concerns, please contact
AWS Support [2].

[1] https://repost.aws/knowledge-center/potential-account-compromise

[2] https://aws.amazon.com/support`
);
}
break;
Expand Down
4 changes: 3 additions & 1 deletion test/files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,9 @@ test('fails when cross account is required but not allowed', async () => {
return { promise: () => Promise.resolve() };
});

await expect(pub.publish({ allowCrossAccount: false })).rejects.toThrow('Wrong account?');
await expect(pub.publish({ allowCrossAccount: false })).rejects.toThrow(
'❗❗ UNEXPECTED BUCKET OWNER DETECTED ❗❗'
);
});

test('succeeds when bucket doesnt belong to us but doesnt contain account id - cross account', async () => {
Expand Down