fix(terraform): CKV_AZURE_249 should flag pull_request OIDC subjects - #7627
Open
Dashtid wants to merge 1 commit into
Open
fix(terraform): CKV_AZURE_249 should flag pull_request OIDC subjects#7627Dashtid wants to merge 1 commit into
Dashtid wants to merge 1 commit into
Conversation
A federated identity credential whose subject is "repo:<org>/<repo>:pull_request" trusts tokens minted by pull_request-triggered workflow runs, which execute proposed changes rather than the protected default branch (and on public repositories may originate from a fork). CKV_AZURE_249 passed such subjects. Add one comparison after the existing repo-format check, matching only the event segment of a repo: subject so that an environment, ref, or repository merely NAMED "pull_request" is unaffected. No shared helper is touched, so CKV_AWS_358 / CKV_AWS_393 / CKV_GCP_125 are unchanged. Fixtures cover the flagged subject and the environment-named-pull_request precision boundary.
Dashtid
force-pushed
the
fix/ckv-azure-249-pull-request
branch
from
July 30, 2026 08:44
ce473dd to
ff33043
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Description
CKV_AZURE_249currently passes a federated identity credential whose subject isrepo:<org>/<repo>:pull_request.That subject matches tokens minted by
pull_request-triggered workflow runs — runs that execute a proposed change rather than the protected default branch. GitHub's security-hardening guidance treats thepull_requestsubject as a distinct, broader trust surface for exactly this reason: the code that runs during a pull request has not necessarily been reviewed or merged, and on public repositories it can originate from a fork.Since an Azure FIC subject is an exact string match, a credential written this way trusts every pull-request run of that repository. The check inspects the subject closely enough to reject wildcards and abusable leading claims, so this seemed like a gap in the same family rather than an intentional allowance.
Change
One additional comparison in
scan_resource_conf, after the existing repo-format check:It matches only the event segment (index 2) of a
repo:subject, so it is deliberately narrow:repo:myOrg/myRepo:pull_requestrepo:myOrg/myRepo:environment:pull_requestpull_request)repo:myOrg/pull_request:ref:refs/heads/xpull_request)repo:myOrg/myRepo:ref:refs/heads/mainrepo:myOrg/myRepo:environment:Productionrepo:*,*,workflow:...No other check or shared helper is touched, so
CKV_AWS_358/CKV_AWS_393/CKV_GCP_125are unaffected (their suites pass unchanged).Tests
Two fixtures:
fail_pull_request(the flagged subject) andpass_environment_named_pull_request, which pins the precision boundary so a later broadened match would fail the suite.References:
pull_request): https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connectChecklist:
Two things I noticed while working in this file and left alone, in case they are of interest:
validate_subject_claimappears to be unused —scan_resource_confre-implements the same sequence inline, and I could not find a caller. I mirrored the new condition into both so they do not drift further, but would removing it (or havingscan_resource_confcall it) be preferable?The check registers only
azuread_application_federated_identity_credential. The AzureAD provider addedazuread_application_flexible_federated_identity_credentialin 3.7, where matching moves to aclaims_matching_expressionand thematchesoperator honours*— soclaims['sub'] matches 'repo:org/*'there really does admit the whole org, unlike a classic FIC subject where*is an inert literal. Is flexible FIC out of scope by design, or would a follow-up covering that resource be welcome?Note on overlap: #7610 (immutable OIDC subject IDs) adds a fixture to the same two Azure test files, so whichever of the two lands first will leave the other with a small fixture-level conflict. The changes are independent — that one widens
gh_repo_regex, this one adds an event-segment comparison — and I am happy to rebase whichever comes second.