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): repository grant uses correct resource ARN #3220

Merged
merged 1 commit into from
Jul 7, 2019
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
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-ecr/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export abstract class RepositoryBase extends Resource implements IRepository {
grantee,
actions,
resourceArns: [this.repositoryArn],
resourceSelfArns: ['*'],
resource: this,
});
}
Expand Down
33 changes: 31 additions & 2 deletions packages/@aws-cdk/aws-ecr/test/test.repository.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, haveResource, haveResourceLike, ResourcePart } from '@aws-cdk/assert';
import iam = require('@aws-cdk/aws-iam');
import cdk = require('@aws-cdk/core');
import { RemovalPolicy } from '@aws-cdk/core';
import { RemovalPolicy, Stack } from '@aws-cdk/core';
import { Test } from 'nodeunit';
import ecr = require('../lib');

Expand Down Expand Up @@ -352,6 +352,35 @@ export = {
"DeletionPolicy": "Delete"
}, ResourcePart.CompleteDefinition));
test.done();
}
},

'grant adds appropriate resource-*'(test: Test) {
// GIVEN
const stack = new Stack();
const repo = new ecr.Repository(stack, 'TestHarnessRepo');

// WHEN
repo.grantPull(new iam.AnyPrincipal());

// THEN
expect(stack).to(haveResource('AWS::ECR::Repository', {
"RepositoryPolicyText": {
"Statement": [
{
"Action": [
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage"
],
"Effect": "Allow",
"Principal": "*",
"Resource": "*",
}
],
"Version": "2012-10-17"
}
}));

test.done();
},
};