How GitHub OIDC Works
Workflow Permissions
The workflow runs with
permissions: id-token: write, causing the runner to prepare an OIDC tokenEnvironment Variables
GitHub injects
ACTIONS_ID_TOKEN_REQUEST_URL and ACTIONS_ID_TOKEN_REQUEST_TOKEN into the job environmentProvider Configuration
The provider automatically reads these environment variables during configuration
Benefits
No Secrets
Long-lived secrets don’t need to be stored in GitHub
Auto Rotation
Tokens are short-lived and automatically rotated
Conditional Access
Fine-grained control over which workflows can obtain tokens
Terraform Cloud Compatible
Works with both local and remote Terraform execution
Prerequisites
- A GitHub repository where you’ll run Terraform
- Permissions to create and configure app registrations in Microsoft Entra ID
- Ability to modify GitHub Actions workflows
- Azure CLI installed (for setup commands)
Setup
Subject Patterns
| Scenario | Subject Format | Example | |----------|----------------|---------|| | Specific branch |repo:ORG/REPO:ref:refs/heads/BRANCH | repo:octo-org/octo-repo:ref:refs/heads/main |
| Any branch | repo:ORG/REPO:* | repo:octo-org/octo-repo:* |
| Pull requests | repo:ORG/REPO:pull_request | repo:octo-org/octo-repo:pull_request |
| Specific tag | repo:ORG/REPO:ref:refs/tags/TAG | repo:octo-org/octo-repo:ref:refs/tags/v1.0.0 |
| Specific environment | repo:ORG/REPO:environment:ENV | repo:octo-org/octo-repo:environment:production |
GitHub Actions Workflow
Provider Configuration
- Environment Variables (Recommended)
- Terraform Configuration
oidc_request_url and oidc_request_token are automatically populated from ACTIONS_ID_TOKEN_REQUEST_URL and ACTIONS_ID_TOKEN_REQUEST_TOKEN.Security Best Practices
Troubleshooting
Missing Environment Variables
Missing Environment Variables
Error:
GitHub OIDC authentication requires oidc_request_url and oidc_request_tokenEnsure your workflow has the permissions: id-token: write directive properly configured.OIDC Provider Not Available
OIDC Provider Not Available
Error:
OIDC provider not availableThis happens when trying to use GitHub OIDC authentication outside a GitHub Actions workflow. The method only works within GitHub Actions.Federated Credential Configuration
Federated Credential Configuration
Error:
No matching federated identity record foundThe subject claim in the JWT doesn’t match any federated credential. Double-check that your subject pattern exactly matches your workflow’s context.Insufficient Permissions
Insufficient Permissions
Error:
Authorization_RequestDeniedThe app registration doesn’t have the necessary Microsoft Graph permissions. Grant permissions and admin consent: