Skip to content

Commit d411f6f

Browse files
author
Eduardo Lopez
authored
[feature] Readonly role OIDC federation enabled + kms decrypt optional (#195)
1 parent df6db81 commit d411f6f

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

aws-iam-role-readonly/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ No requirements.
3535

3636
| Name | Description | Type | Default | Required |
3737
|------|-------------|------|---------|:--------:|
38+
| authorize\_read\_secrets | Should this role also be authorized to decrypt and read secrets. | `bool` | `true` | no |
3839
| iam\_path | n/a | `string` | `"/"` | no |
40+
| 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 |
3941
| role\_name | n/a | `string` | `"readonly"` | no |
4042
| saml\_idp\_arn | The AWS SAML IDP arn to establish a trust relationship. Ignored if empty or not provided. | `string` | `""` | no |
4143
| 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-readonly/main.tf

+25-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" "readonly" {
@@ -65,6 +85,8 @@ data "aws_iam_policy_document" "secrets" {
6585
}
6686

6787
resource "aws_iam_role_policy" "secrets" {
88+
count = var.authorize_read_secrets ? 1 : 0
89+
6890
name = "secrets"
6991
role = aws_iam_role.readonly.name
7092
policy = data.aws_iam_policy_document.secrets.json

aws-iam-role-readonly/variables.tf

+19
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,22 @@ variable "saml_idp_arn" {
2424
default = ""
2525
description = "The AWS SAML IDP arn to establish a trust relationship. Ignored if empty or not provided."
2626
}
27+
28+
variable oidc {
29+
type = list(object(
30+
{
31+
idp_arn : string, # the AWS IAM IDP arn
32+
client_ids : list(string), # a list of oidc client ids
33+
provider : string # your provider url, such as foo.okta.com
34+
}
35+
))
36+
37+
default = []
38+
description = "A list of AWS OIDC IDPs to establish a trust relationship for this role."
39+
}
40+
41+
variable authorize_read_secrets {
42+
type = bool
43+
description = "Should this role also be authorized to decrypt and read secrets."
44+
default = true
45+
}

0 commit comments

Comments
 (0)