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 deployment role contains wildcard permissions #494

Open
kukushking opened this issue Jan 23, 2024 · 2 comments
Open

ECR deployment role contains wildcard permissions #494

kukushking opened this issue Jan 23, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@kukushking
Copy link

ECRDeployment construct always adds a default policy (below) that contains wildcard permissions to the ECR deployment role, even if a custom role is passed to the construct. This unfortunately fails CDK-nag security checks, and requires suppression rules.

I would like to be able to implement least-privilege IAM policies i.e. limit IAM actions to the specific repo/s3 bucket arn.

If a custom role is passed, I expect as the default behavior to not have any additional policies added to the role.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "ecr:GetAuthorizationToken",
                "ecr:BatchCheckLayerAvailability",
                "ecr:GetDownloadUrlForLayer",
                "ecr:GetRepositoryPolicy",
                "ecr:DescribeRepositories",
                "ecr:ListImages",
                "ecr:DescribeImages",
                "ecr:BatchGetImage",
                "ecr:ListTagsForResource",
                "ecr:DescribeImageScanFindings",
                "ecr:InitiateLayerUpload",
                "ecr:UploadLayerPart",
                "ecr:CompleteLayerUpload",
                "ecr:PutImage"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Action": "s3:GetObject",
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}
@ndrpp
Copy link

ndrpp commented Aug 19, 2024

Can't this be solved by putting a .withoutPolicyUpdates() after the role?
example:

   const ecrDeploy = new ecrdeploy.ECRDeployment(this, deploymentName, {
      src,
      dest,
      role: myRole.withoutPolicyUpdates()
    })

@mrgrain mrgrain added the enhancement New feature or request label Oct 16, 2024
@athewsey
Copy link

Even apart from the permissions themselves, I'm having trouble suppressing the generated CDK-Nag errors - I think because of the use of a Singleton Lambda? For example the below within a Construct does not suppress the error:

    const deployment = new ecrDeploy.ECRDeployment(this, "Deployment", {...});
    NagSuppressions.addResourceSuppressions(
      deployment,
      [
        {
          id: "AwsSolutions-IAM4",
          reason: "Can't control managed policies within ECRDeployment resource",
        },
        {
          id: "AwsSolutions-IAM5",
          reason: "Can't control wildcard policies within ECRDeployment resource",
        },
      ],
      true,  // Even with applyToChildren=true
    );

...Because the generated resource that causes the violation is at:

/{path-to-containing-substack}/Custom::CDKECRDeployment{long-alphanumeric}/ServiceRole/DefaultPolicy/Resource

...NOT under the deployment construct itself or even the this parent construct that creates it.

Since ECRDeployment.handler is private, I can't find any more granular way than to suppress the errors on cdk.Stack.of(this) with applyToChildren=true: Ignoring ALL IAM4 and IAM5 violations on the entire (nested) stack.

I understand this could be worked around by passing a custom role, but has anybody found a good way to suppress the CDK-Nag warnings when allowing ECRDeployment to create its own singleton role?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants