fix(terraform): CKV_AZURE_249 should flag pull_request OIDC subjects - #7627
fix(terraform): CKV_AZURE_249 should flag pull_request OIDC subjects#7627Dashtid 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.
ce473dd to
ff33043
Compare
|
It doesn't appear specific to this branch: the same The branch is unchanged since it was opened and still merges cleanly. Happy to push a rebase if re-queuing is the easier path — or would approving the existing run in place be preferable, given a fresh run would start the same 30-day clock over? |
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.