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] Readonly role OIDC federation enabled + kms decrypt optional #195

Merged
merged 1 commit into from
May 21, 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
2 changes: 2 additions & 0 deletions aws-iam-role-readonly/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ No requirements.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| authorize\_read\_secrets | Should this role also be authorized to decrypt and read secrets. | `bool` | `true` | no |
| 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` | `"readonly"` | 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
28 changes: 25 additions & 3 deletions aws-iam-role-readonly/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" "readonly" {
Expand Down Expand Up @@ -65,6 +85,8 @@ data "aws_iam_policy_document" "secrets" {
}

resource "aws_iam_role_policy" "secrets" {
count = var.authorize_read_secrets ? 1 : 0

name = "secrets"
role = aws_iam_role.readonly.name
policy = data.aws_iam_policy_document.secrets.json
Expand Down
19 changes: 19 additions & 0 deletions aws-iam-role-readonly/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,22 @@ variable "saml_idp_arn" {
default = ""
description = "The AWS SAML IDP arn to establish a trust relationship. Ignored if empty or not provided."
}

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."
}

variable authorize_read_secrets {
type = bool
description = "Should this role also be authorized to decrypt and read secrets."
default = true
}