Skip to content

Commit 513ddae

Browse files
committed
fix: remove unnecessary permissions for buildcontroller
1 parent b0dea59 commit 513ddae

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

modules/cluster/irsa.tf

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,35 @@ module "iam_assumable_role_cm_cainjector" {
139139
// ----------------------------------------------------------------------------
140140
// ControllerBuild IAM Policy, IAM Role and Service Account
141141
// ----------------------------------------------------------------------------
142+
143+
data "aws_iam_policy_document" "controllerbuild-policy" {
144+
count = var.create_ctrlb_role && length(aws_s3_bucket.logs_jenkins_x) > 0 ? 1 : 0
145+
statement {
146+
sid = "BuildControllerPolicy"
147+
effect = "Allow"
148+
actions = [
149+
"s3:ListBucket",
150+
"s3:PutObject",
151+
]
152+
resources = [aws_s3_bucket.logs_jenkins_x.*.arn[0], "${aws_s3_bucket.logs_jenkins_x.*.arn[0]}/*"]
153+
}
154+
}
155+
156+
resource "aws_iam_policy" "controllerbuild" {
157+
count = var.create_ctrlb_role && length(aws_s3_bucket.logs_jenkins_x) > 0 ? 1 : 0
158+
name_prefix = "jx-bucketrepo"
159+
description = "bucketrepo policy for cluster ${var.cluster_name}"
160+
policy = data.aws_iam_policy_document.controllerbuild-policy[count.index].json
161+
}
162+
163+
142164
module "iam_assumable_role_controllerbuild" {
143165
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc"
144166
version = "~> v3.8.0"
145-
create_role = var.create_ctrlb_role
167+
create_role = var.create_ctrlb_role && length(aws_s3_bucket.logs_jenkins_x) > 0
146168
role_name = "${local.cluster_trunc}-build-ctrl"
147169
provider_url = var.cluster_oidc_issuer_url
148-
role_policy_arns = ["arn:${data.aws_partition.current.partition}:iam::aws:policy/AmazonS3FullAccess"]
170+
role_policy_arns = aws_iam_policy.controllerbuild[*].arn
149171
oidc_fully_qualified_subjects = ["system:serviceaccount:jx:jenkins-x-controllerbuild"]
150172
}
151173

0 commit comments

Comments
 (0)