Skip to content

Commit

Permalink
feat: Add an ECR role to allow pulling images
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyovriakh committed Feb 28, 2024
1 parent 5dcf592 commit bc7dbd7
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
73 changes: 73 additions & 0 deletions modules/services/eks/iam.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// This is a Single Account installation. The resources are created globally (instead of regionally).

data "aws_iam_policy_document" "ecr_pull_image" {
count = local.n

statement {
sid = "SysdigEcrPullImagePermissions"

effect = "Allow"

actions = [
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
"ecr:BatchCheckLayerAvailability",
"ecr:ListImages",
"ecr:GetAuthorizationToken",
]

resources = [
"*",
]
}
}

resource "aws_iam_policy" "ecr_pull_image" {
count = local.n

name = var.name
description = "Allows Sysdig Secure to pull ECR images"
policy = data.aws_iam_policy_document.ecr_pull_image[0].json
tags = var.tags
}

data "aws_iam_policy_document" "ecr_assume_role" {
count = local.n

statement {
sid = "SysdigEcrAssumeRole"

actions = [
"sts:AssumeRole"
]

principals {
type = "AWS"
identifiers = [
var.trusted_identity,
]
}

condition {
test = "StringEquals"
variable = "sts:ExternalId"
values = [var.external_id]
}
}
}

resource "aws_iam_role" "ecr" {
count = local.n

name = var.name
tags = var.tags
assume_role_policy = data.aws_iam_policy_document.ecr_assume_role[0].json
}

resource "aws_iam_policy_attachment" "ecr" {
count = local.n

name = var.name
roles = [aws_iam_role.ecr[0].name]
policy_arn = aws_iam_policy.ecr_pull_image[0].arn
}
3 changes: 3 additions & 0 deletions modules/services/eks/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ locals {
}
policy_arn = local.eks_view_policy
}

// ECR role to pull images
n = var.deploy_global_resources ? 1 : 0
}

0 comments on commit bc7dbd7

Please sign in to comment.