|
1 | 1 | locals { |
2 | | - github_actions_iam_policy = join("", data.aws_iam_policy_document.github_actions_iam_policy.*.json) |
| 2 | + enabled = module.this.enabled |
| 3 | + github_actions_iam_policy = data.aws_iam_policy_document.github_actions_iam_policy.json |
| 4 | + ecr_resources_static = [for k, v in module.ecr.repository_arn_map : v] |
| 5 | + ecr_resources_wildcard = [for k, v in module.ecr.repository_arn_map : "${v}/*"] |
| 6 | + resources = concat(local.ecr_resources_static, local.ecr_resources_wildcard) |
3 | 7 | } |
4 | 8 |
|
5 | 9 | data "aws_iam_policy_document" "github_actions_iam_policy" { |
6 | | - count = var.github_actions_iam_role_enabled ? 1 : 0 |
7 | | - |
8 | | - # Permissions copied from https://docs.aws.amazon.com/AmazonECR/latest/userguide/security-iam-awsmanpol.html#security-iam-awsmanpol-AmazonEC2ContainerRegistryPowerUser |
9 | | - # This policy grants administrative permissions that allow IAM users to read and write to repositories, |
10 | | - # but doesn't allow them to delete repositories or change the policy documents that are applied to them. |
11 | 10 | statement { |
12 | | - sid = "AmazonEC2ContainerRegistryPowerUser" |
| 11 | + sid = "AllowECRPermissions" |
13 | 12 | effect = "Allow" |
14 | 13 | actions = [ |
15 | | - "ecr:GetAuthorizationToken", |
16 | 14 | "ecr:BatchCheckLayerAvailability", |
17 | | - "ecr:GetDownloadUrlForLayer", |
18 | | - "ecr:GetRepositoryPolicy", |
19 | | - "ecr:DescribeRepositories", |
20 | | - "ecr:ListImages", |
21 | | - "ecr:DescribeImages", |
| 15 | + "ecr:BatchDeleteImage", |
22 | 16 | "ecr:BatchGetImage", |
| 17 | + "ecr:CompleteLayerUpload", |
| 18 | + "ecr:DeleteLifecyclePolicy", |
| 19 | + "ecr:DescribeImages", |
| 20 | + "ecr:DescribeImageScanFindings", |
| 21 | + "ecr:DescribeRepositories", |
| 22 | + "ecr:GetAuthorizationToken", |
| 23 | + "ecr:GetDownloadUrlForLayer", |
23 | 24 | "ecr:GetLifecyclePolicy", |
24 | 25 | "ecr:GetLifecyclePolicyPreview", |
25 | | - "ecr:ListTagsForResource", |
26 | | - "ecr:DescribeImageScanFindings", |
| 26 | + "ecr:GetRepositoryPolicy", |
27 | 27 | "ecr:InitiateLayerUpload", |
28 | | - "ecr:UploadLayerPart", |
29 | | - "ecr:CompleteLayerUpload", |
| 28 | + "ecr:ListImages", |
30 | 29 | "ecr:PutImage", |
| 30 | + "ecr:PutImageScanningConfiguration", |
| 31 | + "ecr:PutImageTagMutability", |
| 32 | + "ecr:PutLifecyclePolicy", |
| 33 | + "ecr:StartImageScan", |
| 34 | + "ecr:StartLifecyclePolicyPreview", |
| 35 | + "ecr:TagResource", |
| 36 | + "ecr:UntagResource", |
| 37 | + "ecr:UploadLayerPart", |
31 | 38 | ] |
| 39 | + resources = local.resources |
| 40 | + } |
32 | 41 |
|
33 | | - #bridgecrew:skip=BC_AWS_IAM_57:OK to allow write access to all ECRs because ECRs have their own access policies |
34 | | - # and this policy prohibits the user from making changes to the access policy. |
| 42 | + # required as minimum permissions for pushing and logging into a public ECR repository |
| 43 | + # https://github.com/aws-actions/amazon-ecr-login#permissions |
| 44 | + # https://docs.aws.amazon.com/AmazonECR/latest/public/docker-push-ecr-image.html |
| 45 | + statement { |
| 46 | + sid = "AllowEcrGetAuthorizationToken" |
| 47 | + effect = "Allow" |
| 48 | + actions = [ |
| 49 | + "ecr:GetAuthorizationToken", |
| 50 | + "sts:GetServiceBearerToken" |
| 51 | + ] |
35 | 52 | resources = ["*"] |
36 | 53 | } |
37 | 54 | } |
| 55 | + |
0 commit comments