-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add an ECR role to allow pulling images
- Loading branch information
1 parent
5dcf592
commit bc7dbd7
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters