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

feat: Ensure that GitHub OIDC subject prefixes are normalied for repo: #310

Merged
merged 2 commits into from
Nov 21, 2022
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
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