With the Azure Login Action, you can login to Azure and run Azure CLI and Azure PowerShell scripts.
Azure Login Action supports different ways of authentication with Azure.
We recommend using OIDC based authentication for increased security.
[!WARNING] By default, the output of Azure CLI commands is printed to the stdout stream. Without redirecting the stdout stream, contents in it will be stored in the build log of the action. Configure Azure CLI to not show output in the console screen or print in the log by setting the environment variable
AZURE_CORE_OUTPUTtonone. If you need the output of a specific command, override the default setting using the argument--outputwith your format of choice. For more information on output options with the Azure CLI, see Format output.
[!WARNING] Avoid using managed identity login on self-hosted runners in public repositories. Managed identities enable secure authentication with Azure resources and obtain Microsoft Entra ID tokens without the need for explicit credential management. Any user can open pull requests against your repository and access your self-hosted runners without credentials. See more details in self-hosted runner security.
[!WARNING] Only pass values from
${{ secrets.* }}intoclient-id,tenant-id,subscription-id, andcreds. Do not pipe values from${{ github.event.* }}(pull request titles, issue comments,workflow_dispatchinputs, branch names, etc.) into these inputs. Untrusted values in these fields can allow attackers to influence the Azure identity the action logs in as.
[!WARNING] Only set
enable-AzPSSession: trueif your workflow runs Azure PowerShell (Az.*) cmdlets. If your workflow only uses the Azure CLI (az ...), leaveenable-AzPSSessionunset (the default isfalse). Enabling it launches an additional PowerShell login step that is unnecessary for CLI-only workflows.
Azure Login follows a major-version support model.
| Version | Status |
|---|---|
| v3 | Supported |
| v2 | Maintenance mode (security fixes only) |
| v1 | End of Life (EOL) |
New features are released only to supported versions. Security fixes are released to supported versions and versions in maintenance mode.
Customers are strongly encouraged to use the latest v3 release.
GitHub Actions users can reference Azure Login using several forms.
uses: azure/login@v3
Receives compatible updates, including security fixes, released to the referenced major version.
uses: azure/login@v2.4.0
Remains pinned to that specific release and does not automatically receive future fixes or updates.
uses: azure/login@master
Receives updates from the referenced branch. For stable workflows, use a supported major-version tag or pin to a full-length commit SHA.
uses: azure/login@<full-length-commit-sha>
Remains pinned to that commit and does not automatically receive future fixes or updates.
Security fixes are released to supported versions and versions in maintenance mode. Customers using exact version tags or commit SHA references must explicitly upgrade to a patched release to receive security fixes.
# Automatically receives future v3 security updates
uses: azure/login@v3
# Does not automatically receive future updates
uses: azure/login@v2.4.0
Customers using v1 should migrate to v3. End-of-life releases no longer receive updates or security fixes.
| Parameter Name | Required? | Type | Default Value | Description |
|---|---|---|---|---|
| client-id | false | UUID | the client id of a service principal or a user-assigned managed identity | |
| subscription-id | false | UUID | the login subscription id | |
| tenant-id | false | UUID | the login tenant id | |
| creds | false | string | a json string for login with an Azure service principal | |
| enable-AzPSSession | false | boolean | false | if Azure PowerShell login is enabled |
| environment | false | string | azurecloud | the Azure Cloud environment. For cloud environments other than the public cloud, the audience will also need to be updated. |
| allow-no-subscriptions | false | boolean | false | if login without subscription is allowed |
| audience | false | string | api://AzureADTokenExchange | the audience to get the JWT ID token from GitHub OIDC provider |
| auth-type | false | string | SERVICE_PRINCIPAL | the auth type |
client-idThe input parameter client-id specifies the login client id. It could be the client id of a service principal or a user-assigned managed identity.
It's used in login with OpenID Connect (OIDC) and user-assigned managed identity.
It's better to create a GitHub Action secret for this parameter when using it. Refer to Using secrets in GitHub Actions.
Refer to Login With OpenID Connect (OIDC) and Login With User-assigned Managed Identity for its usage.
[!NOTE] The action registers the
client-idvalue as a secret (viacore.setSecret) so it is masked in workflow logs. Some enterprises treat the client ID as sensitive, and masking also prevents it from being printed accidentally, which matters in public repositories.tenant-idandsubscription-idare not masked.
subscription-idThe input parameter subscription-id specifies the login subscription id.
It's used in login with OpenID Connect (OIDC) and managed identity.
It's better to create a GitHub Action secret for this parameter when using it. Refer to Using secrets in GitHub Actions.
Refer to Login With OpenID Connect (OIDC), Login With System-assigned Managed Identity and Login With User-assigned Managed Identity for its usage.
tenant-idThe input parameter tenant-id specifies the login tenant id.
It's used in login with OpenID Connect (OIDC) and managed identity.
It's better to create a GitHub Action secret for this parameter when using it. Refer to Using secrets in GitHub Actions.
Refer to Login With OpenID Connect (OIDC), Login With System-assigned Managed Identity and Login With User-assigned Managed Identity for its usage.
creds[!NOTE]
If one of
client-idandsubscription-idandtenant-idis set,credswill be ignored.
The value of input parameter creds is a string in json format, including the following values:
{
"clientSecret": "******",
"subscriptionId": "******",
"tenantId": "******",
"clientId": "******"
}
It's used in login with an Azure service principal.
It's better to create a GitHub Action secret for this parameter when using it. Refer to Using secrets in GitHub Actions.
Refer to Login With a Service Principal Secret for its usage.
enable-AzPSSessionBy default, Azure Login Action only logs in with the Azure CLI. To log in with the Azure PowerShell module, set enable-AzPSSession to true.
Refer to Login With OpenID Connect (OIDC) for its usage.
environmentBy default, Azure Login Action connects to the Azure Public Cloud (AzureCloud).
To login to one of the Azure Government clouds or Azure Stack, set environment to one of the supported values AzureUSGovernment or AzureChinaCloud or AzureGermanCloud or AzureStack.
The default audience for each of these clouds is different and will also need to be set if using anything other than the public environment.
Refer to Login to Azure US Government cloud for its usage.
allow-no-subscriptionsBy default, Azure Login Action requires a subscription-id. To login to Azure tenants without any subscriptions, set allow-no-subscriptions to true.
Refer to Login without subscription for its usage.
audienceAzure Login Action gets the JWT ID token from GitHub OIDC provider when login with OIDC. The default audience is api://AzureADTokenExchange. Users can specify a custom audience.
auth-typeThe input parameter auth-type specifies the type of authentication. The default value is SERVICE_PRINCIPAL. Users can specify it as IDENTITY for login with Managed Identity.
Refer to Login With System-assigned Managed Identity and Login With User-assigned Managed Identity for its usage.
[!NOTE]
- Ensure the CLI version is 2.30 or above to support login with OIDC.
- By default, Azure access tokens issued during OIDC based login could have limited validity. Azure access token issued by Service Principal is expected to have an expiration of 1 hour by default. And with Managed Identities, it would be 24 hours. This expiration time is further configurable in Azure. Refer to access-token lifetime for more details.
Before you use Azure Login Action with OIDC, you need to configure a federated identity credential on a service principal or a managed identity.
After it, create GitHub Action secrets for following values: (Refer to Using secrets in GitHub Actions.)
Now you can try the workflow to login with OIDC.
[!NOTE]
In GitHub workflow, you should set
permissions:withid-token: writeat workflow level or job level based on whether the OIDC token is allowed be generated for all Jobs or a specific Job.
# File: .github/workflows/workflow.yml
name: Run Azure Login with OIDC
on: [push]
permissions:
id-token: write
contents: read
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Azure login
uses: azure/login@v3
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Azure CLI script
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: |
az account show
# File: .github/workflows/workflow.yml
name: Run Azure Login with OIDC
on: [push]
permissions:
id-token: write
contents: read
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Azure login
uses: azure/login@v3
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
enable-AzPSSession: true
- name: Azure CLI script
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: |
az account show
- name: Azure PowerShell script
uses: azure/powershell@v3
with:
azPSVersion: "latest"
inlineScript: |
Get-AzContext
Before you login a service principal secret, you need to prepare a service principal with a secret.
After it, create a GitHub Action secret AZURE_CREDENTIALS with the value like below: (Refer to Using secrets in GitHub Actions.)
{
"clientSecret": "******",
"subscriptionId": "******",
"tenantId": "******",
"clientId": "******"
}
Now you can try the workflow to login with a service principal secret.
# File: .github/workflows/workflow.yml
on: [push]
name: Run Azure Login With a Service Principal Secret
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: azure/login@v3
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Azure CLI script
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: |
az account show
# File: .github/workflows/workflow.yml
on: [push]
name: Run Azure Login With a Service Principal Secret
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: azure/login@v3
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true
- name: Azure CLI script
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: |
az account show
- name: Azure PowerShell script
uses: azure/powershell@v3
with:
azPSVersion: "latest"
inlineScript: |
Get-AzWebApp
If you want to pass subscription ID, tenant ID, client ID, and client secret as individual parameters instead of bundling them in a single JSON object to address the security concerns, below snippet can help with the same.
- uses: azure/login@v3
with:
creds: '{"clientId":"${{ secrets.AZURE_CLIENT_ID }}","clientSecret":"${{ secrets.AZURE_CLIENT_SECRET }}","subscriptionId":"${{ secrets.AZURE_SUBSCRIPTION_ID }}","tenantId":"${{ secrets.AZURE_TENANT_ID }}"}'
[!NOTE]
"Login With System-assigned Managed Identity" is only supported on GitHub self-hosted runners and the self-hosted runners need to be hosted by Azure virtual machines.
Before you login with system-assigned managed identity, you need to create an Azure virtual machine to host the GitHub self-hosted runner.
After it, create GitHub Action secrets for following values: (Refer to Using secrets in GitHub Actions.)
Now you can try the workflow to login with system-assigned managed identity.
# File: .github/workflows/workflow.yml
name: Run Azure Login with System-assigned Managed Identity
on: [push]
jobs:
build-and-deploy:
runs-on: self-hosted
steps:
- name: Azure login
uses: azure/login@v3
with:
auth-type: IDENTITY
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
enable-AzPSSession: true
# Azure CLI Action only supports linux self-hosted runners for now.
# If you want to execute the Azure CLI script on a windows self-hosted runner, you can execute it directly in `run`.
- name: Azure CLI script
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: |
az account show
- name: Azure PowerShell script
uses: azure/powershell@v3
with:
azPSVersion: "latest"
inlineScript: |
Get-AzContext
Get-AzResourceGroup
[!NOTE]
"Login With User-assigned Managed Identity" is only supported on GitHub self-hosted runners and the self-hosted runners need to be hosted by Azure virtual machines.
Before you login with User-assigned managed identity, you need to create an Azure virtual machine to host the GitHub self-hosted runner.
After it, create GitHub Action secrets for following values: (Refer to Using secrets in GitHub Actions.)
Now you can try the workflow to login with user-assigned managed identity.
# File: .github/workflows/workflow.yml
name: Run Azure Login with User-assigned Managed Identity
on: [push]
jobs:
build-and-deploy:
runs-on: self-hosted
steps:
- name: Azure login
uses: azure/login@v3
with:
auth-type: IDENTITY
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
enable-AzPSSession: true
# Azure CLI Action only supports linux self-hosted runners for now.
# If you want to execute the Azure CLI script on a windows self-hosted runner, you can execute it directly in `run`.
- name: Azure CLI script
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: |
az account show
- name: Azure PowerShell script
uses: azure/powershell@v3
with:
azPSVersion: "latest"
inlineScript: |
Get-AzContext
# File: .github/workflows/workflow.yml
on: [push]
name: Login to Azure US Government cloud
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: azure/login@v3
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
environment: 'AzureUSGovernment'
enable-AzPSSession: true
[!NOTE] Azure CLI versions newer than 2.66.x no longer support Azure Stack Hub. To use
environment: 'AzureStack', pin Azure CLI to 2.66.x (LTS), for example via the Azure CLI action withazcliversion: 2.66.0. See the Azure CLI notice for Azure Stack Hub customers.
# File: .github/workflows/workflow.yml
on: [push]
name: Login to Azure Stack Hub cloud
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: azure/login@v3
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
environment: 'AzureStack'
enable-AzPSSession: true
Refer to the Azure Stack Hub Login Action Tutorial for more detailed instructions.
Capability has been added to support access to tenants without subscriptions for both OIDC and non-OIDC. This can be useful to run tenant level commands, such as az ad. The action accepts an optional parameter allow-no-subscriptions which is false by default.
# File: .github/workflows/workflow.yml
on: [push]
name: Run Azure Login without subscription
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Azure Login
uses: azure/login@v3
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
allow-no-subscriptions: true
enable-AzPSSession: true
- name: Azure CLI script
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: |
az account show
- name: Run Azure PowerShell
uses: azure/powershell@v3
with:
azPSVersion: "latest"
inlineScript: |
Get-AzContext
In Azure Login Action, "cleanup" means cleaning up the login context. For security reasons, we recommend users run cleanup every time. But in some scenarios, users need flexible control over cleanup.
Referring to runs for JavaScript actions, there are 3 steps in an action: pre:, main: and post:. Azure Login Action only implement 2 steps: main: and post:.
There are 2 "cleanup" steps in Azure Login Action:
main:
AZURE_LOGIN_PRE_CLEANUP to true.post:
AZURE_LOGIN_POST_CLEANUP to false.Azure Login Action use env variables to enable or disable cleanup steps. In GitHub Actions, there are three valid scopes for env variables.
We set jobs.<job_id>.steps[*].env for example. Users can set env or jobs.<job_id>.env for a wider scope.
# File: .github/workflows/workflow.yml
on: [push]
name: Cleanup examples for Multiple Azure Login
jobs:
deploy:
runs-on: ubuntu-latest
steps:
# enable cleanup for the 1st Azure Login
- name: Azure Login
uses: azure/login@v3
env:
AZURE_LOGIN_PRE_CLEANUP: true
AZURE_LOGIN_POST_CLEANUP: true
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
enable-AzPSSession: true
# run some actions
# disable cleanup for all other Azure Login
- name: Azure Login 2
uses: azure/login@v3
env:
AZURE_LOGIN_PRE_CLEANUP: false
AZURE_LOGIN_POST_CLEANUP: false
with:
client-id: ${{ secrets.AZURE_CLIENT_ID_2 }}
tenant-id: ${{ secrets.AZURE_TENANT_ID_2 }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID_2 }}
enable-AzPSSession: true
# run other actions
# disable cleanup for all other Azure Login
- name: Azure Login 3
uses: azure/login@v3
env:
AZURE_LOGIN_PRE_CLEANUP: false
AZURE_LOGIN_POST_CLEANUP: false
with:
client-id: ${{ secrets.AZURE_CLIENT_ID_3 }}
tenant-id: ${{ secrets.AZURE_TENANT_ID_3 }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID_3 }}
enable-AzPSSession: true
# run other actions
# File: .github/workflows/workflow.yml
on: [push]
name: Disable cleanup for GitHub Hosted Runners
jobs:
deploy:
runs-on: [ubuntu-latest, self-hosted]
steps:
- name: Azure Login
uses: azure/login@v3
env:
AZURE_LOGIN_PRE_CLEANUP: ${{ startsWith(runner.name, 'GitHub Actions') }}
AZURE_LOGIN_POST_CLEANUP: ${{ startsWith(runner.name, 'GitHub Actions') }}
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
enable-AzPSSession: true
# run some actions
AADSTS700213 / AADSTS7002138 (no matching federated identity record)When logging in with OIDC, the login may fail with an error similar to:
Error: AADSTS700213: No matching federated identity record found for presented assertion subject 'repo:<org>/<repo>:environment:production'.
or:
Error: AADSTS7002138: No matching federated identity record found for presented assertion subject 'repo:<org>/<repo>:ref:refs/heads/main'. The subject matches with case-insensitive comparison, but not with case-sensitive comparison.
This means Microsoft Entra ID could not find a federated identity credential whose Subject exactly matches the subject in the OIDC token that GitHub presented. The token's subject is shown in the run log under Federated token details as subject claim. Two common causes:
repo:My-Org/My-Repo), the federated credential Subject must use the exact same casing as the subject claim in the run log.repo:<org>@<org-id>/<repo>@<repo-id>:<entity>:<value>. The OIDC token GitHub sends does not include those numeric IDs (its subject is repo:<org>/<repo>:<entity>:<value>), so it will never match. Create or edit the federated credential without the owner/repository IDs so the Subject matches the token exactly.In both cases, set the federated credential Subject to exactly match the subject claim shown in your run's Federated token details. See Configure a federated identity credential for details.
[!WARNING] When using self hosted runners it is possible to have multiple runners on a single VM. Currently if your runners share a single user on the VM each runner will share the same credentials. That means in detail that each runner is able to change the permissions of another run. As a workaround we propose to use one single VM user per runner. If you start the runner as a service, do not forget to add the optional user argument
Internally in this action, we use azure CLI and execute az login with the credentials provided through secrets. In order to validate the new azure CLI releases for this action, canary test workflow is written which will execute the action on azure CLI's edge build which will fail incase of any breaking change is being introduced in the new upcoming release. The test results can be posted on a slack or teams channel using the corresponding integrations. Incase of a failure, the concern will be raised to azure-cli for taking a necessary action and also the latest CLI installation will be postponed in Runner VMs as well for hosted runner to prevent the workflows failing due to the new CLI changes.
GitHub Actions gives you the flexibility to build an automated software development lifecycle workflow.
With GitHub Actions for Azure, you can create workflows that you can set up in your repository to build, test, package, release and deploy to Azure.
Refer to the Azure CLI GitHub Action to run your Azure CLI scripts.
Refer to the Azure PowerShell GitHub Action to run your Azure PowerShell scripts.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
(top 30 of 42)
TypeScript
99.4%
With the Azure Login Action, you can login to Azure and run Azure CLI and Azure PowerShell scripts.
Azure Login Action supports different ways of authentication with Azure.
We recommend using OIDC based authentication for increased security.
[!WARNING] By default, the output of Azure CLI commands is printed to the stdout stream. Without redirecting the stdout stream, contents in it will be stored in the build log of the action. Configure Azure CLI to not show output in the console screen or print in the log by setting the environment variable
AZURE_CORE_OUTPUTtonone. If you need the output of a specific command, override the default setting using the argument--outputwith your format of choice. For more information on output options with the Azure CLI, see Format output.
[!WARNING] Avoid using managed identity login on self-hosted runners in public repositories. Managed identities enable secure authentication with Azure resources and obtain Microsoft Entra ID tokens without the need for explicit credential management. Any user can open pull requests against your repository and access your self-hosted runners without credentials. See more details in self-hosted runner security.
[!WARNING] Only pass values from
${{ secrets.* }}intoclient-id,tenant-id,subscription-id, andcreds. Do not pipe values from${{ github.event.* }}(pull request titles, issue comments,workflow_dispatchinputs, branch names, etc.) into these inputs. Untrusted values in these fields can allow attackers to influence the Azure identity the action logs in as.
[!WARNING] Only set
enable-AzPSSession: trueif your workflow runs Azure PowerShell (Az.*) cmdlets. If your workflow only uses the Azure CLI (az ...), leaveenable-AzPSSessionunset (the default isfalse). Enabling it launches an additional PowerShell login step that is unnecessary for CLI-only workflows.
Azure Login follows a major-version support model.
| Version | Status |
|---|---|
| v3 | Supported |
| v2 | Maintenance mode (security fixes only) |
| v1 | End of Life (EOL) |
New features are released only to supported versions. Security fixes are released to supported versions and versions in maintenance mode.
Customers are strongly encouraged to use the latest v3 release.
GitHub Actions users can reference Azure Login using several forms.
uses: azure/login@v3
Receives compatible updates, including security fixes, released to the referenced major version.
uses: azure/login@v2.4.0
Remains pinned to that specific release and does not automatically receive future fixes or updates.
uses: azure/login@master
Receives updates from the referenced branch. For stable workflows, use a supported major-version tag or pin to a full-length commit SHA.
uses: azure/login@<full-length-commit-sha>
Remains pinned to that commit and does not automatically receive future fixes or updates.
Security fixes are released to supported versions and versions in maintenance mode. Customers using exact version tags or commit SHA references must explicitly upgrade to a patched release to receive security fixes.
# Automatically receives future v3 security updates
uses: azure/login@v3
# Does not automatically receive future updates
uses: azure/login@v2.4.0
Customers using v1 should migrate to v3. End-of-life releases no longer receive updates or security fixes.
| Parameter Name | Required? | Type | Default Value | Description |
|---|---|---|---|---|
| client-id | false | UUID | the client id of a service principal or a user-assigned managed identity | |
| subscription-id | false | UUID | the login subscription id | |
| tenant-id | false | UUID | the login tenant id | |
| creds | false | string | a json string for login with an Azure service principal | |
| enable-AzPSSession | false | boolean | false | if Azure PowerShell login is enabled |
| environment | false | string | azurecloud | the Azure Cloud environment. For cloud environments other than the public cloud, the audience will also need to be updated. |
| allow-no-subscriptions | false | boolean | false | if login without subscription is allowed |
| audience | false | string | api://AzureADTokenExchange | the audience to get the JWT ID token from GitHub OIDC provider |
| auth-type | false | string | SERVICE_PRINCIPAL | the auth type |
client-idThe input parameter client-id specifies the login client id. It could be the client id of a service principal or a user-assigned managed identity.
It's used in login with OpenID Connect (OIDC) and user-assigned managed identity.
It's better to create a GitHub Action secret for this parameter when using it. Refer to Using secrets in GitHub Actions.
Refer to Login With OpenID Connect (OIDC) and Login With User-assigned Managed Identity for its usage.
[!NOTE] The action registers the
client-idvalue as a secret (viacore.setSecret) so it is masked in workflow logs. Some enterprises treat the client ID as sensitive, and masking also prevents it from being printed accidentally, which matters in public repositories.tenant-idandsubscription-idare not masked.
subscription-idThe input parameter subscription-id specifies the login subscription id.
It's used in login with OpenID Connect (OIDC) and managed identity.
It's better to create a GitHub Action secret for this parameter when using it. Refer to Using secrets in GitHub Actions.
Refer to Login With OpenID Connect (OIDC), Login With System-assigned Managed Identity and Login With User-assigned Managed Identity for its usage.
tenant-idThe input parameter tenant-id specifies the login tenant id.
It's used in login with OpenID Connect (OIDC) and managed identity.
It's better to create a GitHub Action secret for this parameter when using it. Refer to Using secrets in GitHub Actions.
Refer to Login With OpenID Connect (OIDC), Login With System-assigned Managed Identity and Login With User-assigned Managed Identity for its usage.
creds[!NOTE]
If one of
client-idandsubscription-idandtenant-idis set,credswill be ignored.
The value of input parameter creds is a string in json format, including the following values:
{
"clientSecret": "******",
"subscriptionId": "******",
"tenantId": "******",
"clientId": "******"
}
It's used in login with an Azure service principal.
It's better to create a GitHub Action secret for this parameter when using it. Refer to Using secrets in GitHub Actions.
Refer to Login With a Service Principal Secret for its usage.
enable-AzPSSessionBy default, Azure Login Action only logs in with the Azure CLI. To log in with the Azure PowerShell module, set enable-AzPSSession to true.
Refer to Login With OpenID Connect (OIDC) for its usage.
environmentBy default, Azure Login Action connects to the Azure Public Cloud (AzureCloud).
To login to one of the Azure Government clouds or Azure Stack, set environment to one of the supported values AzureUSGovernment or AzureChinaCloud or AzureGermanCloud or AzureStack.
The default audience for each of these clouds is different and will also need to be set if using anything other than the public environment.
Refer to Login to Azure US Government cloud for its usage.
allow-no-subscriptionsBy default, Azure Login Action requires a subscription-id. To login to Azure tenants without any subscriptions, set allow-no-subscriptions to true.
Refer to Login without subscription for its usage.
audienceAzure Login Action gets the JWT ID token from GitHub OIDC provider when login with OIDC. The default audience is api://AzureADTokenExchange. Users can specify a custom audience.
auth-typeThe input parameter auth-type specifies the type of authentication. The default value is SERVICE_PRINCIPAL. Users can specify it as IDENTITY for login with Managed Identity.
Refer to Login With System-assigned Managed Identity and Login With User-assigned Managed Identity for its usage.
[!NOTE]
- Ensure the CLI version is 2.30 or above to support login with OIDC.
- By default, Azure access tokens issued during OIDC based login could have limited validity. Azure access token issued by Service Principal is expected to have an expiration of 1 hour by default. And with Managed Identities, it would be 24 hours. This expiration time is further configurable in Azure. Refer to access-token lifetime for more details.
Before you use Azure Login Action with OIDC, you need to configure a federated identity credential on a service principal or a managed identity.
After it, create GitHub Action secrets for following values: (Refer to Using secrets in GitHub Actions.)
Now you can try the workflow to login with OIDC.
[!NOTE]
In GitHub workflow, you should set
permissions:withid-token: writeat workflow level or job level based on whether the OIDC token is allowed be generated for all Jobs or a specific Job.
# File: .github/workflows/workflow.yml
name: Run Azure Login with OIDC
on: [push]
permissions:
id-token: write
contents: read
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Azure login
uses: azure/login@v3
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Azure CLI script
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: |
az account show
# File: .github/workflows/workflow.yml
name: Run Azure Login with OIDC
on: [push]
permissions:
id-token: write
contents: read
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Azure login
uses: azure/login@v3
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
enable-AzPSSession: true
- name: Azure CLI script
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: |
az account show
- name: Azure PowerShell script
uses: azure/powershell@v3
with:
azPSVersion: "latest"
inlineScript: |
Get-AzContext
Before you login a service principal secret, you need to prepare a service principal with a secret.
After it, create a GitHub Action secret AZURE_CREDENTIALS with the value like below: (Refer to Using secrets in GitHub Actions.)
{
"clientSecret": "******",
"subscriptionId": "******",
"tenantId": "******",
"clientId": "******"
}
Now you can try the workflow to login with a service principal secret.
# File: .github/workflows/workflow.yml
on: [push]
name: Run Azure Login With a Service Principal Secret
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: azure/login@v3
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Azure CLI script
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: |
az account show
# File: .github/workflows/workflow.yml
on: [push]
name: Run Azure Login With a Service Principal Secret
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: azure/login@v3
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true
- name: Azure CLI script
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: |
az account show
- name: Azure PowerShell script
uses: azure/powershell@v3
with:
azPSVersion: "latest"
inlineScript: |
Get-AzWebApp
If you want to pass subscription ID, tenant ID, client ID, and client secret as individual parameters instead of bundling them in a single JSON object to address the security concerns, below snippet can help with the same.
- uses: azure/login@v3
with:
creds: '{"clientId":"${{ secrets.AZURE_CLIENT_ID }}","clientSecret":"${{ secrets.AZURE_CLIENT_SECRET }}","subscriptionId":"${{ secrets.AZURE_SUBSCRIPTION_ID }}","tenantId":"${{ secrets.AZURE_TENANT_ID }}"}'
[!NOTE]
"Login With System-assigned Managed Identity" is only supported on GitHub self-hosted runners and the self-hosted runners need to be hosted by Azure virtual machines.
Before you login with system-assigned managed identity, you need to create an Azure virtual machine to host the GitHub self-hosted runner.
After it, create GitHub Action secrets for following values: (Refer to Using secrets in GitHub Actions.)
Now you can try the workflow to login with system-assigned managed identity.
# File: .github/workflows/workflow.yml
name: Run Azure Login with System-assigned Managed Identity
on: [push]
jobs:
build-and-deploy:
runs-on: self-hosted
steps:
- name: Azure login
uses: azure/login@v3
with:
auth-type: IDENTITY
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
enable-AzPSSession: true
# Azure CLI Action only supports linux self-hosted runners for now.
# If you want to execute the Azure CLI script on a windows self-hosted runner, you can execute it directly in `run`.
- name: Azure CLI script
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: |
az account show
- name: Azure PowerShell script
uses: azure/powershell@v3
with:
azPSVersion: "latest"
inlineScript: |
Get-AzContext
Get-AzResourceGroup
[!NOTE]
"Login With User-assigned Managed Identity" is only supported on GitHub self-hosted runners and the self-hosted runners need to be hosted by Azure virtual machines.
Before you login with User-assigned managed identity, you need to create an Azure virtual machine to host the GitHub self-hosted runner.
After it, create GitHub Action secrets for following values: (Refer to Using secrets in GitHub Actions.)
Now you can try the workflow to login with user-assigned managed identity.
# File: .github/workflows/workflow.yml
name: Run Azure Login with User-assigned Managed Identity
on: [push]
jobs:
build-and-deploy:
runs-on: self-hosted
steps:
- name: Azure login
uses: azure/login@v3
with:
auth-type: IDENTITY
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
enable-AzPSSession: true
# Azure CLI Action only supports linux self-hosted runners for now.
# If you want to execute the Azure CLI script on a windows self-hosted runner, you can execute it directly in `run`.
- name: Azure CLI script
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: |
az account show
- name: Azure PowerShell script
uses: azure/powershell@v3
with:
azPSVersion: "latest"
inlineScript: |
Get-AzContext
# File: .github/workflows/workflow.yml
on: [push]
name: Login to Azure US Government cloud
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: azure/login@v3
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
environment: 'AzureUSGovernment'
enable-AzPSSession: true
[!NOTE] Azure CLI versions newer than 2.66.x no longer support Azure Stack Hub. To use
environment: 'AzureStack', pin Azure CLI to 2.66.x (LTS), for example via the Azure CLI action withazcliversion: 2.66.0. See the Azure CLI notice for Azure Stack Hub customers.
# File: .github/workflows/workflow.yml
on: [push]
name: Login to Azure Stack Hub cloud
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: azure/login@v3
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
environment: 'AzureStack'
enable-AzPSSession: true
Refer to the Azure Stack Hub Login Action Tutorial for more detailed instructions.
Capability has been added to support access to tenants without subscriptions for both OIDC and non-OIDC. This can be useful to run tenant level commands, such as az ad. The action accepts an optional parameter allow-no-subscriptions which is false by default.
# File: .github/workflows/workflow.yml
on: [push]
name: Run Azure Login without subscription
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Azure Login
uses: azure/login@v3
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
allow-no-subscriptions: true
enable-AzPSSession: true
- name: Azure CLI script
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: |
az account show
- name: Run Azure PowerShell
uses: azure/powershell@v3
with:
azPSVersion: "latest"
inlineScript: |
Get-AzContext
In Azure Login Action, "cleanup" means cleaning up the login context. For security reasons, we recommend users run cleanup every time. But in some scenarios, users need flexible control over cleanup.
Referring to runs for JavaScript actions, there are 3 steps in an action: pre:, main: and post:. Azure Login Action only implement 2 steps: main: and post:.
There are 2 "cleanup" steps in Azure Login Action:
main:
AZURE_LOGIN_PRE_CLEANUP to true.post:
AZURE_LOGIN_POST_CLEANUP to false.Azure Login Action use env variables to enable or disable cleanup steps. In GitHub Actions, there are three valid scopes for env variables.
We set jobs.<job_id>.steps[*].env for example. Users can set env or jobs.<job_id>.env for a wider scope.
# File: .github/workflows/workflow.yml
on: [push]
name: Cleanup examples for Multiple Azure Login
jobs:
deploy:
runs-on: ubuntu-latest
steps:
# enable cleanup for the 1st Azure Login
- name: Azure Login
uses: azure/login@v3
env:
AZURE_LOGIN_PRE_CLEANUP: true
AZURE_LOGIN_POST_CLEANUP: true
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
enable-AzPSSession: true
# run some actions
# disable cleanup for all other Azure Login
- name: Azure Login 2
uses: azure/login@v3
env:
AZURE_LOGIN_PRE_CLEANUP: false
AZURE_LOGIN_POST_CLEANUP: false
with:
client-id: ${{ secrets.AZURE_CLIENT_ID_2 }}
tenant-id: ${{ secrets.AZURE_TENANT_ID_2 }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID_2 }}
enable-AzPSSession: true
# run other actions
# disable cleanup for all other Azure Login
- name: Azure Login 3
uses: azure/login@v3
env:
AZURE_LOGIN_PRE_CLEANUP: false
AZURE_LOGIN_POST_CLEANUP: false
with:
client-id: ${{ secrets.AZURE_CLIENT_ID_3 }}
tenant-id: ${{ secrets.AZURE_TENANT_ID_3 }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID_3 }}
enable-AzPSSession: true
# run other actions
# File: .github/workflows/workflow.yml
on: [push]
name: Disable cleanup for GitHub Hosted Runners
jobs:
deploy:
runs-on: [ubuntu-latest, self-hosted]
steps:
- name: Azure Login
uses: azure/login@v3
env:
AZURE_LOGIN_PRE_CLEANUP: ${{ startsWith(runner.name, 'GitHub Actions') }}
AZURE_LOGIN_POST_CLEANUP: ${{ startsWith(runner.name, 'GitHub Actions') }}
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
enable-AzPSSession: true
# run some actions
AADSTS700213 / AADSTS7002138 (no matching federated identity record)When logging in with OIDC, the login may fail with an error similar to:
Error: AADSTS700213: No matching federated identity record found for presented assertion subject 'repo:<org>/<repo>:environment:production'.
or:
Error: AADSTS7002138: No matching federated identity record found for presented assertion subject 'repo:<org>/<repo>:ref:refs/heads/main'. The subject matches with case-insensitive comparison, but not with case-sensitive comparison.
This means Microsoft Entra ID could not find a federated identity credential whose Subject exactly matches the subject in the OIDC token that GitHub presented. The token's subject is shown in the run log under Federated token details as subject claim. Two common causes:
repo:My-Org/My-Repo), the federated credential Subject must use the exact same casing as the subject claim in the run log.repo:<org>@<org-id>/<repo>@<repo-id>:<entity>:<value>. The OIDC token GitHub sends does not include those numeric IDs (its subject is repo:<org>/<repo>:<entity>:<value>), so it will never match. Create or edit the federated credential without the owner/repository IDs so the Subject matches the token exactly.In both cases, set the federated credential Subject to exactly match the subject claim shown in your run's Federated token details. See Configure a federated identity credential for details.
[!WARNING] When using self hosted runners it is possible to have multiple runners on a single VM. Currently if your runners share a single user on the VM each runner will share the same credentials. That means in detail that each runner is able to change the permissions of another run. As a workaround we propose to use one single VM user per runner. If you start the runner as a service, do not forget to add the optional user argument
Internally in this action, we use azure CLI and execute az login with the credentials provided through secrets. In order to validate the new azure CLI releases for this action, canary test workflow is written which will execute the action on azure CLI's edge build which will fail incase of any breaking change is being introduced in the new upcoming release. The test results can be posted on a slack or teams channel using the corresponding integrations. Incase of a failure, the concern will be raised to azure-cli for taking a necessary action and also the latest CLI installation will be postponed in Runner VMs as well for hosted runner to prevent the workflows failing due to the new CLI changes.
GitHub Actions gives you the flexibility to build an automated software development lifecycle workflow.
With GitHub Actions for Azure, you can create workflows that you can set up in your repository to build, test, package, release and deploy to Azure.
Refer to the Azure CLI GitHub Action to run your Azure CLI scripts.
Refer to the Azure PowerShell GitHub Action to run your Azure PowerShell scripts.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
(top 30 of 42)
TypeScript
99.4%