Skip to content

Commit 07eaee6

Browse files
authored
feat(github-oidc_iam-role): improve trust policy config (#17)
- switch `sub` from `string` to `set(string)` - add `repo_owners` arg for configurability
1 parent 6e0eaf5 commit 07eaee6

3 files changed

Lines changed: 35 additions & 6 deletions

File tree

github-oidc-iam-role/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ module "oidc_github_iam_role" {
4444
"arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess"
4545
]
4646
47+
repo_owners = [
48+
"my-owner"
49+
]
50+
51+
sub = [
52+
"repo:my-owner/my-repo:ref:refs/heads/*"
53+
]
54+
4755
tags = {
4856
Project = "my-project"
4957
Service = "my-service"

github-oidc-iam-role/data.tf

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,27 @@ data "aws_iam_policy_document" "assume_role_policy" {
1616
condition {
1717
test = "StringEquals"
1818
variable = "token.actions.githubusercontent.com:aud"
19-
values = ["sts.amazonaws.com"]
19+
values = ["sts.amazonaws.com"]
2020
}
2121

22-
condition {
23-
test = "StringLike"
24-
variable = "token.actions.githubusercontent.com:sub"
25-
values = ["repo:${var.sub}"]
22+
dynamic "condition" {
23+
for_each = length(var.repo_owners) > 0 ? [1] : []
24+
25+
content {
26+
test = "StringEquals"
27+
variable = "token.actions.githubusercontent.com:repository_owner"
28+
values = var.repo_owners
29+
}
30+
}
31+
32+
dynamic "condition" {
33+
for_each = length(var.sub) > 0 ? [1] : []
34+
35+
content {
36+
test = "StringLike"
37+
variable = "token.actions.githubusercontent.com:sub"
38+
values = var.sub
39+
}
2640
}
2741
}
2842
}

github-oidc-iam-role/variables.tf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@ variable "policy_arns" {
2222
default = []
2323
}
2424

25+
variable "repo_owners" {
26+
type = set(string)
27+
description = "Set of repo owners for the assume role policy"
28+
default = []
29+
}
30+
2531
variable "sub" {
26-
type = string
32+
type = set(string)
2733
description = "The sub pattern for the assume role policy (e.g. org/repo:ref:refs/heads/master)"
34+
default = []
2835
}
2936

3037
variable "tags" {

0 commit comments

Comments
 (0)