Skip to content
Open
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
67 changes: 67 additions & 0 deletions terraform/aws/modules/2-nbs7/eks-nbs/irsa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,71 @@
}
]
})
}

# ──────────────────────────────────────────────────────────
# Cluster Autoscaler IRSA
# ──────────────────────────────────────────────────────────

module "cluster_autoscaler_irsa_role" {
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts"
version = ">=6.2.3, <7.0.0"

name = "${local.eks_name}-cluster-autoscaler"
create = var.create_cluster_autoscaler_irsa

oidc_providers = {
main = {
provider_arn = module.eks.oidc_provider_arn
namespace_service_accounts = ["kube-system:cluster-autoscaler-aws-cluster-autoscaler"]
}
}

policies = {
policy = try(aws_iam_policy.cluster_autoscaler_irsa_policy[0].arn, null)
}
}

resource "aws_iam_policy" "cluster_autoscaler_irsa_policy" {
count = var.create_cluster_autoscaler_irsa ? 1 : 0
name = "${local.eks_name}-cluster-autoscaler-policy"
description = "Cluster Autoscaler permissions for EKS node group scaling"

policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Sid = "ClusterAutoscalerDescribe"
Effect = "Allow"
Action = [
"autoscaling:DescribeAutoScalingGroups",
"autoscaling:DescribeAutoScalingInstances",
"autoscaling:DescribeLaunchConfigurations",
"autoscaling:DescribeScalingActivities",
"autoscaling:DescribeTags",
"ec2:DescribeImages",
"ec2:DescribeInstanceTypes",
"ec2:DescribeLaunchTemplateVersions",
"ec2:GetInstanceTypesFromInstanceRequirements",
"eks:DescribeNodegroup"
]
Resource = ["*"]

Check failure on line 180 in terraform/aws/modules/2-nbs7/eks-nbs/irsa.tf

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make sure granting access to all resources is safe here.

See more on https://sonarcloud.io/project/issues?id=CDCgov_NEDSS-Infrastructure&issues=AZ898x1hcDaOUeGsDCYz&open=AZ898x1hcDaOUeGsDCYz&pullRequest=313

Check failure

Code scanning / SonarCloud

IAM policies should not grant access to all account resources High

Make sure granting access to all resources is safe here. See more on SonarQube Cloud
Comment thread
EmmanuelNwa247 marked this conversation as resolved.
Dismissed
},
{
Sid = "ClusterAutoscalerScale"
Effect = "Allow"
Action = [
"autoscaling:SetDesiredCapacity",
"autoscaling:TerminateInstanceInAutoScalingGroup"
]
Resource = ["*"]

Check failure on line 189 in terraform/aws/modules/2-nbs7/eks-nbs/irsa.tf

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make sure granting access to all resources is safe here.

See more on https://sonarcloud.io/project/issues?id=CDCgov_NEDSS-Infrastructure&issues=AZ898x1hcDaOUeGsDCY0&open=AZ898x1hcDaOUeGsDCY0&pullRequest=313

Check failure

Code scanning / SonarCloud

IAM policies should not grant access to all account resources High

Make sure granting access to all resources is safe here. See more on SonarQube Cloud
Comment thread
EmmanuelNwa247 marked this conversation as resolved.
Dismissed
Condition = {
StringEquals = {
"aws:ResourceTag/k8s.io/cluster-autoscaler/enabled" = "true"
"aws:ResourceTag/k8s.io/cluster-autoscaler/${var.cluster_autoscaler_cluster_name}" = "owned"
}
}
}
]
})
}
5 changes: 5 additions & 0 deletions terraform/aws/modules/2-nbs7/eks-nbs/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ output "readonly_role_arns" {
output "otel_collector_role_arn" {
description = "OTEL Collector IRSA role ARN — pass to helm install via --set serviceAccount.annotations"
value = var.create_otel_collector_irsa ? module.otel_collector_irsa_role.arn : null
}

output "cluster_autoscaler_irsa_role_arn" {
description = "ARN of the Cluster Autoscaler IRSA role"
value = var.create_cluster_autoscaler_irsa ? module.cluster_autoscaler_irsa_role.arn : null
}
12 changes: 12 additions & 0 deletions terraform/aws/modules/2-nbs7/eks-nbs/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,15 @@ variable "datacompare_s3_bucket_keyname_prefix" {
error_message = "The datacompare_s3_bucket_keyname_prefix variable must be an empty string or end with a forward slash (/). Example: 'myFolder/' or \"\"."
}
}

variable "create_cluster_autoscaler_irsa" {
description = "Whether to create the Cluster Autoscaler IRSA role and policy"
type = bool
default = false
}

variable "cluster_autoscaler_cluster_name" {
description = "EKS cluster name for Cluster Autoscaler IAM policy tag-based scoping"
type = string
default = ""
}
Loading