OIDC allows workflows to authenticate and interact with Azure using short-lived tokens. This removes the need for long-lived personal access tokens (PATs) or a service principal with a secret. It is a more secure and manageable way to reach cloud resources directly from GitHub Actions.
Configuration: You configure your Azure AD App Registration to trust an external identity provider by setting up a federation with that IdP. This involves specifying details about the IdP, such as the issuer URL, and possibly uploading metadata documents for SAML-based federations.
Authentication Flow: A user or service attempts to access an application protected by Azure AD and is redirected to sign in. Instead of presenting Azure AD credentials, the user or service presents credentials from the federated IdP. The federated IdP authenticates the user or service and issues a token. This token is presented to Azure AD, which validates it based on the trust configuration. Upon successful validation, Azure AD issues its own token to the user or service, granting access to the application.
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
jobs:
task_leveraging_oidc_login:
runs-on: ubuntu-latest
steps:
- name: checkout_github_action_code
uses: actions/checkout@v4
with:
ref: main
# Option 1: Using azure-cli
- name: azure_oidc_login
uses: azure/login@v1
with:
client-id: $
tenant-id: $
allow-no-subscriptions: true
- name: capture_azure_tokens
run: |
# https://learn.microsoft.com/en-us/cli/azure/account?view=azure-cli-latest#az-account-get-access-token
# [--resource-type {aad-graph, arm, batch, data-lake, media, ms-graph, oss-rdbms}]
export MG_TOKEN="$(az account get-access-token --resource-type ms-graph --query accessToken -o tsv)"
export AZ_TOKEN="$(az account get-access-token --resource-type arm --query accessToken -o tsv)"
echo "MG_TOKEN=$MG_TOKEN" >> $GITHUB_ENV # To use in another step
echo "AZ_TOKEN=$AZ_TOKEN" >> $GITHUB_ENV
curl -sH "Content-Type: application/json" -H "Authorization: Bearer ${AZ_TOKEN}" -X GET "https://management.azure.com/subscriptions?api-version=2022-12-01" | jq
# Option 2: Using the oidctok binary (RECOMMENDED)
- name: install_oidctok
run: go install github.com/queone/gkit/cmd/oidctok@latest
# Appends AZ_TOKEN and MG_TOKEN to GITHUB_ENV, so every later step sees them
- name: get_azure_tokens
run: oidctok
env:
CLIENT_ID: $
TENANT_ID: $
# Option 3: Using the Python script
# See https://github.com/queone/gkit/blob/main/scripts/get_oidc_tokens.py
- name: some_other_step
run: |
curl -sH "Content-Type: application/json" -H "Authorization: Bearer $" -X GET "https://graph.microsoft.com/v1.0/users" | jq
A Github workflow action can be setup to You can - Using Azure as a sample cloud provider
GitHub GitHub Workflow Action Microsoft
│ │ │
│ 1. Give me JWT token │ │
│ ◄──────────────────────── │ │
│ │ │
│ 2. Returns JWT token │ │
│ ────────────────────────► │ │
│ │ │
│ │ │
│ │ 3. Give me Azure ARM │
│ │ and MS Graph tokens │
│ │ ──────────────────────────► │
│ │ │
│ │ 4. Returns each token │
│ │ ◄────────────────────────── │
│
│
MS Graph │ Azure ARM
│ │ │
│ 5. Update MS Graph X │ │
│ object using token │ │
│ ◄──────────────────────── │ │
│ │ │
│ 6. Update done │ │
│ ────────────────────────► │ │
│ │ │
│ │ 7. Update Azure ARM X │
│ │ object using token │
│ │ ──────────────────────────► │
│ │ │
│ │ 8. Update done │
│ │ ◄────────────────────────── │
This document explains how OpenID Connect (OIDC) authentication works between a program (like a GitHub workflow) and Azure. It also covers what it takes for any program to be trusted by Azure.
When a GitHub workflow authenticates with Azure, it follows these steps:
Yes, any program can use OIDC to authenticate with Azure, provided it meets the following requirements:
issuer claim must match the trusted issuer (e.g., https://token.actions.githubusercontent.com for GitHub).subject claim must match the expected value (e.g., repo:<org/repo>:ref:refs/heads/main for a specific GitHub repository and branch).Azure trusts the GitHub OIDC token because:
https://token.actions.githubusercontent.com).issuer, subject, audience) match the conditions defined in the federated identity configuration.For any program to be trusted by Azure, you need to:
issuer, subject, audience).issuer, subject, audience values).If you want to write a custom program that uses OIDC to authenticate with Azure, here’s what you’d do:
issuer, subject, audience, etc.).issuer and subject values).In the OIDC authentication flow between GitHub and Azure, GitHub acts as the Identity Provider (IdP). Azure acts as the Relying Party (RP), also called the Service Provider (SP).
https://token.actions.githubusercontent.com/.well-known/openid-configuration) for Azure to retrieve public keys and configuration details.issuer, subject, audience) against the configured federated identity credentials.