Skip to content

Commit

Permalink
Merge pull request #1372 from alphagov/add-pull-from-ecr-policy
Browse files Browse the repository at this point in the history
Add pull-through ECR permissions for EKS nodes
  • Loading branch information
theseanything authored Jul 8, 2024
2 parents e11be35 + d6f59c4 commit f536f33
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion terraform/deployments/cluster-infrastructure/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,41 @@ resource "aws_iam_role" "node" {
force_detach_policies = true
}

data "aws_iam_policy_document" "pull_from_ecr" {
statement {
actions = [
"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:GetRepositoryPolicy",
"ecr:DescribeRepositories",
"ecr:ListImages",
"ecr:DescribeImages",
"ecr:BatchGetImage",
"ecr:BatchImportUpstreamImage",
"ecr:GetLifecyclePolicy",
"ecr:GetLifecyclePolicyPreview",
"ecr:ListTagsForResource",
"ecr:DescribeImageScanFindings"
]

effect = "Allow"
resources = ["*"]
}
}

resource "aws_iam_policy" "pull_from_ecr" {
name = "pull-from-ecr"
description = "Policy to allows EKS to pull images from ECR"
policy = data.aws_iam_policy_document.pull_from_ecr.json
}

resource "aws_iam_role_policy_attachment" "node" {
for_each = toset([
"AmazonEKSWorkerNodePolicy",
"AmazonEC2ContainerRegistryReadOnly",
"AmazonEKS_CNI_Policy",
"AmazonSSMManagedInstanceCore",
aws_iam_policy.pull_from_ecr.name,
])
policy_arn = "arn:aws:iam::aws:policy/${each.key}"
role = aws_iam_role.node.name
Expand Down

0 comments on commit f536f33

Please sign in to comment.