Skip to content

Commit b9873a0

Browse files
feat: Ensure that GitHub OIDC subject prefixes are normalied for repo: (#310)
Co-authored-by: Anton Babenko <[email protected]>
1 parent 4bd4c1e commit b9873a0

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

examples/iam-github-oidc/main.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,14 @@ module "iam_github_oidc_provider_disabled" {
3737
module "iam_github_oidc_role" {
3838
source = "../../modules/iam-github-oidc-role"
3939

40+
name = local.name
41+
4042
# This should be updated to suit your organization, repository, references/branches, etc.
41-
subjects = ["terraform-aws-modules/terraform-aws-iam:*"]
43+
subjects = [
44+
# You can prepend with `repo:` but it is not required
45+
"repo:terraform-aws-modules/terraform-aws-iam:pull_request",
46+
"terraform-aws-modules/terraform-aws-iam:ref:refs/heads/master",
47+
]
4248

4349
policies = {
4450
additional = aws_iam_policy.additional.arn

modules/iam-github-oidc-role/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ data "aws_iam_policy_document" "this" {
4444
condition {
4545
test = "StringLike"
4646
variable = "${local.provider_url}:sub"
47-
values = [for subject in var.subjects : "repo:${subject}"]
47+
# Strip `repo:` to normalize for cases where users may prepend it
48+
values = [for subject in var.subjects : "repo:${trimprefix(subject, "repo:")}"]
4849
}
4950
}
5051
}

0 commit comments

Comments
 (0)