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

ecr: grant methods cause circular references in generated templates #2473

Closed
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container bug This issue is a bug.

Comments

@otterley
Copy link
Contributor

otterley commented May 3, 2019

The grant* methods on the ecr.Repository class incorrectly add self-references to the repository's policies, leading to a circular reference error.

Example code:

const repo = new ecr.Repository(this, 'TestHarnessRepo', {
    repositoryName: props.repoName,
});
repo.grantPull(principal);

Rendered template (in relevant part):

TestHarnessRepoAA7E9724:
    Type: AWS::ECR::Repository
    Properties:
      RepositoryName: codebuild-inspec-test-harness
      RepositoryPolicyText:
        Statement:
          - Action:
              - ecr:BatchCheckLayerAvailability
              - ecr:GetDownloadUrlForLayer
              - ecr:BatchGetImage
            Effect: Allow
            Principal:
              Service:
                Fn::Join:
                  - ""
                  - - codebuild.
                    - Ref: AWS::URLSuffix
            Resource:
              Fn::GetAtt:
                - TestHarnessRepoAA7E9724 # !!!! this is the problem
                - Arn

ECR repository policies do not require resources to be defined (or they can be set to *) -- see the documentation for examples.

@otterley otterley added the bug This issue is a bug. label May 3, 2019
@otterley otterley changed the title ecr: grant methods cause circular references in generate template ecr: grant methods cause circular references in generated templates May 3, 2019
@otterley
Copy link
Contributor Author

otterley commented May 3, 2019

A workaround for the moment is to use the addToResourcePolicy method on the repo instead.

@RomainMuller RomainMuller added the @aws-cdk/aws-ecs Related to Amazon Elastic Container label Jun 26, 2019
rix0rrr added a commit that referenced this issue Jul 5, 2019
When granting to a cross-account principal the repository would
use a self-reference to obtain the right ARN to use in its own
resource policy, which can obviously never work.

The solution is to use a '*' resource ARN.

Fixes #2473.
eladb pushed a commit that referenced this issue Jul 7, 2019
When granting to a cross-account principal the repository would
use a self-reference to obtain the right ARN to use in its own
resource policy, which can obviously never work.

The solution is to use a '*' resource ARN.

Fixes #2473.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment