Skip to content

Commit e7c1503

Browse files
author
Andres Montalban
committed
fix: Properly configure fully qualified audiences
1 parent de95e21 commit e7c1503

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

modules/iam-assumable-role-with-oidc/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ No modules.
4444
| <a name="input_force_detach_policies"></a> [force\_detach\_policies](#input\_force\_detach\_policies) | Whether policies should be detached from this role when destroying | `bool` | `false` | no |
4545
| <a name="input_max_session_duration"></a> [max\_session\_duration](#input\_max\_session\_duration) | Maximum CLI/API session duration in seconds between 3600 and 43200 | `number` | `3600` | no |
4646
| <a name="input_number_of_role_policy_arns"></a> [number\_of\_role\_policy\_arns](#input\_number\_of\_role\_policy\_arns) | Number of IAM policies to attach to IAM role | `number` | `null` | no |
47+
| <a name="input_oidc_audiences_with_wildcards"></a> [oidc\_audiences\_with\_wildcards](#input\_oidc\_audiences\_with\_wildcards) | The audiences using wildcards to be added to the role policy. | `set(string)` | `[]` | no |
4748
| <a name="input_oidc_fully_qualified_audiences"></a> [oidc\_fully\_qualified\_audiences](#input\_oidc\_fully\_qualified\_audiences) | The audience to be added to the role policy. Set to sts.amazonaws.com for cross-account assumable role. Leave empty otherwise. | `set(string)` | `[]` | no |
4849
| <a name="input_oidc_fully_qualified_subjects"></a> [oidc\_fully\_qualified\_subjects](#input\_oidc\_fully\_qualified\_subjects) | The fully qualified OIDC subjects to be added to the role policy | `set(string)` | `[]` | no |
4950
| <a name="input_oidc_subjects_with_wildcards"></a> [oidc\_subjects\_with\_wildcards](#input\_oidc\_subjects\_with\_wildcards) | The OIDC subject using wildcards to be added to the role policy | `set(string)` | `[]` | no |

modules/iam-assumable-role-with-oidc/main.tf

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,21 @@ data "aws_iam_policy_document" "assume_role_with_oidc" {
7575
for_each = length(var.oidc_fully_qualified_audiences) > 0 ? local.urls : []
7676

7777
content {
78-
test = "StringLike"
78+
test = "StringEquals"
7979
variable = "${statement.value}:aud"
8080
values = var.oidc_fully_qualified_audiences
8181
}
8282
}
83+
84+
dynamic "condition" {
85+
for_each = length(var.oidc_audiences_with_wildcards) > 0 ? local.urls : []
86+
87+
content {
88+
test = "StringLike"
89+
variable = "${statement.value}:aud"
90+
values = var.oidc_audiences_with_wildcards
91+
}
92+
}
8393
}
8494
}
8595
}

modules/iam-assumable-role-with-oidc/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ variable "oidc_fully_qualified_audiences" {
9494
default = []
9595
}
9696

97+
variable "oidc_audiences_with_wildcards" {
98+
description = "The audiences using wildcards to be added to the role policy."
99+
type = set(string)
100+
default = []
101+
}
102+
97103
variable "force_detach_policies" {
98104
description = "Whether policies should be detached from this role when destroying"
99105
type = bool

wrappers/iam-assumable-role-with-oidc/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module "wrapper" {
99
force_detach_policies = try(each.value.force_detach_policies, var.defaults.force_detach_policies, false)
1010
max_session_duration = try(each.value.max_session_duration, var.defaults.max_session_duration, 3600)
1111
number_of_role_policy_arns = try(each.value.number_of_role_policy_arns, var.defaults.number_of_role_policy_arns, null)
12+
oidc_audiences_with_wildcards = try(each.value.oidc_audiences_with_wildcards, var.defaults.oidc_audiences_with_wildcards, [])
1213
oidc_fully_qualified_audiences = try(each.value.oidc_fully_qualified_audiences, var.defaults.oidc_fully_qualified_audiences, [])
1314
oidc_fully_qualified_subjects = try(each.value.oidc_fully_qualified_subjects, var.defaults.oidc_fully_qualified_subjects, [])
1415
oidc_subjects_with_wildcards = try(each.value.oidc_subjects_with_wildcards, var.defaults.oidc_subjects_with_wildcards, [])

0 commit comments

Comments
 (0)