Skip to content

Commit f8fd3e2

Browse files
Merge pull request #294678 from juliakm/users/jukullam/emphasize-oidc-feb14
Update with latest OpenID Connect security guidance for GitHub Actions
2 parents 75e77f2 + a4845e9 commit f8fd3e2

File tree

1 file changed

+25
-65
lines changed

1 file changed

+25
-65
lines changed

articles/app-service/deploy-container-github-action.md

Lines changed: 25 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Custom container CI/CD from GitHub Actions
33
description: Learn how to use GitHub Actions to deploy your custom Linux container to App Service from a CI/CD pipeline.
44
ms.topic: article
5-
ms.date: 12/15/2021
5+
ms.date: 02/14/2025
66
ms.reviewer: ushan
77
ms.custom: github-actions-azure, devx-track-azurecli, linux-related-content
88
ms.devlang: azurecli
@@ -34,7 +34,7 @@ For an Azure App Service container workflow, the file has three sections:
3434

3535
## Generate deployment credentials
3636

37-
The recommended way to authenticate with Azure App Services for GitHub Actions is with a publish profile. You can also authenticate with a service principal or Open ID Connect but the process requires more steps.
37+
The recommended way to authenticate with Azure App Services for GitHub Actions is with OpenID Connect. You can also authenticate with a service principal or a Publish Profile.
3838

3939
Save your publish profile credential or service principal as a [GitHub secret](https://docs.github.com/en/actions/reference/encrypted-secrets) to authenticate with Azure. You'll access the secret within your workflow.
4040

@@ -53,74 +53,31 @@ A publish profile is an app-level credential. Set up your publish profile as a G
5353

5454
# [Service principal](#tab/service-principal)
5555

56-
You can create a [service principal](../active-directory/develop/app-objects-and-service-principals.md#service-principal-object) with the [az ad sp create-for-rbac](/cli/azure/ad/sp#az-ad-sp-create-for-rbac) command in the [Azure CLI](/cli/azure/). Run this command with [Azure Cloud Shell](https://shell.azure.com/) in the Azure portal or by selecting the **Try it** button.
56+
* Create a Microsoft Entra application with a service principal by [Azure portal](/entra/identity-platform/howto-create-service-principal-portal#register-an-application-with-microsoft-entra-id-and-create-a-service-principal), [Azure CLI](/cli/azure/azure-cli-sp-tutorial-1#create-a-service-principal), or [Azure PowerShell](/powershell/azure/create-azure-service-principal-azureps#create-a-service-principal).
57+
* Create a client secret for your service principal by [Azure portal](/entra/identity-platform/howto-create-service-principal-portal#option-3-create-a-new-client-secret), [Azure CLI](/cli/azure/azure-cli-sp-tutorial-2?branch=main#create-a-service-principal-containing-a-password), or [Azure PowerShell](/powershell/azure/create-azure-service-principal-azureps?#password-based-authentication).
58+
* Copy the values for **Client ID**, **Client Secret**, **Subscription ID**, and **Directory (tenant) ID** to use later in your GitHub Actions workflow.
59+
* Assign an appropriate role to your service principal by [Azure portal](/entra/identity-platform/howto-create-service-principal-portal#assign-a-role-to-the-application), [Azure CLI](/cli/azure/azure-cli-sp-tutorial-5#create-or-remove-a-role-assignment), or [Azure PowerShell](/powershell/azure/create-azure-service-principal-azureps#manage-service-principal-roles).
5760

58-
```azurecli-interactive
59-
az ad sp create-for-rbac --name "myApp" --role contributor \
60-
--scopes /subscriptions/<subscription-id>/resourceGroups/<group-name>/providers/Microsoft.Web/sites/<app-name> \
61-
--json-auth
62-
```
63-
64-
In the example, replace the placeholders with your subscription ID, resource group name, and app name. The output is a JSON object with the role assignment credentials that provide access to your App Service app. Copy this JSON object for later.
65-
66-
```output
67-
{
68-
"clientId": "<GUID>",
69-
"clientSecret": "<GUID>",
70-
"subscriptionId": "<GUID>",
71-
"tenantId": "<GUID>",
72-
(...)
73-
}
74-
```
75-
76-
> [!IMPORTANT]
77-
> It is always a good practice to grant minimum access. The scope in the previous example is limited to the specific App Service app and not the entire resource group.
7861

7962
# [OpenID Connect](#tab/openid)
8063

8164
OpenID Connect is an authentication method that uses short-lived tokens. Setting up [OpenID Connect with GitHub Actions](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect) is more complex process that offers hardened security.
8265

83-
1. If you don't have an existing application, register a [new Active Directory application and service principal that can access resources](../active-directory/develop/howto-create-service-principal-portal.md). Create the Active Directory application.
66+
To use [Azure Login action](https://github.com/marketplace/actions/azure-login) with OIDC, you need to configure a federated identity credential on a Microsoft Entra application or a user-assigned managed identity.
8467

85-
```azurecli-interactive
86-
az ad app create --display-name myApp
87-
```
68+
**Option 1: Microsoft Entra application**
8869

89-
This command will output JSON with an `appId` that is your `client-id`. Save the value to use as the `AZURE_CLIENT_ID` GitHub secret later.
90-
91-
You'll use the `objectId` value when creating federated credentials with Graph API and reference it as the `APPLICATION-OBJECT-ID`.
92-
93-
1. Create a service principal. Replace the `$appID` with the appId from your JSON output.
94-
95-
This command generates JSON output with a different `objectId` and will be used in the next step. The new `objectId` is the `assignee-object-id`.
96-
97-
Copy the `appOwnerTenantId` to use as a GitHub secret for `AZURE_TENANT_ID` later.
70+
* Create a Microsoft Entra application with a service principal by [Azure portal](/entra/identity-platform/howto-create-service-principal-portal#register-an-application-with-microsoft-entra-id-and-create-a-service-principal), [Azure CLI](/cli/azure/azure-cli-sp-tutorial-1#create-a-service-principal), or [Azure PowerShell](/powershell/azure/create-azure-service-principal-azureps#create-a-service-principal).
71+
* Copy the values for **Client ID**, **Subscription ID**, and **Directory (tenant) ID** to use later in your GitHub Actions workflow.
72+
* Assign an appropriate role to your service principal by [Azure portal](/entra/identity-platform/howto-create-service-principal-portal#assign-a-role-to-the-application), [Azure CLI](/cli/azure/azure-cli-sp-tutorial-5#create-or-remove-a-role-assignment), or [Azure PowerShell](/powershell/azure/create-azure-service-principal-azureps#manage-service-principal-roles).
73+
* [Configure a federated identity credential on a Microsoft Entra application](/entra/workload-id/workload-identity-federation-create-trust) to trust tokens issued by GitHub Actions to your GitHub repository.
9874

99-
```azurecli-interactive
100-
az ad sp create --id $appId
101-
```
75+
**Option 2: User-assigned managed identity**
10276

103-
1. Create a new role assignment by subscription and object. By default, the role assignment will be tied to your default subscription. Replace `$subscriptionId` with your subscription ID, `$resourceGroupName` with your resource group name, and `$assigneeObjectId` with the generated `assignee-object-id`. Learn [how to manage Azure subscriptions with the Azure CLI](/cli/azure/manage-azure-subscriptions-azure-cli).
104-
105-
```azurecli-interactive
106-
az role assignment create --role contributor --subscription $subscriptionId --assignee-object-id $assigneeObjectId --assignee-principal-type ServicePrincipal --scopes /subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Web/sites/
107-
```
108-
109-
1. Run the following command to [create a new federated identity credential](/graph/api/application-post-federatedidentitycredentials?view=graph-rest-beta&preserve-view=true) for your active directory application.
110-
111-
* Replace `APPLICATION-OBJECT-ID` with the **objectId (generated while creating app)** for your Active Directory application.
112-
* Set a value for `CREDENTIAL-NAME` to reference later.
113-
* Set the `subject`. The value of this is defined by GitHub depending on your workflow:
114-
* Jobs in your GitHub Actions environment: `repo:< Organization/Repository >:environment:< Name >`
115-
* For Jobs not tied to an environment, include the ref path for branch/tag based on the ref path used for triggering the workflow: `repo:< Organization/Repository >:ref:< ref path>`. For example, `repo:n-username/ node_express:ref:refs/heads/my-branch` or `repo:n-username/ node_express:ref:refs/tags/my-tag`.
116-
* For workflows triggered by a pull request event: `repo:< Organization/Repository >:pull_request`.
117-
118-
```azurecli
119-
az rest --method POST --uri 'https://graph.microsoft.com/beta/applications/<APPLICATION-OBJECT-ID>/federatedIdentityCredentials' --body '{"name":"<CREDENTIAL-NAME>","issuer":"https://token.actions.githubusercontent.com","subject":"repo:organization/repository:ref:refs/heads/main","description":"Testing","audiences":["api://AzureADTokenExchange"]}'
120-
```
121-
122-
To learn how to create a Create an active directory application, service principal, and federated credentials in Azure portal, see [Connect GitHub and Azure](/azure/developer/github/connect-from-azure#use-the-azure-login-action-with-openid-connect).
123-
77+
* [Create a user-assigned managed identity](/entra/identity/managed-identities-azure-resources/how-manage-user-assigned-managed-identities#create-a-user-assigned-managed-identity).
78+
* Copy the values for **Client ID**, **Subscription ID**, and **Directory (tenant) ID** to use later in your GitHub Actions workflow.
79+
* [Assign an appropriate role to your user-assigned managed identity](/entra/identity/managed-identities-azure-resources/how-manage-user-assigned-managed-identities#manage-access-to-user-assigned-managed-identities).
80+
* [Configure a federated identity credential on a user-assigned managed identity](/entra/workload-id/workload-identity-federation-create-trust-user-assigned-managed-identity) to trust tokens issued by GitHub Actions to your GitHub repository.
12481

12582
---
12683
## Configure the GitHub secret for authentication
@@ -148,7 +105,7 @@ To use [user-level credentials](#generate-deployment-credentials), paste the ent
148105
When you configure the workflow file later, you use the secret for the input `creds` of the Azure Login action. For example:
149106

150107
```yaml
151-
- uses: azure/login@v1
108+
- uses: azure/login@v2
152109
with:
153110
creds: ${{ secrets.AZURE_CREDENTIALS }}
154111
```
@@ -159,6 +116,9 @@ You need to provide your application's **Client ID**, **Tenant ID** and **Subscr
159116

160117
1. Open your GitHub repository and go to **Settings > Security > Secrets and variables > Actions > New repository secret**.
161118

119+
> [!NOTE]
120+
> To enhance workflow security in public repositories, use [environment secrets](https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#environment-secrets) instead of repository secrets. If the environment requires approval, a job cannot access environment secrets until one of the required reviewers approves it.
121+
162122
1. Create secrets for `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, and `AZURE_SUBSCRIPTION_ID`. Use these values from your Active Directory application for your GitHub secrets. You can find these values in the Azure portal by searching for your active directory application.
163123

164124
|GitHub Secret | Active Directory Application |
@@ -354,7 +314,7 @@ jobs:
354314
uses: actions/checkout@main
355315
356316
- name: 'Sign in via Azure CLI'
357-
uses: azure/login@v1
317+
uses: azure/login@v2
358318
with:
359319
creds: ${{ secrets.AZURE_CREDENTIALS }}
360320
@@ -396,7 +356,7 @@ jobs:
396356
uses: actions/checkout@main
397357
398358
- name: 'Sign in via Azure CLI'
399-
uses: azure/login@v1
359+
uses: azure/login@v2
400360
with:
401361
client-id: ${{ secrets.AZURE_CLIENT_ID }}
402362
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
@@ -472,7 +432,7 @@ jobs:
472432
uses: actions/checkout@main
473433
474434
- name: 'Sign in via Azure CLI'
475-
uses: azure/login@v1
435+
uses: azure/login@v2
476436
with:
477437
creds: ${{ secrets.AZURE_CREDENTIALS }}
478438
@@ -514,7 +474,7 @@ jobs:
514474
uses: actions/checkout@main
515475
516476
- name: 'Sign in via Azure CLI'
517-
uses: azure/login@v1
477+
uses: azure/login@v2
518478
with:
519479
client-id: ${{ secrets.AZURE_CLIENT_ID }}
520480
tenant-id: ${{ secrets.AZURE_TENANT_ID }}

0 commit comments

Comments
 (0)