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

fix: ecr policy warning always throws #25041

Merged
merged 2 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/aws-ecr/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ export class Repository extends RepositoryBase {
* It will fail if a resource section is present at all.
*/
public addToResourcePolicy(statement: iam.PolicyStatement): iam.AddToResourcePolicyResult {
if (statement.resources) {
if (statement.resources.length) {
Annotations.of(this).addWarning('ECR resource policy does not allow resource statements.');
}
if (this.policyDocument === undefined) {
Expand Down
16 changes: 16 additions & 0 deletions packages/aws-cdk-lib/aws-ecr/test/repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,22 @@ describe('repository', () => {
Annotations.fromStack(stack).hasWarning('*', 'ECR resource policy does not allow resource statements.');
});

test('does not warn if repository policy does not have resources', () => {
// GIVEN
const app = new cdk.App();
const stack = new cdk.Stack(app, 'my-stack');
const repo = new ecr.Repository(stack, 'Repo');

// WHEN
repo.addToResourcePolicy(new iam.PolicyStatement({
actions: ['ecr:*'],
principals: [new iam.AnyPrincipal()],
}));

// THEN
Annotations.fromStack(stack).hasNoWarning('*', 'ECR resource policy does not allow resource statements.');
});

test('default encryption configuration', () => {
// GIVEN
const app = new cdk.App();
Expand Down