Skip to content

Commit e04477b

Browse files
authored
Expand ECR GH OIDC Default Policy (#711)
1 parent e198524 commit e04477b

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed
Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,55 @@
11
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)
37
}
48

59
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.
1110
statement {
12-
sid = "AmazonEC2ContainerRegistryPowerUser"
11+
sid = "AllowECRPermissions"
1312
effect = "Allow"
1413
actions = [
15-
"ecr:GetAuthorizationToken",
1614
"ecr:BatchCheckLayerAvailability",
17-
"ecr:GetDownloadUrlForLayer",
18-
"ecr:GetRepositoryPolicy",
19-
"ecr:DescribeRepositories",
20-
"ecr:ListImages",
21-
"ecr:DescribeImages",
15+
"ecr:BatchDeleteImage",
2216
"ecr:BatchGetImage",
17+
"ecr:CompleteLayerUpload",
18+
"ecr:DeleteLifecyclePolicy",
19+
"ecr:DescribeImages",
20+
"ecr:DescribeImageScanFindings",
21+
"ecr:DescribeRepositories",
22+
"ecr:GetAuthorizationToken",
23+
"ecr:GetDownloadUrlForLayer",
2324
"ecr:GetLifecyclePolicy",
2425
"ecr:GetLifecyclePolicyPreview",
25-
"ecr:ListTagsForResource",
26-
"ecr:DescribeImageScanFindings",
26+
"ecr:GetRepositoryPolicy",
2727
"ecr:InitiateLayerUpload",
28-
"ecr:UploadLayerPart",
29-
"ecr:CompleteLayerUpload",
28+
"ecr:ListImages",
3029
"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",
3138
]
39+
resources = local.resources
40+
}
3241

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+
]
3552
resources = ["*"]
3653
}
3754
}
55+

0 commit comments

Comments
 (0)