Skip to content

Commit bd7a439

Browse files
author
Eduardo Lopez
authored
[feature] AWS Poweruser role allows OIDC sts:AssumeRoleWithWebIdentity (#192)
1 parent 28c40d0 commit bd7a439

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

aws-iam-role-poweruser/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ No requirements.
3232
| Name | Description | Type | Default | Required |
3333
|------|-------------|------|---------|:--------:|
3434
| iam\_path | n/a | `string` | `"/"` | no |
35+
| oidc | A list of AWS OIDC IDPs to establish a trust relationship for this role. | <pre>list(object(<br> {<br> idp_arn : string, # the AWS IAM IDP arn<br> client_ids : list(string), # a list of oidc client ids<br> provider : string # your provider url, such as foo.okta.com<br> }<br> ))</pre> | `[]` | no |
3536
| role\_name | n/a | `string` | `"poweruser"` | no |
3637
| saml\_idp\_arn | The AWS SAML IDP arn to establish a trust relationship. Ignored if empty or not provided. | `string` | `""` | no |
3738
| source\_account\_id | The source AWS account to establish a trust relationship. Ignored if empty or not provided. DEPRECATED: Please use source\_account\_ids. | `string` | `""` | no |

aws-iam-role-poweruser/main.tf

+23-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ data "aws_iam_policy_document" "assume-role" {
66
type = "AWS"
77
identifiers = ["arn:aws:iam::${statement.value}:root"]
88
}
9-
actions = ["sts:AssumeRole"]
9+
actions = ["sts:AssumeRole", "sts:TagSession"]
1010
}
1111
}
1212

@@ -17,7 +17,7 @@ data "aws_iam_policy_document" "assume-role" {
1717
type = "AWS"
1818
identifiers = ["arn:aws:iam::${statement.value}:root"]
1919
}
20-
actions = ["sts:AssumeRole"]
20+
actions = ["sts:AssumeRole", "sts:TagSession"]
2121
}
2222
}
2323

@@ -29,7 +29,7 @@ data "aws_iam_policy_document" "assume-role" {
2929
identifiers = [statement.value]
3030
}
3131

32-
actions = ["sts:AssumeRoleWithSAML"]
32+
actions = ["sts:AssumeRoleWithSAML", "sts:TagSession"]
3333

3434
condition {
3535
test = "StringEquals"
@@ -38,6 +38,26 @@ data "aws_iam_policy_document" "assume-role" {
3838
}
3939
}
4040
}
41+
42+
dynamic "statement" {
43+
for_each = var.oidc
44+
iterator = oidc
45+
46+
content {
47+
principals {
48+
type = "Federated"
49+
identifiers = [oidc.value["idp_arn"]]
50+
}
51+
52+
actions = ["sts:AssumeRoleWithWebIdentity", "sts:TagSession"]
53+
condition {
54+
test = "StringEquals"
55+
variable = "${oidc.value["provider"]}:aud"
56+
values = oidc.value["client_ids"]
57+
}
58+
}
59+
}
60+
4161
}
4262

4363
resource "aws_iam_role" "poweruser" {

aws-iam-role-poweruser/variables.tf

+13
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,16 @@ variable "iam_path" {
2525
type = string
2626
default = "/"
2727
}
28+
29+
variable oidc {
30+
type = list(object(
31+
{
32+
idp_arn : string, # the AWS IAM IDP arn
33+
client_ids : list(string), # a list of oidc client ids
34+
provider : string # your provider url, such as foo.okta.com
35+
}
36+
))
37+
38+
default = []
39+
description = "A list of AWS OIDC IDPs to establish a trust relationship for this role."
40+
}

0 commit comments

Comments
 (0)