|
| 1 | +locals { |
| 2 | + github_actions_iam_policy = data.aws_iam_policy_document.github_actions_iam_policy.json |
| 3 | + ecr_resources_static = [for k, v in module.ecr.repository_arn_map : v] |
| 4 | + ecr_resources_wildcard = [for k, v in module.ecr.repository_arn_map : "${v}/*"] |
| 5 | + resources = concat(local.ecr_resources_static, local.ecr_resources_wildcard) |
| 6 | +} |
| 7 | + |
| 8 | +data "aws_iam_policy_document" "github_actions_iam_policy" { |
| 9 | + statement { |
| 10 | + sid = "AllowECRPermissions" |
| 11 | + effect = "Allow" |
| 12 | + actions = [ |
| 13 | + "ecr:BatchCheckLayerAvailability", |
| 14 | + "ecr:BatchDeleteImage", |
| 15 | + "ecr:BatchGetImage", |
| 16 | + "ecr:CompleteLayerUpload", |
| 17 | + "ecr:DeleteLifecyclePolicy", |
| 18 | + "ecr:DescribeImages", |
| 19 | + "ecr:DescribeImageScanFindings", |
| 20 | + "ecr:DescribeRepositories", |
| 21 | + "ecr:GetAuthorizationToken", |
| 22 | + "ecr:GetDownloadUrlForLayer", |
| 23 | + "ecr:GetLifecyclePolicy", |
| 24 | + "ecr:GetLifecyclePolicyPreview", |
| 25 | + "ecr:GetRepositoryPolicy", |
| 26 | + "ecr:InitiateLayerUpload", |
| 27 | + "ecr:ListImages", |
| 28 | + "ecr:PutImage", |
| 29 | + "ecr:PutImageScanningConfiguration", |
| 30 | + "ecr:PutImageTagMutability", |
| 31 | + "ecr:PutLifecyclePolicy", |
| 32 | + "ecr:StartImageScan", |
| 33 | + "ecr:StartLifecyclePolicyPreview", |
| 34 | + "ecr:TagResource", |
| 35 | + "ecr:UntagResource", |
| 36 | + "ecr:UploadLayerPart", |
| 37 | + ] |
| 38 | + resources = local.resources |
| 39 | + } |
| 40 | + |
| 41 | + # required as minimum permissions for pushing and logging into a public ECR repository |
| 42 | + # https://github.com/aws-actions/amazon-ecr-login#permissions |
| 43 | + # https://docs.aws.amazon.com/AmazonECR/latest/public/docker-push-ecr-image.html |
| 44 | + statement { |
| 45 | + sid = "AllowEcrGetAuthorizationToken" |
| 46 | + effect = "Allow" |
| 47 | + actions = [ |
| 48 | + "ecr:GetAuthorizationToken", |
| 49 | + "sts:GetServiceBearerToken" |
| 50 | + ] |
| 51 | + resources = ["*"] |
| 52 | + } |
| 53 | +} |
0 commit comments