Skip to content

Commit 5702679

Browse files
feat: Added variable trusted_role_actions to sub modules as a "Action of STS" (#393)
Co-authored-by: Bryant Biggs <[email protected]>
1 parent c1e20a2 commit 5702679

File tree

16 files changed

+35
-25
lines changed

16 files changed

+35
-25
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ No modules.
5252
| <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 |
5353
| <a name="input_role_policy_arns"></a> [role\_policy\_arns](#input\_role\_policy\_arns) | List of ARNs of IAM policies to attach to IAM role | `list(string)` | `[]` | no |
5454
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to IAM role resources | `map(string)` | `{}` | no |
55-
| <a name="input_trusted_role_actions"></a> [trusted\_role\_actions](#input\_trusted\_role\_actions) | Extra Actions of STS | `list(string)` | <pre>[<br> ""<br>]</pre> | no |
55+
| <a name="input_trusted_role_actions"></a> [trusted\_role\_actions](#input\_trusted\_role\_actions) | Additional role actions | `list(string)` | <pre>[<br> "sts:AssumeRoleWithSAML",<br> "sts:TagSession"<br>]</pre> | no |
5656

5757
## Outputs
5858

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ data "aws_iam_policy_document" "assume_role_with_saml" {
3737
actions = compact(distinct(concat(["sts:AssumeRoleWithSAML"], var.trusted_role_actions)))
3838

3939
principals {
40-
type = "Federated"
41-
40+
type = "Federated"
4241
identifiers = local.identifiers
4342
}
4443

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ variable "allow_self_assume_role" {
8989
}
9090

9191
variable "trusted_role_actions" {
92-
description = "Extra Actions of STS"
92+
description = "Additional role actions"
9393
type = list(string)
94-
default = [""]
94+
default = ["sts:AssumeRoleWithSAML", "sts:TagSession"]
9595
}

modules/iam-assumable-role/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ No modules.
6666
| <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 |
6767
| <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 |
6868
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to IAM role resources | `map(string)` | `{}` | no |
69-
| <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 |
69+
| <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 |
7070
| <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 |
7171
| <a name="input_trusted_role_services"></a> [trusted\_role\_services](#input\_trusted\_role\_services) | AWS Services that can assume these roles | `list(string)` | `[]` | no |
7272

modules/iam-assumable-role/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ data "aws_iam_policy_document" "assume_role" {
3535

3636
statement {
3737
effect = "Allow"
38-
actions = var.trusted_role_actions
38+
actions = compact(distinct(concat(["sts:AssumeRole"], var.trusted_role_actions)))
3939

4040
principals {
4141
type = "AWS"
@@ -85,7 +85,7 @@ data "aws_iam_policy_document" "assume_role_with_mfa" {
8585

8686
statement {
8787
effect = "Allow"
88-
actions = var.trusted_role_actions
88+
actions = compact(distinct(concat(["sts:AssumeRole"], var.trusted_role_actions)))
8989

9090
principals {
9191
type = "AWS"

modules/iam-assumable-role/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
variable "trusted_role_actions" {
2-
description = "Actions of STS"
2+
description = "Additional trusted role actions"
33
type = list(string)
4-
default = ["sts:AssumeRole"]
4+
default = ["sts:AssumeRole", "sts:TagSession"]
55
}
66

77
variable "trusted_role_arns" {

modules/iam-assumable-roles-with-saml/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ No modules.
6666
| <a name="input_readonly_role_permissions_boundary_arn"></a> [readonly\_role\_permissions\_boundary\_arn](#input\_readonly\_role\_permissions\_boundary\_arn) | Permissions boundary ARN to use for readonly role | `string` | `""` | no |
6767
| <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 |
6868
| <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 |
69+
| <a name="input_trusted_role_actions"></a> [trusted\_role\_actions](#input\_trusted\_role\_actions) | Additional role actions | `list(string)` | <pre>[<br> "sts:AssumeRoleWithSAML",<br> "sts:TagSession"<br>]</pre> | no |
6970

7071
## Outputs
7172

modules/iam-assumable-roles-with-saml/main.tf

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,11 @@ data "aws_iam_policy_document" "assume_role_with_saml" {
7575
}
7676

7777
statement {
78-
effect = "Allow"
79-
80-
actions = ["sts:AssumeRoleWithSAML"]
78+
effect = "Allow"
79+
actions = compact(distinct(concat(["sts:AssumeRoleWithSAML"], var.trusted_role_actions)))
8180

8281
principals {
83-
type = "Federated"
84-
82+
type = "Federated"
8583
identifiers = local.identifiers
8684
}
8785

@@ -103,8 +101,7 @@ resource "aws_iam_role" "admin" {
103101

104102
force_detach_policies = var.force_detach_policies
105103
permissions_boundary = var.admin_role_permissions_boundary_arn
106-
107-
assume_role_policy = data.aws_iam_policy_document.assume_role_with_saml.json
104+
assume_role_policy = data.aws_iam_policy_document.assume_role_with_saml.json
108105

109106
tags = var.admin_role_tags
110107
}
@@ -126,8 +123,7 @@ resource "aws_iam_role" "poweruser" {
126123

127124
force_detach_policies = var.force_detach_policies
128125
permissions_boundary = var.poweruser_role_permissions_boundary_arn
129-
130-
assume_role_policy = data.aws_iam_policy_document.assume_role_with_saml.json
126+
assume_role_policy = data.aws_iam_policy_document.assume_role_with_saml.json
131127

132128
tags = var.poweruser_role_tags
133129
}
@@ -149,8 +145,7 @@ resource "aws_iam_role" "readonly" {
149145

150146
force_detach_policies = var.force_detach_policies
151147
permissions_boundary = var.readonly_role_permissions_boundary_arn
152-
153-
assume_role_policy = data.aws_iam_policy_document.assume_role_with_saml.json
148+
assume_role_policy = data.aws_iam_policy_document.assume_role_with_saml.json
154149

155150
tags = var.readonly_role_tags
156151
}

modules/iam-assumable-roles-with-saml/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ variable "allow_self_assume_role" {
2222
default = false
2323
}
2424

25+
variable "trusted_role_actions" {
26+
description = "Additional role actions"
27+
type = list(string)
28+
default = ["sts:AssumeRoleWithSAML", "sts:TagSession"]
29+
}
30+
2531
# Admin
2632
variable "create_admin_role" {
2733
description = "Whether to create admin role"

modules/iam-assumable-roles/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ No modules.
6666
| <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 |
6767
| <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 |
6868
| <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 |
69+
| <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 |
6970
| <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 |
7071
| <a name="input_trusted_role_services"></a> [trusted\_role\_services](#input\_trusted\_role\_services) | AWS Services that can assume these roles | `list(string)` | `[]` | no |
7172

modules/iam-assumable-roles/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ data "aws_iam_policy_document" "assume_role" {
7575

7676
statement {
7777
effect = "Allow"
78-
actions = ["sts:AssumeRole"]
78+
actions = compact(distinct(concat(["sts:AssumeRole"], var.trusted_role_actions)))
7979

8080
principals {
8181
type = "AWS"
@@ -158,7 +158,7 @@ data "aws_iam_policy_document" "assume_role_with_mfa" {
158158

159159
statement {
160160
effect = "Allow"
161-
actions = ["sts:AssumeRole"]
161+
actions = compact(distinct(concat(["sts:AssumeRole"], var.trusted_role_actions)))
162162

163163
principals {
164164
type = "AWS"

modules/iam-assumable-roles/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
variable "trusted_role_actions" {
2+
description = "Additional trusted role actions"
3+
type = list(string)
4+
default = ["sts:AssumeRole", "sts:TagSession"]
5+
}
6+
17
variable "trusted_role_arns" {
28
description = "ARNs of AWS entities who can assume these roles"
39
type = list(string)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ module "wrapper" {
1818
number_of_role_policy_arns = try(each.value.number_of_role_policy_arns, var.defaults.number_of_role_policy_arns, null)
1919
force_detach_policies = try(each.value.force_detach_policies, var.defaults.force_detach_policies, false)
2020
allow_self_assume_role = try(each.value.allow_self_assume_role, var.defaults.allow_self_assume_role, false)
21-
trusted_role_actions = try(each.value.trusted_role_actions, var.defaults.trusted_role_actions, [""])
21+
trusted_role_actions = try(each.value.trusted_role_actions, var.defaults.trusted_role_actions, ["sts:AssumeRoleWithSAML", "sts:TagSession"])
2222
}

wrappers/iam-assumable-role/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module "wrapper" {
33

44
for_each = var.items
55

6-
trusted_role_actions = try(each.value.trusted_role_actions, var.defaults.trusted_role_actions, ["sts:AssumeRole"])
6+
trusted_role_actions = try(each.value.trusted_role_actions, var.defaults.trusted_role_actions, ["sts:AssumeRole", "sts:TagSession"])
77
trusted_role_arns = try(each.value.trusted_role_arns, var.defaults.trusted_role_arns, [])
88
trusted_role_services = try(each.value.trusted_role_services, var.defaults.trusted_role_services, [])
99
mfa_age = try(each.value.mfa_age, var.defaults.mfa_age, 86400)

wrappers/iam-assumable-roles-with-saml/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module "wrapper" {
77
provider_ids = try(each.value.provider_ids, var.defaults.provider_ids, [])
88
aws_saml_endpoint = try(each.value.aws_saml_endpoint, var.defaults.aws_saml_endpoint, "https://signin.aws.amazon.com/saml")
99
allow_self_assume_role = try(each.value.allow_self_assume_role, var.defaults.allow_self_assume_role, false)
10+
trusted_role_actions = try(each.value.trusted_role_actions, var.defaults.trusted_role_actions, ["sts:AssumeRoleWithSAML", "sts:TagSession"])
1011
create_admin_role = try(each.value.create_admin_role, var.defaults.create_admin_role, false)
1112
admin_role_name = try(each.value.admin_role_name, var.defaults.admin_role_name, "admin")
1213
admin_role_path = try(each.value.admin_role_path, var.defaults.admin_role_path, "/")

wrappers/iam-assumable-roles/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module "wrapper" {
33

44
for_each = var.items
55

6+
trusted_role_actions = try(each.value.trusted_role_actions, var.defaults.trusted_role_actions, ["sts:AssumeRole", "sts:TagSession"])
67
trusted_role_arns = try(each.value.trusted_role_arns, var.defaults.trusted_role_arns, [])
78
trusted_role_services = try(each.value.trusted_role_services, var.defaults.trusted_role_services, [])
89
mfa_age = try(each.value.mfa_age, var.defaults.mfa_age, 86400)

0 commit comments

Comments
 (0)