Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add role_requires_session_name #491

Closed
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
2 changes: 2 additions & 0 deletions modules/iam-assumable-roles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ No modules.
| <a name="input_readonly_role_policy_arns"></a> [readonly\_role\_policy\_arns](#input\_readonly\_role\_policy\_arns) | List of policy ARNs to use for readonly role | `list(string)` | <pre>[<br> "arn:aws:iam::aws:policy/ReadOnlyAccess"<br>]</pre> | no |
| <a name="input_readonly_role_requires_mfa"></a> [readonly\_role\_requires\_mfa](#input\_readonly\_role\_requires\_mfa) | Whether readonly role requires MFA | `bool` | `true` | no |
| <a name="input_readonly_role_tags"></a> [readonly\_role\_tags](#input\_readonly\_role\_tags) | A map of tags to add to readonly role resource. | `map(string)` | `{}` | no |
| <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 |
| <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 |
| <a name="input_trusted_role_actions"></a> [trusted\_role\_actions](#input\_trusted\_role\_actions) | Additional trusted role actions | `list(string)` | <pre>[<br> "sts:AssumeRole",<br> "sts:TagSession"<br>]</pre> | no |
| <a name="input_trusted_role_arns"></a> [trusted\_role\_arns](#input\_trusted\_role\_arns) | ARNs of AWS entities who can assume these roles | `list(string)` | `[]` | no |
| <a name="input_trusted_role_services"></a> [trusted\_role\_services](#input\_trusted\_role\_services) | AWS Services that can assume these roles | `list(string)` | `[]` | no |
Expand Down
9 changes: 9 additions & 0 deletions modules/iam-assumable-roles/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ data "aws_iam_policy_document" "assume_role_with_mfa" {
variable = "aws:MultiFactorAuthAge"
values = [var.mfa_age]
}

dynamic "condition" {
for_each = var.role_requires_session_name ? [1] : []
content {
test = "StringEquals"
variable = "sts:RoleSessionName"
values = var.role_session_name
}
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions modules/iam-assumable-roles/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,15 @@ variable "force_detach_policies" {
type = bool
default = false
}

variable "role_requires_session_name" {
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/)"
type = bool
default = false
}

variable "role_session_name" {
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"
type = list(string)
default = ["$${aws:username}"]
}
2 changes: 2 additions & 0 deletions wrappers/iam-assumable-roles/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ module "wrapper" {
readonly_role_policy_arns = try(each.value.readonly_role_policy_arns, var.defaults.readonly_role_policy_arns, ["arn:aws:iam::aws:policy/ReadOnlyAccess"])
readonly_role_requires_mfa = try(each.value.readonly_role_requires_mfa, var.defaults.readonly_role_requires_mfa, true)
readonly_role_tags = try(each.value.readonly_role_tags, var.defaults.readonly_role_tags, {})
role_requires_session_name = try(each.value.role_requires_session_name, var.defaults.role_requires_session_name, false)
role_session_name = try(each.value.role_session_name, var.defaults.role_session_name, ["$${aws:username}"])
trusted_role_actions = try(each.value.trusted_role_actions, var.defaults.trusted_role_actions, ["sts:AssumeRole", "sts:TagSession"])
trusted_role_arns = try(each.value.trusted_role_arns, var.defaults.trusted_role_arns, [])
trusted_role_services = try(each.value.trusted_role_services, var.defaults.trusted_role_services, [])
Expand Down