Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 60 additions & 4 deletions terraform/codebase-pipelines/ecr.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ data "aws_iam_policy_document" "ecr_policy" {
actions = [
"ecr:BatchCheckLayerAvailability",
"ecr:BatchGetImage",
"ecr:CompleteLayerUpload",
"ecr:GetDownloadUrlForLayer",
"ecr:InitiateLayerUpload",
"ecr:PutImage",
"ecr:UploadLayerPart"
]

principals {
Expand All @@ -41,6 +37,66 @@ data "aws_iam_policy_document" "ecr_policy" {
}
}

statement {
effect = "Allow"
sid = "allowECRAuthentication"
actions = [
"ecr:GetAuthorizationToken"
]
resources = "*"
}

statement {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this statement get ignored, since another action adds the same permissions below.

sid = "AllowImagePull"
effect = "Allow"
actions = [
"ecr:BatchGetImage",
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer"
]
resources = [
"arn:aws:ecr:eu-west-2:${id}:repository/${locals.ecr_name}",
]
}

statement {
sid = "AllowSignatureRevokeCheck"
effect = "Allow"
actions = [
"signer:GetRevocationStatus"
]
resources = [
"*"
]
}

statement {
effect = "Allow"
sid = "PushActions"

actions = [
"ecr:CompleteLayerUpload",
"ecr:InitiateLayerUpload",
"ecr:PutImage",
"ecr:UploadLayerPart"
]

principals {
type = "AWS"
identifiers = ["*"]
}

condition {
test = "StringLike"
variable = "aws:PrincipalArn"
values = [
"arn:aws:iam::${id}:role/aws-reserved/sso.amazonaws.com/eu-west-2/AWSReservedSSO_AdministratorAccess_*",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we are fine allowing admins to have access under some circumstances where for some reason they may need to manually upload an image? Unlikely, but probably worth keeping the access there.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, should be okay

"arn:aws:iam::${id}:role/github-oidc-${var.application}-repo-role",
"arn:aws:iam::${id}:role/${var.application}-${var.codebase}-codebase-image-build"
]
}
}

statement {
sid = "PreventRepoDelete"
effect = "Deny"
Expand Down
Loading