You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-resource-manager/bicep/deploy-github-actions.md
+110-3Lines changed: 110 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ description: In this quickstart, you learn how to deploy Bicep files by using Gi
4
4
author: mumian
5
5
ms.author: jgao
6
6
ms.topic: conceptual
7
-
ms.date: 11/16/2021
7
+
ms.date: 05/19/2022
8
8
ms.custom: github-actions-azure
9
9
---
10
10
@@ -32,7 +32,9 @@ az group create -n exampleRG -l westus
32
32
33
33
## Generate deployment credentials
34
34
35
-
Your GitHub Actions runs under an identity. Use the [az ad sp create-for-rbac](/cli/azure/ad/sp#az-ad-sp-create-for-rbac) command to create a [service principal](../../active-directory/develop/app-objects-and-service-principals.md#service-principal-object) for the identity.
35
+
# [Service principal](#tab/userlevel)
36
+
37
+
Your GitHub Actions run under an identity. Use the [az ad sp create-for-rbac](/cli/azure/ad/sp#az-ad-sp-create-for-rbac) command to create a [service principal](../../active-directory/develop/app-objects-and-service-principals.md#service-principal-object) for the identity.
36
38
37
39
Replace the placeholder `myApp` with the name of your application. Replace `{subscription-id}` with your subscription ID.
38
40
@@ -54,9 +56,57 @@ The output is a JSON object with the role assignment credentials that provide ac
54
56
(...)
55
57
}
56
58
```
59
+
# [Open ID Connect](#tab/openid)
60
+
61
+
62
+
Open ID 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.
63
+
64
+
1. If you do not 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.
65
+
66
+
```azurecli-interactive
67
+
az ad app create --display-name myApp
68
+
```
69
+
70
+
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.
71
+
72
+
You'll use the `objectId` value when creating federated credentials with Graph API and reference it as the `APPLICATION-OBJECT-ID`.
73
+
74
+
1. Create a service principal. Replace the `$appID` with the appId from your JSON output.
75
+
76
+
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`.
77
+
78
+
Copy the `appOwnerTenantId` to use as a GitHub secret for `AZURE_TENANT_ID` later.
79
+
80
+
```azurecli-interactive
81
+
az ad sp create --id $appId
82
+
```
83
+
84
+
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).
85
+
86
+
```azurecli-interactive
87
+
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/
88
+
```
57
89
90
+
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.
91
+
92
+
* Replace `APPLICATION-OBJECT-ID` with the **objectId (generated while creating app)** for your Active Directory application.
93
+
* Set a value for `CREDENTIAL-NAME` to reference later.
94
+
* Set the `subject`. The value of this is defined by GitHub depending on your workflow:
95
+
* Jobs in your GitHub Actions environment: `repo:< Organization/Repository >:environment:< Name >`
96
+
* 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`.
97
+
* For workflows triggered by a pull request event: `repo:< Organization/Repository >:pull_request`.
98
+
99
+
```azurecli
100
+
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"]}'
101
+
```
102
+
103
+
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).
104
+
105
+
---
58
106
## Configure the GitHub secrets
59
107
108
+
# [Service principal](#tab/userlevel)
109
+
60
110
Create secrets for your Azure credentials, resource group, and subscriptions.
61
111
62
112
1. In [GitHub](https://github.com/), navigate to your repository.
@@ -69,6 +119,26 @@ Create secrets for your Azure credentials, resource group, and subscriptions.
69
119
70
120
1. Create another secret named `AZURE_SUBSCRIPTION`. Add your subscription ID to the secret's value field (example: `90fd3f9d-4c61-432d-99ba-1273f236afa2`).
71
121
122
+
# [Open ID Connect](#tab/openid)
123
+
124
+
You need to provide your application's **Client ID**, **Tenant ID**, and **Subscription ID** to the login action. These values can either be provided directly in the workflow or can be stored in GitHub secrets and referenced in your workflow. Saving the values as GitHub secrets is the more secure option.
125
+
126
+
1. Open your GitHub repository and go to **Settings**.
127
+
128
+
1. Select **Settings > Secrets > New secret**.
129
+
130
+
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:
131
+
132
+
|GitHub Secret | Active Directory Application |
133
+
|---------|---------|
134
+
|AZURE_CLIENT_ID | Application (client) ID |
135
+
|AZURE_TENANT_ID | Directory (tenant) ID |
136
+
|AZURE_SUBSCRIPTION_ID | Subscription ID |
137
+
138
+
1. Save each secret by selecting **Add secret**.
139
+
140
+
---
141
+
72
142
## Add a Bicep file
73
143
74
144
Add a Bicep file to your GitHub repository. The following Bicep file creates a storage account:
@@ -91,6 +161,8 @@ To create a workflow, take the following steps:
91
161
1. Rename the workflow file if you prefer a different name other than **main.yml**. For example: **deployBicepFile.yml**.
92
162
1. Replace the content of the yml file with the following code:
93
163
164
+
# [Service principal](#tab/userlevel)
165
+
94
166
```yml
95
167
on: [push]
96
168
name: Azure ARM
@@ -117,7 +189,7 @@ To create a workflow, take the following steps:
117
189
parameters: storagePrefix=mystore
118
190
failOnStdErr: false
119
191
```
120
-
192
+
121
193
Replace `mystore` with your own storage account name prefix.
122
194
123
195
> [!NOTE]
@@ -127,6 +199,41 @@ To create a workflow, take the following steps:
127
199
128
200
- **name**: The name of the workflow.
129
201
- **on**: The name of the GitHub events that triggers the workflow. The workflow is triggered when there's a push event on the main branch.
0 commit comments