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
@@ -24,7 +24,7 @@ This article shows how to set up a workflow in a GitHub repo that performs the f
24
24
25
25
This article shows two ways to set up the workflow:
26
26
27
-
*[Configure GitHub workflow](#configure-github-workflow) - Create a workflow in a GitHub repo using the Deploy to Azure Container Instances action and other actions.
27
+
*[Configure GitHub workflow](#configure-github-workflow) - Create a workflow in a GitHub repo using the Deploy to Azure Container Instances action and other actions.
28
28
*[Use CLI extension](#use-deploy-to-azure-extension) - Use the `az container app up` command in the [Deploy to Azure](https://github.com/Azure/deploy-to-azure-cli-extension) extension in the Azure CLI. This command streamlines creation of the GitHub workflow and deployment steps.
29
29
30
30
> [!IMPORTANT]
@@ -50,8 +50,6 @@ This article shows two ways to set up the workflow:
50
50
51
51
### Create credentials for Azure authentication
52
52
53
-
# [Service principal](#tab/userlevel)
54
-
55
53
In the GitHub workflow, you need to supply Azure credentials to authenticate to the Azure CLI. The following example creates a service principal with the Contributor role scoped to the resource group for your container registry.
56
54
57
55
First, get the resource ID of your resource group. Substitute the name of your group in the following [az group show][az-group-show] command:
@@ -68,7 +66,7 @@ Use [az ad sp create-for-rbac][az-ad-sp-create-for-rbac] to create the service p
68
66
az ad sp create-for-rbac \
69
67
--scope $groupId \
70
68
--role Contributor \
71
-
--json-auth
69
+
--sdk-auth
72
70
```
73
71
74
72
Output is similar to:
@@ -90,68 +88,9 @@ Output is similar to:
90
88
91
89
Save the JSON output because it is used in a later step. Also, take note of the `clientId`, which you need to update the service principal in the next section.
92
90
93
-
# [OpenID Connect](#tab/openid)
94
-
95
-
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.
96
-
97
-
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.
98
-
99
-
```azurecli-interactive
100
-
az ad app create --display-name myApp
101
-
```
102
-
103
-
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.
104
-
105
-
You'll use the `objectId` value when creating federated credentials with Graph API and reference it as the `APPLICATION-OBJECT-ID`.
106
-
107
-
1. Create a service principal. Replace the `$appID` with the appId from your JSON output.
108
-
109
-
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`.
110
-
111
-
Copy the `appOwnerTenantId` to use as a GitHub secret for `AZURE_TENANT_ID` later.
112
-
113
-
```azurecli-interactive
114
-
az ad sp create --id $appId
115
-
```
116
-
117
-
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).
118
-
119
-
```azurecli-interactive
120
-
az role assignment create --role contributor --subscription $subscriptionId --assignee-object-id $assigneeObjectId --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Web/sites/ --assignee-principal-type ServicePrincipal
121
-
```
122
-
123
-
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.
124
-
125
-
* Replace `APPLICATION-OBJECT-ID` with the **objectId (generated while creating app)** for your Active Directory application.
126
-
* Set a value for `CREDENTIAL-NAME` to reference later.
127
-
* Set the `subject`. The value of this is defined by GitHub depending on your workflow:
128
-
* Jobs in your GitHub Actions environment: `repo:< Organization/Repository >:environment:< Name >`
129
-
* 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`.
130
-
* For workflows triggered by a pull request event: `repo:< Organization/Repository >:pull_request`.
131
-
132
-
```azurecli-interactive
133
-
az ad app federated-credential create --id <APPLICATION-OBJECT-ID> --parameters credential.json
134
-
("credential.json" contains the following content)
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).
147
-
148
-
---
149
-
150
91
### Update for registry authentication
151
92
152
-
# [Service principal](#tab/userlevel)
153
-
154
-
Update the Azure service principal credentials to allow push and pull access to your container registry. This step enables the GitHub workflow to use the service principal to [authenticate with your container registry](../container-registry/container-registry-auth-service-principal.md) and to push and pull a Docker image.
93
+
Update the Azure service principal credentials to allow push and pull access to your container registry. This step enables the GitHub workflow to use the service principal to [authenticate with your container registry](../container-registry/container-registry-auth-service-principal.md) and to push and pull a Docker image.
155
94
156
95
Get the resource ID of your container registry. Substitute the name of your registry in the following [az acr show][az-acr-show] command:
157
96
@@ -171,27 +110,8 @@ az role assignment create \
171
110
--role AcrPush
172
111
```
173
112
174
-
# [OpenID Connect](#tab/openid)
175
-
176
-
You need to give your application permission to access the Azure Container Registry and to create an Azure Container Instance.
177
-
178
-
1. In Azure portal, go to [App registrations](https://portal.azure.com/#view/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/~/RegisteredApps).
179
-
1. Search for your OpenID Connect app registration and copy the **Application (client) ID**.
180
-
1. Grant permissions for your app to your resource group. You'll need to set permissions at the resource group level so that you can create Azure Container instances.
1. In the GitHub UI, navigate to your forked repository and select **Security > Secrets and variables > Actions**.
196
116
197
117
1. Select **New repository secret** to add the following secrets:
@@ -204,33 +124,13 @@ You need to give your application permission to access the Azure Container Regis
204
124
|`REGISTRY_PASSWORD`| The `clientSecret` from the JSON output from the service principal creation |
205
125
|`RESOURCE_GROUP`| The name of the resource group you used to scope the service principal |
206
126
207
-
# [OpenID Connect](#tab/openid)
208
-
209
-
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.
210
-
211
-
1. Open your GitHub repository and go to **Settings > Security > Secrets and variables > Actions > New repository secret**.
212
-
213
-
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:
214
-
215
-
|GitHub Secret | Active Directory Application |
216
-
|---------|---------|
217
-
|AZURE_CLIENT_ID | Application (client) ID |
218
-
|AZURE_TENANT_ID | Directory (tenant) ID |
219
-
|AZURE_SUBSCRIPTION_ID | Subscription ID |
220
-
221
-
1. Save each secret by selecting **Add secret**.
222
-
223
-
---
224
-
225
127
### Create workflow file
226
128
227
129
1. In the GitHub UI, select **Actions**.
228
130
1. Select **set up a workflow yourself**.
229
131
1. In **Edit new file**, paste the following YAML contents to overwrite the sample code. Accept the default filename `main.yml`, or provide a filename you choose.
230
132
1. Select **Start commit**, optionally provide short and extended descriptions of your commit, and select **Commit new file**.
See [Viewing workflow run history](https://docs.github.com/en/actions/managing-workflow-runs/viewing-workflow-run-history) for information about viewing the status and results of each step in your workflow. If the workflow doesn't complete, see [Viewing logs to diagnose failures](https://docs.github.com/en/actions/managing-workflow-runs/using-workflow-run-logs#viewing-logs-to-diagnose-failures).
331
181
332
-
When the workflow completes successfully, get information about the container instance named *aci-sampleapp* by running the [az container show][az-container-show] command. Substitute the name of your resource group:
182
+
When the workflow completes successfully, get information about the container instance named *aci-sampleapp* by running the [az container show][az-container-show] command. Substitute the name of your resource group:
333
183
334
184
```azurecli-interactive
335
185
az container show \
@@ -353,7 +203,7 @@ After the instance is provisioned, navigate to the container's FQDN in your brow
353
203
354
204
## Use Deploy to Azure extension
355
205
356
-
Alternatively, use the [Deploy to Azure extension](https://github.com/Azure/deploy-to-azure-cli-extension) in the Azure CLI to configure the workflow. The `az container app up` command in the extension takes input parameters from you to set up a workflow to deploy to Azure Container Instances.
206
+
Alternatively, use the [Deploy to Azure extension](https://github.com/Azure/deploy-to-azure-cli-extension) in the Azure CLI to configure the workflow. The `az container app up` command in the extension takes input parameters from you to set up a workflow to deploy to Azure Container Instances.
357
207
358
208
The workflow created by the Azure CLI is similar to the workflow you can [create manually using GitHub](#configure-github-workflow).
359
209
@@ -394,7 +244,7 @@ az container app up \
394
244
* Service principal credentials for the Azure CLI
395
245
* Credentials to access the Azure container registry
396
246
397
-
* After the command commits the workflow file to your repo, the workflow is triggered.
247
+
* After the command commits the workflow file to your repo, the workflow is triggered.
398
248
399
249
Output is similar to:
400
250
@@ -412,7 +262,7 @@ To view the workflow status and results of each step in the GitHub UI, see [View
412
262
413
263
### Validate workflow
414
264
415
-
The workflow deploys an Azure container instance with the base name of your GitHub repo, in this case, *acr-build-helloworld-node*. When the workflow completes successfully, get information about the container instance named *acr-build-helloworld-node* by running the [az container show][az-container-show] command. Substitute the name of your resource group:
265
+
The workflow deploys an Azure container instance with the base name of your GitHub repo, in this case, *acr-build-helloworld-node*. When the workflow completes successfully, get information about the container instance named *acr-build-helloworld-node* by running the [az container show][az-container-show] command. Substitute the name of your resource group:
0 commit comments