diff --git a/aws-iam-role-poweruser/README.md b/aws-iam-role-poweruser/README.md index 49aeb48d..60da4ade 100644 --- a/aws-iam-role-poweruser/README.md +++ b/aws-iam-role-poweruser/README.md @@ -32,6 +32,7 @@ No requirements. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | iam\_path | n/a | `string` | `"/"` | no | +| oidc | A list of AWS OIDC IDPs to establish a trust relationship for this role. |
list(object(
{
idp_arn : string, # the AWS IAM IDP arn
client_ids : list(string), # a list of oidc client ids
provider : string # your provider url, such as foo.okta.com
}
))
| `[]` | no | | role\_name | n/a | `string` | `"poweruser"` | no | | saml\_idp\_arn | The AWS SAML IDP arn to establish a trust relationship. Ignored if empty or not provided. | `string` | `""` | no | | 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 | diff --git a/aws-iam-role-poweruser/main.tf b/aws-iam-role-poweruser/main.tf index 80023d0a..a329361c 100755 --- a/aws-iam-role-poweruser/main.tf +++ b/aws-iam-role-poweruser/main.tf @@ -6,7 +6,7 @@ data "aws_iam_policy_document" "assume-role" { type = "AWS" identifiers = ["arn:aws:iam::${statement.value}:root"] } - actions = ["sts:AssumeRole"] + actions = ["sts:AssumeRole", "sts:TagSession"] } } @@ -17,7 +17,7 @@ data "aws_iam_policy_document" "assume-role" { type = "AWS" identifiers = ["arn:aws:iam::${statement.value}:root"] } - actions = ["sts:AssumeRole"] + actions = ["sts:AssumeRole", "sts:TagSession"] } } @@ -29,7 +29,7 @@ data "aws_iam_policy_document" "assume-role" { identifiers = [statement.value] } - actions = ["sts:AssumeRoleWithSAML"] + actions = ["sts:AssumeRoleWithSAML", "sts:TagSession"] condition { test = "StringEquals" @@ -38,6 +38,26 @@ data "aws_iam_policy_document" "assume-role" { } } } + + dynamic "statement" { + for_each = var.oidc + iterator = oidc + + content { + principals { + type = "Federated" + identifiers = [oidc.value["idp_arn"]] + } + + actions = ["sts:AssumeRoleWithWebIdentity", "sts:TagSession"] + condition { + test = "StringEquals" + variable = "${oidc.value["provider"]}:aud" + values = oidc.value["client_ids"] + } + } + } + } resource "aws_iam_role" "poweruser" { diff --git a/aws-iam-role-poweruser/variables.tf b/aws-iam-role-poweruser/variables.tf index 181ca6ad..4eaafe34 100755 --- a/aws-iam-role-poweruser/variables.tf +++ b/aws-iam-role-poweruser/variables.tf @@ -25,3 +25,16 @@ variable "iam_path" { type = string default = "/" } + +variable oidc { + type = list(object( + { + idp_arn : string, # the AWS IAM IDP arn + client_ids : list(string), # a list of oidc client ids + provider : string # your provider url, such as foo.okta.com + } + )) + + default = [] + description = "A list of AWS OIDC IDPs to establish a trust relationship for this role." +}