Skip to content

Commit

Permalink
Add role_requires_session_name
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianvoss committed May 25, 2024
1 parent de95e21 commit 77e3665
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
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}"]
}

0 comments on commit 77e3665

Please sign in to comment.