Skip to content

Commit 5aabe67

Browse files
christiangonreChristian González
andauthored
feat: Add support for condition role_session_name when assuming a role (#379)
Co-authored-by: Christian González <[email protected]>
1 parent 1258cba commit 5aabe67

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

modules/iam-assumable-role/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ No modules.
6262
| <a name="input_role_path"></a> [role\_path](#input\_role\_path) | Path of IAM role | `string` | `"/"` | no |
6363
| <a name="input_role_permissions_boundary_arn"></a> [role\_permissions\_boundary\_arn](#input\_role\_permissions\_boundary\_arn) | Permissions boundary ARN to use for IAM role | `string` | `""` | no |
6464
| <a name="input_role_requires_mfa"></a> [role\_requires\_mfa](#input\_role\_requires\_mfa) | Whether role requires MFA | `bool` | `true` | no |
65+
| <a name="input_role_requires_session_name"></a> [role\_requires\_session\_name](#input\_role\_requires\_session\_name) | Determines if the role-session-name variable is needed when assuming a role(https://aws.amazon.com/blogs/security/easily-control-naming-individual-iam-role-sessions/) | `bool` | `false` | no |
66+
| <a name="input_role_session_name"></a> [role\_session\_name](#input\_role\_session\_name) | role\_session\_name for roles which require this parameter when being assumed. By default, you need to set your own username as role\_session\_name | `list(string)` | <pre>[<br> "${aws:username}"<br>]</pre> | no |
6567
| <a name="input_role_sts_externalid"></a> [role\_sts\_externalid](#input\_role\_sts\_externalid) | STS ExternalId condition values to use with a role (when MFA is not required) | `any` | `[]` | no |
6668
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to IAM role resources | `map(string)` | `{}` | no |
6769
| <a name="input_trusted_role_actions"></a> [trusted\_role\_actions](#input\_trusted\_role\_actions) | Actions of STS | `list(string)` | <pre>[<br> "sts:AssumeRole"<br>]</pre> | no |

modules/iam-assumable-role/main.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ data "aws_iam_policy_document" "assume_role_with_mfa" {
117117
values = local.role_sts_externalid
118118
}
119119
}
120+
121+
dynamic "condition" {
122+
for_each = var.role_requires_session_name ? [1] : []
123+
content {
124+
test = "StringEquals"
125+
variable = "sts:RoleSessionName"
126+
values = var.role_session_name
127+
}
128+
}
120129
}
121130
}
122131

modules/iam-assumable-role/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,15 @@ variable "allow_self_assume_role" {
154154
type = bool
155155
default = false
156156
}
157+
158+
variable "role_requires_session_name" {
159+
description = "Determines if the role-session-name variable is needed when assuming a role(https://aws.amazon.com/blogs/security/easily-control-naming-individual-iam-role-sessions/)"
160+
type = bool
161+
default = false
162+
}
163+
164+
variable "role_session_name" {
165+
description = "role_session_name for roles which require this parameter when being assumed. By default, you need to set your own username as role_session_name"
166+
type = list(string)
167+
default = ["$${aws:username}"]
168+
}

0 commit comments

Comments
 (0)