Skip to main content

Wildcard Federated Credentials Widen UAMI Blast Radius

Critical severityAzure About 20 minutes to fix

Overview

A flexible federated credential (preview) whose matching expression accepts any GitHub environment, paired with Contributor at subscription scope, lets a workflow meant for one resource group change resources across the subscription. Classic federated credentials match the subject exactly.

At a glance

Symptom
A GitHub Actions workflow in any environment matching the wildcard subject requests an OIDC token and assumes the identity outside its intended resource group.
Likely cause
User-assigned managed identity granted Contributor at subscription scope with a federated credential subject using an environment wildcard.
Impact
The compromised or misdirected workflow gains Contributor rights across every resource group in the subscription, not just its target.
Verification signal
Re-run the detection test and a controlled negative-path test.
Safe correction
Scope role assignments to exact resource group ARM IDs and pin federated credential subjects to exact repo, branch and environment strings.
Rollback or recovery
Restore the exported configuration if the new control blocks required production traffic, then narrow the policy before redeployment.

The Trap

Wildcard Federated Credential Subjects on Subscription-Scoped User-Assigned Managed Identities. A user-assigned managed identity (UAMI) is created for GitHub Actions deployment, and a flexible federated credential (a preview feature) matches the subject claim with a wildcard — for example repo:org/repo:environment:* or repo:org/repo:ref:refs/heads/* — instead of an exact string. The same identity’s role assignment is then created at subscription or management group scope rather than against the single resource group it is meant to deploy into.

The Default State

The Azure Portal’s role assignment wizard opens with the subscription pre-selected in the scope picker; drilling down to a resource group is an extra step most engineers skip when time-pressured. Command-line users copy a working az role assignment create --role Contributor --scope /subscriptions/{subId} snippet from internal documentation and never narrow it.

On the federation side, a classic credential’s --subject must match the token exactly (a literal * never matches), so teams wanting to cover multiple branches or environments create one flexible credential with a matches expression in the portal or through Microsoft Graph rather than maintaining a federated credential per pipeline stage.

The Blast Radius

Microsoft Entra ID’s token exchange checks issuer, audience and subject (or the flexible matching expression) only — it has no concept of resource group boundaries. Once a workflow run produces a token whose subject satisfies the wildcard, it receives the identity’s access token with whatever RBAC scope that identity holds.

If the identity is Contributor at subscription level, a workflow intended to deploy a single storage account can instead modify network security groups in the production networking resource group, read secrets from an unrelated Key Vault, or delete resources in a resource group it has never touched.

A dependency-confusion compromise in a low-trust repository environment therefore escalates into subscription-wide write access, and any anomaly alerting fires only after the damage, not before it.

The Lead Mechanic Fix

Scope every managed identity role assignment to the exact resource group ARM ID: az role assignment create --role Contributor --scope /subscriptions/{subId}/resourceGroups/{rgName} --assignee-object-id {principalId} --assignee-principal-type ServicePrincipal, then remove any broader grant with az role assignment delete --assignee {principalId} --scope /subscriptions/{subId}. Where possible, replace Contributor with a custom role limited to the resource types the pipeline actually deploys: Conditional Access for workload identities does not cover managed identities, so role scope and the federated credential match are the only limits on this identity. Replace flexible matching expressions with credentials pinned to exact repository, branch and environment strings — one credential per pipeline stage, e.g. az identity federated-credential create --name gh-deploy-prod --identity-name uami-prod --resource-group rg-identity --issuer https://token.actions.githubusercontent.com --subject "repo:org/repo:environment:prod" --audiences api://AzureADTokenExchange. Enforce the scope rule with an Azure Policy definition that denies Microsoft.Authorization/roleAssignments writes above resource group scope for a parameterised list of workload identity principal IDs, and audit quarterly with az role assignment list --all --query "[?principalType=='ServicePrincipal']".

3

Apply the safer control

Before you change production

Confirm the affected scope, export the current configuration, and test the replacement control in a non-production environment first.

Fix commands and configuration

az role assignment create --role Contributor --scope /subscriptions/{subId}/resourceGroups/{rgName} --assignee-object-id {principalId} --assignee-principal-type ServicePrincipal
az role assignment delete --assignee {principalId} --scope /subscriptions/{subId}
az identity federated-credential create --name gh-deploy-prod --identity-name uami-prod --resource-group rg-identity --issuer https://token.actions.githubusercontent.com --subject "repo:org/repo:environment:prod" --audiences api://AzureADTokenExchange
4

Verify, roll back or escalate

Verify

Re-run the detection test and a controlled negative-path test. Confirm the unsafe behaviour is blocked while approved traffic still succeeds.

Rollback

Restore the exported configuration if the new control blocks required production traffic, then narrow the policy before redeployment.

Escalate

Escalate when the blast radius is uncertain, the control cannot be tested safely, or remediation requires an outage or security exception.

The KBY Brief

Fixed? Get the next one before it hits you: The KBY Brief

Practical fixes for the systems you run, by email about twice a week. Unsubscribe at any time.

About this page

Credited to

Dates

Published

Last updated

Corrections

No corrections are listed for this page. Some review sweeps corrected pages without naming each one; those are in the corrections log.

Was this useful?

Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.

After remediation

Further reading stays below the corrective workflow and is selected by platform, category and shared technical keywords.

More from KBY that goes with this config trap.