Skip to content

Commit 813c607

Browse files
dpiddockcmpmax-rocket-internet
authored andcommitted
Make "dangerous" policy attachments optional (#539)
1 parent 09635a3 commit 813c607

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
1717

1818
- Add option to enable lifecycle hooks creation (by @barryib)
1919
- Remove helm chart value `sslCertPath` described in `docs/autoscaling.md` (by @wi1dcard)
20+
- Attaching of IAM policies for autoscaler and CNI to the worker nodes now optional (by @dpiddockcmp)
2021

2122
# History
2223

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
108108
109109
| Name | Description | Type | Default | Required |
110110
|------|-------------|:----:|:-----:|:-----:|
111+
| attach\_worker\_autoscaling\_policy | Whether to attach the module managed cluster autoscaling iam policy to the default worker IAM role. This requires `manage_worker_autoscaling_policy = true` | bool | `"true"` | no |
112+
| attach\_worker\_cni\_policy | Whether to attach the Amazon managed `AmazonEKS_CNI_Policy` IAM policy to the default worker IAM role. WARNING: If set `false` the permissions must be assigned to the `aws-node` DaemonSet pods via another method or nodes will not be able to join the cluster. | bool | `"true"` | no |
111113
| cluster\_create\_security\_group | Whether to create a security group for the cluster or attach the cluster to `cluster_security_group_id`. | bool | `"true"` | no |
112114
| cluster\_create\_timeout | Timeout value when creating the EKS cluster. | string | `"15m"` | no |
113115
| cluster\_delete\_timeout | Timeout value when deleting the EKS cluster. | string | `"15m"` | no |
@@ -130,6 +132,7 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
130132
| local\_exec\_interpreter | Command to run for local-exec resources. Must be a shell-style interpreter. If you are on Windows Git Bash is a good choice. | list(string) | `[ "/bin/sh", "-c" ]` | no |
131133
| manage\_aws\_auth | Whether to apply the aws-auth configmap file. | string | `"true"` | no |
132134
| manage\_cluster\_iam\_resources | Whether to let the module manage cluster IAM resources. If set to false, cluster_iam_role_name must be specified. | bool | `"true"` | no |
135+
| manage\_worker\_autoscaling\_policy | Whether to let the module manage the cluster autoscaling iam policy. | bool | `"true"` | no |
133136
| manage\_worker\_iam\_resources | Whether to let the module manage worker IAM resources. If set to false, iam_instance_profile_name must be specified for workers. | bool | `"true"` | no |
134137
| map\_accounts | Additional AWS account numbers to add to the aws-auth configmap. See examples/basic/variables.tf for example format. | list(string) | `[]` | no |
135138
| map\_roles | Additional IAM roles to add to the aws-auth configmap. See examples/basic/variables.tf for example format. | object | `[]` | no |
@@ -170,6 +173,8 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
170173
| config\_map\_aws\_auth | A kubernetes configuration to authenticate to this EKS cluster. |
171174
| kubeconfig | kubectl config file contents for this EKS cluster. |
172175
| kubeconfig\_filename | The filename of the generated kubectl config. |
176+
| worker\_autoscaling\_policy\_arn | ARN of the worker autoscaling IAM policy if `manage_worker_autoscaling_policy = true` |
177+
| worker\_autoscaling\_policy\_name | Name of the worker autoscaling IAM policy if `manage_worker_autoscaling_policy = true` |
173178
| worker\_iam\_instance\_profile\_arns | default IAM instance profile ARN for EKS worker groups |
174179
| worker\_iam\_instance\_profile\_names | default IAM instance profile name for EKS worker groups |
175180
| worker\_iam\_role\_arn | default IAM role ARN for EKS worker groups |

outputs.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,12 @@ output "worker_iam_role_arn" {
142142
)[0]
143143
}
144144

145+
output "worker_autoscaling_policy_name" {
146+
description = "Name of the worker autoscaling IAM policy if `manage_worker_autoscaling_policy = true`"
147+
value = concat(aws_iam_policy.worker_autoscaling[*].name, [""])[0]
148+
}
149+
150+
output "worker_autoscaling_policy_arn" {
151+
description = "ARN of the worker autoscaling IAM policy if `manage_worker_autoscaling_policy = true`"
152+
value = concat(aws_iam_policy.worker_autoscaling[*].arn, [""])[0]
153+
}

variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,21 @@ variable "workers_role_name" {
263263
type = string
264264
default = ""
265265
}
266+
267+
variable "manage_worker_autoscaling_policy" {
268+
description = "Whether to let the module manage the cluster autoscaling iam policy."
269+
type = bool
270+
default = true
271+
}
272+
273+
variable "attach_worker_autoscaling_policy" {
274+
description = "Whether to attach the module managed cluster autoscaling iam policy to the default worker IAM role. This requires `manage_worker_autoscaling_policy = true`"
275+
type = bool
276+
default = true
277+
}
278+
279+
variable "attach_worker_cni_policy" {
280+
description = "Whether to attach the Amazon managed `AmazonEKS_CNI_Policy` IAM policy to the default worker IAM role. WARNING: If set `false` the permissions must be assigned to the `aws-node` DaemonSet pods via another method or nodes will not be able to join the cluster."
281+
type = bool
282+
default = true
283+
}

workers.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ resource "aws_iam_role_policy_attachment" "workers_AmazonEKSWorkerNodePolicy" {
342342
}
343343

344344
resource "aws_iam_role_policy_attachment" "workers_AmazonEKS_CNI_Policy" {
345-
count = var.manage_worker_iam_resources ? 1 : 0
345+
count = var.manage_worker_iam_resources && var.attach_worker_cni_policy ? 1 : 0
346346
policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"
347347
role = aws_iam_role.workers[0].name
348348
}
@@ -360,13 +360,13 @@ resource "aws_iam_role_policy_attachment" "workers_additional_policies" {
360360
}
361361

362362
resource "aws_iam_role_policy_attachment" "workers_autoscaling" {
363-
count = var.manage_worker_iam_resources ? 1 : 0
363+
count = var.manage_worker_iam_resources && var.manage_worker_autoscaling_policy && var.attach_worker_autoscaling_policy ? 1 : 0
364364
policy_arn = aws_iam_policy.worker_autoscaling[0].arn
365365
role = aws_iam_role.workers[0].name
366366
}
367367

368368
resource "aws_iam_policy" "worker_autoscaling" {
369-
count = var.manage_worker_iam_resources ? 1 : 0
369+
count = var.manage_worker_iam_resources && var.manage_worker_autoscaling_policy ? 1 : 0
370370
name_prefix = "eks-worker-autoscaling-${aws_eks_cluster.this.name}"
371371
description = "EKS worker node autoscaling policy for cluster ${aws_eks_cluster.this.name}"
372372
policy = data.aws_iam_policy_document.worker_autoscaling.json

0 commit comments

Comments
 (0)