Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduced permissions for ECR in IAM #13

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Truefoundry AWS Control Plane Module
|------|------|
| [aws_db_instance.truefoundry_db](https://registry.terraform.io/providers/hashicorp/aws/5.44.0/docs/resources/db_instance) | resource |
| [aws_db_subnet_group.rds](https://registry.terraform.io/providers/hashicorp/aws/5.44.0/docs/resources/db_subnet_group) | resource |
| [aws_iam_policy.svcfoundry_access_to_ecr](https://registry.terraform.io/providers/hashicorp/aws/5.44.0/docs/resources/iam_policy) | resource |
| [aws_iam_policy.svcfoundry_access_to_multitenant_ssm](https://registry.terraform.io/providers/hashicorp/aws/5.44.0/docs/resources/iam_policy) | resource |
| [aws_iam_policy.svcfoundry_access_to_ssm](https://registry.terraform.io/providers/hashicorp/aws/5.44.0/docs/resources/iam_policy) | resource |
| [aws_iam_policy.truefoundry_assume_role_all](https://registry.terraform.io/providers/hashicorp/aws/5.44.0/docs/resources/iam_policy) | resource |
Expand All @@ -41,7 +42,7 @@ Truefoundry AWS Control Plane Module
| [aws_security_group.rds](https://registry.terraform.io/providers/hashicorp/aws/5.44.0/docs/resources/security_group) | resource |
| [aws_security_group.rds-public](https://registry.terraform.io/providers/hashicorp/aws/5.44.0/docs/resources/security_group) | resource |
| [random_password.truefoundry_db_password](https://registry.terraform.io/providers/hashicorp/random/3.5.1/docs/resources/password) | resource |
| [aws_iam_policy.servicefoundry_ecr_policy](https://registry.terraform.io/providers/hashicorp/aws/5.44.0/docs/data-sources/iam_policy) | data source |
| [aws_iam_policy_document.svcfoundry_access_to_ecr](https://registry.terraform.io/providers/hashicorp/aws/5.44.0/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.svcfoundry_access_to_multitenant_ssm](https://registry.terraform.io/providers/hashicorp/aws/5.44.0/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.svcfoundry_access_to_ssm](https://registry.terraform.io/providers/hashicorp/aws/5.44.0/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.truefoundry_assume_role_all](https://registry.terraform.io/providers/hashicorp/aws/5.44.0/docs/data-sources/iam_policy_document) | data source |
Expand Down
48 changes: 48 additions & 0 deletions iam-ecr.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
data "aws_iam_policy_document" "svcfoundry_access_to_ecr" {
statement {
effect = "Allow"
actions = [
"ecr:GetRegistryPolicy",
"ecr:DescribeImageScanFindings",
"ecr:GetLifecyclePolicyPreview",
"ecr:CreateRepository",
"ecr:GetDownloadUrlForLayer",
"ecr:DescribeImageReplicationStatus",
"ecr:ListTagsForResource",
"ecr:BatchGetRepositoryScanningConfiguration",
"ecr:GetRegistryScanningConfiguration",
"ecr:PutImage",
"ecr:BatchGetImage",
"ecr:DescribeRepositories",
"ecr:BatchCheckLayerAvailability",
"ecr:GetRepositoryPolicy",
"ecr:GetLifecyclePolicy",
"ecr:ListImages",
"ecr:InitiateLayerUpload",
"ecr:CompleteLayerUpload",
"ecr:DescribeImages",
"ecr:DeleteRepository",
"ecr:UploadLayerPart",
]

resources = [
"arn:aws:ecr:${var.aws_region}:${var.aws_account_id}:repository/tfy-*"
]
}
statement {
effect = "Allow"
actions = [
"ecr:DescribeRegistry",
"ecr:GetAuthorizationToken",
"sts:GetServiceBearerToken"
]
resources = ["*"]
}
}

resource "aws_iam_policy" "svcfoundry_access_to_ecr" {
name_prefix = "${local.svcfoundry_unique_name}-access-to-ecr"
description = "ECR access for ${var.svcfoundry_name} on ${var.cluster_name}"
policy = data.aws_iam_policy_document.svcfoundry_access_to_ecr.json
tags = local.tags
}
6 changes: 1 addition & 5 deletions iam-sa.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# From https://github.com/terraform-aws-modules/terraform-aws-eks/blob/master/examples/irsa/irsa.tf

data "aws_iam_policy" "servicefoundry_ecr_policy" {
name = "AmazonEC2ContainerRegistryFullAccess"
}

module "truefoundry_oidc_iam" {
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc"
version = "5.39.0"
Expand All @@ -21,7 +17,7 @@ module "truefoundry_oidc_iam" {
aws_iam_policy.svcfoundry_access_to_ssm.arn,
aws_iam_policy.svcfoundry_access_to_multitenant_ssm.arn,
aws_iam_policy.truefoundry_assume_role_all.arn,
data.aws_iam_policy.servicefoundry_ecr_policy.arn,
dunefro marked this conversation as resolved.
Show resolved Hide resolved
aws_iam_policy.svcfoundry_access_to_ecr.arn,
aws_iam_policy.truefoundry_db_iam_auth_policy.arn,
]
tags = local.tags
Expand Down
2 changes: 1 addition & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ variable "mlfoundry_k8s_namespace" {
}

##################################################################################
## Servicefoundry
## Servicefoundry service account
##################################################################################

variable "svcfoundry_name" {
Expand Down