Skip to content

Commit

Permalink
feat: Ensure that GitHub OIDC subject prefixes are normalied for `rep…
Browse files Browse the repository at this point in the history
…o:` (terraform-aws-modules#310)

Co-authored-by: Anton Babenko <[email protected]>
  • Loading branch information
bryantbiggs and antonbabenko authored Nov 21, 2022
1 parent 4bd4c1e commit b9873a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 7 additions & 1 deletion examples/iam-github-oidc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ module "iam_github_oidc_provider_disabled" {
module "iam_github_oidc_role" {
source = "../../modules/iam-github-oidc-role"

name = local.name

# This should be updated to suit your organization, repository, references/branches, etc.
subjects = ["terraform-aws-modules/terraform-aws-iam:*"]
subjects = [
# You can prepend with `repo:` but it is not required
"repo:terraform-aws-modules/terraform-aws-iam:pull_request",
"terraform-aws-modules/terraform-aws-iam:ref:refs/heads/master",
]

policies = {
additional = aws_iam_policy.additional.arn
Expand Down
3 changes: 2 additions & 1 deletion modules/iam-github-oidc-role/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ data "aws_iam_policy_document" "this" {
condition {
test = "StringLike"
variable = "${local.provider_url}:sub"
values = [for subject in var.subjects : "repo:${subject}"]
# Strip `repo:` to normalize for cases where users may prepend it
values = [for subject in var.subjects : "repo:${trimprefix(subject, "repo:")}"]
}
}
}
Expand Down

0 comments on commit b9873a0

Please sign in to comment.