Repository navigation
feat: support use_immutable_subject and sub_claim_prefix on repository OIDC subject claim template - #3582
Conversation
|
👋 Hi, and thank you for this contribution! This repo is maintained by GitHub and community members on a best-effort basis. We'll get to this as soon as we can. You can help us prioritize by joining the discussion on open issues and PRs, sharing details on the changes you need, and reviewing other contributions. 🤖 This is an automated message. |
…y OIDC subject claim template Wires the use_immutable_subject and sub_claim_prefix fields (already present on go-github v89's OIDCSubjectClaimCustomTemplate struct) through the github_actions_repository_oidc_subject_claim_customization_template resource, allowing existing repositories to opt into GitHub's immutable OIDC subject claim format on a per-repository basis without an org-wide change. Closes integrations#3548
7878e57 to
08da046
Compare
|
Not a maintainer, just helping with review triage, so this is a comment rather than a review. Building on what @RulerOf found above: I checked the write side too, and Same derived value before and after, exactly as in @RulerOf's examples. That has two consequences for this PR specifically. The attribute is Separately, The field is dropped. This matters because opting back out does work at the API level: on the same throwaway repo I set it to There's an existing idiom for this in the repo: I haven't run the acceptance tests. |
## Link to Issue or Message thread - GitHub changelog: [Immutable subject claims for GitHub Actions OIDC tokens](https://github.blog/changelog/2026-04-23-immutable-subject-claims-for-github-actions-oidc-tokens/) ## Why is this change necessary? Since 2026-07-15, GitHub enables immutable OIDC subject claims for every newly created repository, and for any existing repository that is renamed or transferred. Their Actions tokens carry `sub = repo:<org>@<org_id>/<repo>@<repo_id>:<context>` instead of `repo:<org>/<repo>:<context>`. `create_oidc_assume_role_policy` only emitted the legacy form, so every OIDC role this template creates (ECR push, CodeArtifact, central-infra IaC, application OIDC, workload deploy/preview) rejects tokens from new repos. Existing repos keep the legacy format until opted in, and GitHub has announced no retirement date for it, so both formats must be trusted. ## How does this change address the issue? - New copier question `central_infra_github_organization_id` (validated as a positive integer, with help text explaining how to look it up), rendered into `GITHUB_ORG_IDS` in `iac_management/lib/constants.py`. - The trust policy `sub` condition now lists both `repo:<org>/<repo>:<ctx>` and `repo:<org>@<org_id>/<repo>@*:<ctx>`. The org ID is pinned; the repo ID is wildcarded (a TODO documents why that is acceptable and how to tighten it). - The `sub` condition always uses `StringLike` (previously `StringEquals` for ref-scoped roles), because the repo-ID wildcard would otherwise be compared literally and main-only roles would still reject new repos. - `GithubOidcConfig` validation: - restrictions may be `None` or a bare `*`; any other `*` or `?` is rejected, so `StringLike` cannot silently widen a scoped role - `repo_org` must have an entry in `GITHUB_ORG_IDS`, with an error that explains how to find the ID (replaces a bare `KeyError` at policy build time) - TODOs pointing at removing the legacy format once all repos use immutable subjects, and at managing `use_immutable_subject` from the `Repo` class once [terraform-provider-github#3582](integrations/terraform-provider-github#3582) ships. ## What side effects does this change have? - Every existing GitHub OIDC role's trust policy updates in place on the next deploy (`assumeRolePolicyDocument` only; no creates, deletes, or replaces). Verified in the downstream `aws-central-infrastructure` preview: 56 roles in artifact-stores and 15 in iac-management. - Ref-scoped roles switch from `StringEquals` to `StringLike`. For literal restrictions (e.g. `ref:refs/heads/main`) this matches exactly the same tokens, and the new validation prevents wildcard restrictions. - Consumers must answer the new `central_infra_github_organization_id` question on their next `copier update`. - Consumers that build OIDC roles for repos in a second GitHub org must add that org to `GITHUB_ORG_IDS`; the validation error says how. ## How is this change tested? - New unit tests in `template/tests/unit/iac_management/test_oidc_assume_role_policy.py` covering both `sub` patterns, ref-scoped roles, wildcard restriction rejection, bare `*` and explicit `None` restrictions, and unknown-org rejection. - Rendered locally with `tests/copier_data/data1.yaml` and checked the generated `constants.py` and `.copier-answers.yml`. downstream repo ## Other Developed and reviewed in `aws-central-infrastructure` first, then ported here commit by commit. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a setup question for the central infrastructure GitHub organization ID, with guidance for finding it. * OIDC role policies now support both legacy and immutable GitHub subject claims for known organizations. * Added validation for organization IDs and subject restrictions; unsupported wildcard patterns are rejected. <!-- end of auto-generated comment: release notes by coderabbit.ai -->


Summary
Wires
use_immutable_subjectandsub_claim_prefix— already present on go-github v89'sOIDCSubjectClaimCustomTemplatestruct — through togithub_actions_repository_oidc_subject_claim_customization_template.This lets a repository created before GitHub's July 15, 2026 immutable-subject-claims rollout opt in individually via Terraform, instead of requiring an org-wide toggle or an out-of-band REST call that Terraform can't track.
Changes
use_immutable_subject(bool, optional, computed) andsub_claim_prefix(string, optional, computed) added to the resource schemaCreateOrUpdateandRead, following the existingGetOk+new(...)pattern already used elsewhere in this resource (include_claim_keys) and in sibling resources (e.g.resource_github_enterprise_actions_workflow_permissions.go)docs/resources/...mdand its.tmplsource) and the example underexamples/resources/...updated to cover both new argumentsScoped to the repository-level resource only, matching the issue — the organization-level resource and this resource's
Deletebehavior are unchanged.Closes #3548
Test plan
TestAccGithubActionsRepositoryOIDCSubjectClaimCustomizationTemplate), since these require a live GitHub token this environment doesn't haveuse_default/include_claim_keysandcan_approve_pull_request_reviewspatterns for consistency