Skip to content

Commit 0515ad6

Browse files
feat: Add opt-in aws:SourceAccount condition to Karpenter node IAM role trust policy (#3695)
feat: Add opt-in aws:SourceAccount condition on Karpenter node IAM role trust policy Closes #3688 Co-authored-by: Bryant Biggs <bryantbiggs@gmail.com>
1 parent 76f5a89 commit 0515ad6

3 files changed

Lines changed: 17 additions & 0 deletions

File tree

modules/karpenter/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ No modules.
168168
| <a name="input_node_iam_role_name"></a> [node\_iam\_role\_name](#input\_node\_iam\_role\_name) | Name to use on IAM role created | `string` | `null` | no |
169169
| <a name="input_node_iam_role_path"></a> [node\_iam\_role\_path](#input\_node\_iam\_role\_path) | IAM role path | `string` | `"/"` | no |
170170
| <a name="input_node_iam_role_permissions_boundary"></a> [node\_iam\_role\_permissions\_boundary](#input\_node\_iam\_role\_permissions\_boundary) | ARN of the policy that is used to set the permissions boundary for the IAM role | `string` | `null` | no |
171+
| <a name="input_node_iam_role_source_account_condition"></a> [node\_iam\_role\_source\_account\_condition](#input\_node\_iam\_role\_source\_account\_condition) | Whether to add an `aws:SourceAccount` condition to the node IAM role's trust policy, scoped to the current account | `bool` | `false` | no |
171172
| <a name="input_node_iam_role_tags"></a> [node\_iam\_role\_tags](#input\_node\_iam\_role\_tags) | A map of additional tags to add to the IAM role created | `map(string)` | `{}` | no |
172173
| <a name="input_node_iam_role_use_name_prefix"></a> [node\_iam\_role\_use\_name\_prefix](#input\_node\_iam\_role\_use\_name\_prefix) | Determines whether the Node IAM role name (`node_iam_role_name`) is used as a prefix | `bool` | `true` | no |
173174
| <a name="input_queue_kms_data_key_reuse_period_seconds"></a> [queue\_kms\_data\_key\_reuse\_period\_seconds](#input\_queue\_kms\_data\_key\_reuse\_period\_seconds) | The length of time, in seconds, for which Amazon SQS can reuse a data key to encrypt or decrypt messages before calling AWS KMS again | `number` | `null` | no |

modules/karpenter/main.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,16 @@ data "aws_iam_policy_document" "node_assume_role" {
340340
type = "Service"
341341
identifiers = [local.ec2_sp_name]
342342
}
343+
344+
dynamic "condition" {
345+
for_each = var.node_iam_role_source_account_condition ? [1] : []
346+
347+
content {
348+
test = "StringEquals"
349+
variable = "aws:SourceAccount"
350+
values = [local.account_id]
351+
}
352+
}
343353
}
344354
}
345355

modules/karpenter/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,12 @@ variable "node_iam_role_additional_policies" {
306306
default = {}
307307
}
308308

309+
variable "node_iam_role_source_account_condition" {
310+
description = "Whether to add an `aws:SourceAccount` condition to the node IAM role's trust policy, scoped to the current account"
311+
type = bool
312+
default = false
313+
}
314+
309315
variable "node_iam_role_tags" {
310316
description = "A map of additional tags to add to the IAM role created"
311317
type = map(string)

0 commit comments

Comments
 (0)