Overview
OpenID Connect (OIDC) allows your GitHub Actions workflows to access resources in Azure, without needing to store the Azure credentials as long-lived GitHub secrets.
This guide gives an overview of how to configure Azure to trust GitHub's OIDC as a federated identity, and includes a workflow example for the azure/login
action that uses tokens to authenticate to Azure and access resources.
Prerequisites
-
Para aprender los conceptos básicos de cómo GitHub utiliza OpenID Connect (OIDC) y su arquitectura y beneficios, consulta la sección "Acerca del fortalecimiento de seguridad con OpenID Connect".
-
Antes de proceder, debes planear tu estrategia de seguridad para garantizar que los tokens de acceso solo se asignen de forma predecible. Para controlar la forma en la que tu proveedor de servicios en la nube emite tokens de acceso, debes define por lo menos una condición para que los repositorios no confiables no puedan solicitar tokens de acceso para tus recursos en la nube. Para obtener más información, consulta la sección "Configurar la relación de confianza de OIDC con la nube".
Adding the Federated Credentials to Azure
GitHub's OIDC provider works with Azure's workload identity federation. For an overview, see Microsoft's documentation at "Workload identity federation."
To configure the OIDC identity provider in Azure, you will need to perform the following configuration. For instructions on making these changes, refer to the Azure documentation.
- Create an Azure Active Directory application and a service principal.
- Add federated credentials for the Azure Active Directory application.
- Create GitHub secrets for storing Azure configuration.
Additional guidance for configuring the identity provider:
- For security hardening, make sure you've reviewed "Configuring the OIDC trust with the cloud". For an example, see "Configuring the subject in your cloud provider".
- For the
audience
setting,api://AzureADTokenExchange
is the recommended value, but you can also specify other values here.
Updating your GitHub Actions workflow
To update your workflows for OIDC, you will need to make two changes to your YAML:
- Add permissions settings for the token.
- Use the
azure/login
action to exchange the OIDC token (JWT) for a cloud access token.
Adding permissions settings
The job or workflow run requires a permissions
setting with id-token: write
. You won't be able to request the OIDC JWT ID token if the permissions
setting for id-token
is set to read
or none
.
The id-token: write
setting allows the JWT to be requested from GitHub's OIDC provider using one of these approaches:
- Using environment variables on the runner (
ACTIONS_ID_TOKEN_REQUEST_URL
andACTIONS_ID_TOKEN_REQUEST_TOKEN
). - Using
getIDToken()
from the Actions toolkit.
Si solo necesitas recuperar un token de OIDC para un solo job, entonces este permiso puede configurarse dentro de dicho job. Por ejemplo:
permissions:
id-token: write
Puede que necesites especificar permisos adicionales aquí, dependiendo de los requisitos de tu flujo de trabajo.
Requesting the access token
The azure/login
action receives a JWT from the GitHub OIDC provider, and then requests an access token from Azure. For more information, see the azure/login
documentation.
The following example exchanges an OIDC ID token with Azure to receive an access token, which can then be used to access cloud resources.
name: Run Azure Login with OIDC
on: [push]
permissions:
id-token: write
contents: read
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: 'Az CLI login'
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: 'Run az commands'
run: |
az account show
az group list