Infrastructure

GitHub Actions OIDC: migrate to immutable subjects before renaming a repository

A production runbook for migrating GitHub Actions federation to immutable OIDC subjects, canarying the Entra ID exchange, and retiring the old contract without bringing back a secret.

16 Nov 2026 github-actionsazuremicrosoft-entraworkload-identityoidcfederated-credentialsimmutable-subjectsidentitydevopssecuritycanaryrunbookrollbackproduction

A GitHub Actions workflow has deployed to Azure through OIDC for months. No client secret is stored, the federated credential targets main, and Azure roles are limited to the production resource group. The team now needs to rename or transfer the repository.

The original OIDC subject depends on the owner and repository names. The token exchange can fail after the change; more importantly, a released namespace can be reused and produce the same subject. GitHub now has an immutable format that adds the numeric owner and repository IDs. New GitHub.com repositories created after July 15, 2026 use it by default, and a rename or transfer after that date can also move a repository to the new format. Older repositories can opt in; GitHub Enterprise Server is not covered.

This runbook prepares the migration before the name changes. It ends with one bounded decision: keep the new contract after a complete canary, defer the rename, or return to the historical subject without creating a client secret.

Freeze the contract that production actually uses

Start from a known-good production run. Preserve its run ID, commit, workflow, GitHub environment, branch or tag, tenant, Entra application and Azure scope. A branch, environment and pull request produce different subject suffixes; do not reconstruct the contract from the workflow name alone.

yaml 01-oidc-migration-scope.yml
change: CHG-OIDC-184
repository: platform/payments-api
workflow: .github/workflows/deploy.yml
job: deploy-production
context:
environment: production
ref: refs/heads/main

azure:
tenant_id: <tenant-guid>
application_object_id: <application-object-guid>
client_id: <application-client-guid>
subscription_id: <subscription-guid>
role_scope: /subscriptions/<subscription-guid>/resourceGroups/rg-payments-prod

current_subject: repo:platform/payments-api:environment:production
issuer: https://token.actions.githubusercontent.com
audience: api://AzureADTokenExchange

stop_conditions:
- application object is ambiguous
- current subject is not inventoried
- repository or owner id cannot be verified
- no credential slot is available
- rollback owner is absent

Microsoft Entra ID compares issuer, subject and audience case-sensitively. The application object ID administers the credential; azure/login uses the client ID. Confusing them can update the wrong application while leaving the workflow broken.

Build the immutable subject from GitHub IDs

Read the numeric IDs from GitHub instead of deriving them from names. The immutable format keeps names for readability, but appends owner_id and repository_id after an @ separator.

bash 02-inventory-repository-and-credentials.sh
set -euo pipefail

OWNER="platform"
REPO="payments-api"
APP_OBJECT_ID="<application-object-guid>"

gh api "repos/$OWNER/$REPO" --jq '{repository:.full_name,repository_id:.id,owner:.owner.login,owner_id:.owner.id}'

az ad app federated-credential list --id "$APP_OBJECT_ID" --query '[].{name:name,issuer:issuer,subject:subject,audiences:audiences}' --output yaml

For a branch, the candidate subject follows this form:

text 03-subject-comparison.txt
Historical subject
repo:platform/payments-api:ref:refs/heads/main

Immutable subject
repo:platform@<owner-id>/payments-api@<repository-id>:ref:refs/heads/main

Environment variant
repo:platform@<owner-id>/payments-api@<repository-id>:environment:production

Pull request variant
repo:platform@<owner-id>/payments-api@<repository-id>:pull_request

Use the job’s exact context. When a job references an environment, the subject carries the environment instead of the branch. If an environment name contains :, GitHub encodes it as %3A. An almost identical contract is still a different contract.

Check identity capacity as well: an application or user-assigned managed identity supports at most twenty federated credentials. If every slot is occupied, retire a proven orphan with an owner and evidence first; do not delete the active production contract merely to make room during the migration.

Add the new credential before changing GitHub

Create a second credential on the same application, with the same issuer and audience. Change neither Azure roles nor the workflow in this step. Coexistence keeps the old path working while GitHub still emits the historical subject.

json 04-immutable-federated-credential.json
{
"name": "payments-api-production-immutable",
"issuer": "https://token.actions.githubusercontent.com",
"subject": "repo:platform@<owner-id>/payments-api@<repository-id>:environment:production",
"audiences": ["api://AzureADTokenExchange"],
"description": "GitHub Actions production deployment using immutable repository identity"
}
bash 05-create-immutable-credential.sh
set -euo pipefail
APP_OBJECT_ID="<application-object-guid>"

az ad app federated-credential create --id "$APP_OBJECT_ID" --parameters 04-immutable-federated-credential.json

az ad app federated-credential list --id "$APP_OBJECT_ID" --query '[].{name:name,subject:subject,audiences:audiences}' --output table

For a user-assigned managed identity, use that identity’s federated credential API instead of az ad app. In both cases, retain the old and new subjects through the canary. Do not replace coexistence with a wildcard: classic Entra federated credentials expect an exact subject.

Preview, then enable the format in GitHub

In the repository or organization OIDC settings, use GitHub’s preview to confirm the subject that will be emitted. Compare the complete string with the Entra credential, then enable immutable subjects at the intended scope. Configure the cloud first and GitHub second; reversing the order creates a window in which no credential matches.

Do not combine this migration with a sub customization, a new job_workflow_ref requirement, an environment change or the repository transfer itself. Immutable IDs remain present in customized subjects, but changing several dimensions makes both the canary and rollback ambiguous.

The workflow must request an OIDC token explicitly and keep permissions narrow:

yaml 06-oidc-canary.yml
name: oidc-immutable-canary
on:
workflow_dispatch:

permissions:
id-token: write
contents: read

jobs:
verify:
  environment: production
  runs-on: ubuntu-latest
  steps:
    - uses: azure/login@v3
      with:
        client-id: ${{ vars.AZURE_CLIENT_ID }}
        tenant-id: ${{ vars.AZURE_TENANT_ID }}
        subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}

    - name: Prove identity and bounded access
      shell: bash
      run: |
        set -euo pipefail
        az account show --query '{tenant:tenantId,subscription:id,user:user.name}' -o yaml
        az group show --name rg-payments-prod --query '{id:id,name:name}' -o yaml
        if az group show --name rg-negative-control >/dev/null 2>&1; then
          echo "Negative RBAC control unexpectedly succeeded" >&2
          exit 1
        fi

The positive read proves token exchange and intended scope. The negative control proves that the migration did not broaden authorization. A complete deployment is unnecessary to qualify identity and adds an avoidable side effect.

Correlate the canary and locate drift

Preserve the run ID, UTC time, client ID, resulting principal and Entra correlation ID. An AADSTS700213 after enablement usually means the presented subject matches no credential. AuthorizationFailed happens later: exchange worked, and the problem is Azure RBAC or the command scope.

kusto 07-oidc-canary-signins.kql
let Start = datetime(2026-11-16T08:00:00Z);
let End = Start + 1h;
let ClientId = "<application-client-guid>";
AADServicePrincipalSignInLogs
| where TimeGenerated between (Start .. End)
| where AppId == ClientId
| project TimeGenerated,
        AppDisplayName,
        ServicePrincipalId,
        ResourceDisplayName,
        ResultType,
        ResultDescription,
        CorrelationId,
        IPAddress
| order by TimeGenerated desc

Adapt the query to the table actually routed to the workspace. No matching Entra event points back to id-token permission, the workflow or GitHub token acquisition. A successful sign-in followed by an ARM denial points to roles rather than the OIDC subject.

Rename only after proof, then retire the old subject

The canary must pass before and after the planned rename or transfer. Confirm that the numeric repository and owner IDs remain the expected values, GitHub emits the immutable subject, the Entra principal is unchanged, and the negative control remains denied.

Remove the historical credential only after an observation window covers the triggers that production actually uses: manual dispatch, push, tag or production environment. Inventory other workflows that shared the old subject; deleting it too soon can break a nightly job that was absent from the canary.

The normal rollback is to defer the rename or, before deletion, re-enable the historical format in GitHub and replay the canary while the old credential still exists. After a rename that forces the immutable format, restore the exact candidate credential instead of adding a secret. Keep both contracts only as long as necessary: the name-based subject remains exposed to namespace recycling.

Decide and close the change

Promote the immutable subject when the candidate credential exists before enablement, the positive canary succeeds, the negative control fails, sign-ins resolve to the same principal, and every required trigger is covered. Then delete the historical credential and confirm that no workflow still depends on it.

Defer when the previewed subject differs, IDs are ambiguous, the credential limit prevents coexistence, or the workflow cannot be tested without an effect. Return to the historical contract before renaming when the canary fails, without changing roles or creating a client secret.

Conclusion

A name-based OIDC subject is convenient, but the name can change or be reused. The immutable subject binds federation to the durable identity of the repository and owner; the migration still has to be operated as an observable production change.

The sequence is strict: inventory, create the candidate credential, preview, enable, canary, rename, observe, then retire the old subject. It turns a potentially blocking repository change into a reversible cutover without widening Azure RBAC or putting a secret back into the delivery chain.