Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] AWS Poweruser role allows OIDC sts:AssumeRoleWithWebIdentity #192

Merged
merged 2 commits into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions aws-iam-role-poweruser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. | <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 |
| 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 |
Expand Down
26 changes: 23 additions & 3 deletions aws-iam-role-poweruser/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
}

Expand All @@ -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"]
}
}

Expand All @@ -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"
Expand All @@ -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" {
Expand Down
13 changes: 13 additions & 0 deletions aws-iam-role-poweruser/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}