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
1.[Configure the GitHub secret](#2-configure-the-github-secret)
53
53
1.[Add the workflow file to your GitHub repository](#3-add-the-workflow-file-to-your-github-repository)
54
54
55
55
### 1. Generate deployment credentials
56
56
57
-
The recommended way to authenticate with Azure App Services for GitHub Actions is with a user-defined managed identity, and the easiest way for that is by [configuring GitHub Actions deployment directly in the portal](deploy-continuous-deployment.md) instead and selecting **User-assigned managed identity**.
57
+
The recommended way to authenticate with Azure App Services for GitHub Actions is with OpenID Connect. This is an authentication method that uses short-lived tokens. Setting up [OpenID Connect with GitHub Actions](/azure/developer/github/connect-from-azure) is more complex but offers hardened security.
58
58
59
-
> [!NOTE]
60
-
> Authentication using a user-assigned managed identity is currently in preview.
61
-
62
-
Alternatively, you can authenticate with a service principal, OpenID Connect, or a publish profile.
63
-
64
-
# [Publish profile](#tab/applevel)
65
-
66
-
> [!NOTE]
67
-
> Publish profile requires [basic authentication](configure-basic-auth-disable.md) to be enabled.
68
-
69
-
A publish profile is an app-level credential. Set up your publish profile as a GitHub secret.
70
-
71
-
1. Go to your app service in the Azure portal.
72
-
73
-
1. On the **Overview** page, select **Get Publish profile**.
74
-
75
-
1. Save the downloaded file. You'll use the contents of the file to create a GitHub secret.
76
-
77
-
> [!NOTE]
78
-
> As of October 2020, Linux web apps needs the app setting `WEBSITE_WEBDEPLOY_USE_SCM` set to `true`**before downloading the publish profile**. This requirement will be removed in the future.
79
-
80
-
# [Service principal](#tab/userlevel)
81
-
82
-
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.
83
-
84
-
```azurecli-interactive
85
-
az ad sp create-for-rbac --name "myApp" --role contributor \
In the previous 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 similar to the following JSON snippet. Copy this JSON object for later.
91
-
92
-
```output
93
-
{
94
-
"clientId": "<GUID>",
95
-
"clientSecret": "<GUID>",
96
-
"subscriptionId": "<GUID>",
97
-
"tenantId": "<GUID>",
98
-
(...)
99
-
}
100
-
```
101
-
102
-
> [!IMPORTANT]
103
-
> 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.
59
+
Alternatively, you can authenticate with a User-assigned Managed Identity, a service principal, or a publish profile.
104
60
105
61
# [OpenID Connect](#tab/openid)
106
62
107
-
OpenID Connect is an authentication method that uses short-lived tokens. Setting up [OpenID Connect with GitHub Actions](/azure/developer/github/connect-from-azure) is more complex but offers hardened security.
63
+
The below runs you through the steps for creating an active directory application, service principal, and federated credentials using Azure CLI statements. To learn how to 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).
108
64
109
65
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.
110
66
@@ -126,15 +82,15 @@ OpenID Connect is an authentication method that uses short-lived tokens. Setting
126
82
az ad sp create --id $appId
127
83
```
128
84
129
-
1. Create a new role assignment by subscription and object. By default, the role assignment is 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
+
1. Create a new role assignment by subscription and object. By default, the role assignment is tied to your default subscription. Replace `$subscriptionId` with your subscription ID, `$resourceGroupName` with your resource group name, `$webappName` with your web app name, and `$assigneeObjectId` with the generated `id`. Learn [how to manage Azure subscriptions with the Azure CLI](/cli/azure/manage-azure-subscriptions-azure-cli).
130
86
131
87
```azurecli-interactive
132
-
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
88
+
az role assignment create --role contributor --subscription $subscriptionId --assignee-object-id $assigneeObjectId --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Web/sites/$webappName --assignee-principal-type ServicePrincipal
133
89
```
134
90
135
91
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.
136
92
137
-
* Replace `APPLICATION-OBJECT-ID` with the **objectId (generated while creating app)** for your Active Directory application.
93
+
* Replace `APPLICATION-OBJECT-ID` with the **appId (generated while creating app)** for your Active Directory application.
138
94
* Set a value for `CREDENTIAL-NAME` to reference later.
139
95
* Set the `subject`. Its value is defined by GitHub depending on your workflow:
140
96
* Jobs in your GitHub Actions environment: `repo:< Organization/Repository >:environment:< Name >`
@@ -154,14 +110,69 @@ OpenID Connect is an authentication method that uses short-lived tokens. Setting
154
110
]
155
111
}
156
112
```
157
-
158
-
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).
113
+
114
+
# [Publish profile](#tab/applevel)
115
+
116
+
> [!NOTE]
117
+
> Publish profile requires [basic authentication](configure-basic-auth-disable.md) to be enabled.
118
+
119
+
A publish profile is an app-level credential. Set up your publish profile as a GitHub secret.
120
+
121
+
1. Go to your app service in the Azure portal.
122
+
123
+
1. On the **Overview** page, select **Get Publish profile**.
124
+
125
+
1. Save the downloaded file. You'll use the contents of the file to create a GitHub secret.
126
+
127
+
> [!NOTE]
128
+
> As of October 2020, Linux web apps needs the app setting `WEBSITE_WEBDEPLOY_USE_SCM` set to `true` **before downloading the publish profile**. This requirement will be removed in the future.
129
+
130
+
# [Service principal](#tab/userlevel)
131
+
132
+
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.
133
+
134
+
```azurecli-interactive
135
+
az ad sp create-for-rbac --name "myApp" --role contributor \
In the previous 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 similar to the following JSON snippet. Copy this JSON object for later.
141
+
142
+
```output
143
+
{
144
+
"clientId": "<GUID>",
145
+
"clientSecret": "<GUID>",
146
+
"subscriptionId": "<GUID>",
147
+
"tenantId": "<GUID>",
148
+
(...)
149
+
}
150
+
```
151
+
152
+
> [!IMPORTANT]
153
+
> 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.
159
154
160
155
---
161
156
162
157
### 2. Configure the GitHub secret
163
158
164
159
160
+
# [OpenID Connect](#tab/openid)
161
+
162
+
You need to provide your application's **Client ID**, **Tenant ID** and **Subscription ID** to the [Azure/login](https://github.com/marketplace/actions/azure-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.
163
+
164
+
1. Open your GitHub repository and go to **Settings > Security > Secrets and variables > Actions > New repository secret**.
165
+
166
+
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:
167
+
168
+
|GitHub Secret | Active Directory Application |
169
+
|---------|---------|
170
+
|AZURE_CLIENT_ID | Application (client) ID |
171
+
|AZURE_TENANT_ID | Directory (tenant) ID |
172
+
|AZURE_SUBSCRIPTION_ID | Subscription ID |
173
+
174
+
1. Save each secret by selecting **Add secret**.
175
+
165
176
# [Publish profile](#tab/applevel)
166
177
167
178
In [GitHub](https://github.com/), browse your repository. Select **Settings > Security > Secrets and variables > Actions > New repository secret**.
@@ -190,22 +201,6 @@ When you configure the GitHub workflow file later, you use the secret for the in
190
201
creds: ${{ secrets.AZURE_CREDENTIALS }}
191
202
```
192
203
193
-
# [OpenID Connect](#tab/openid)
194
-
195
-
You need to provide your application's **Client ID**, **Tenant ID** and **Subscription ID** to the [Azure/login](https://github.com/marketplace/actions/azure-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.
196
-
197
-
1. Open your GitHub repository and go to **Settings > Security > Secrets and variables > Actions > New repository secret**.
198
-
199
-
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:
200
-
201
-
|GitHub Secret | Active Directory Application |
202
-
|---------|---------|
203
-
|AZURE_CLIENT_ID | Application (client) ID |
204
-
|AZURE_TENANT_ID | Directory (tenant) ID |
205
-
|AZURE_SUBSCRIPTION_ID | Subscription ID |
206
-
207
-
1. Save each secret by selecting **Add secret**.
208
-
209
204
---
210
205
211
206
### 3. Add the workflow file to your GitHub repository
@@ -222,6 +217,10 @@ To deploy your code to an App Service app, you use the [azure/webapps-deploy@v3]
222
217
223
218
The following examples show the part of the workflow that builds the web app, in different supported languages.
- [How do I deploy a WAR file through Maven plugin and OpenID Connect](#how-do-i-deploy-a-war-file-through-maven-plugin-and-openid-connect)
238
+
- [How do I deploy a WAR file through Az CLI and OpenID Connect](#how-do-i-deploy-a-war-file-through-az-cli-and-openid-connect)
239
+
- [How do I deploy to a Container](#how-do-i-deploy-to-a-container)
240
+
- [How do I update the Tomcat configuration after deployment](#how-do-i-update-the-tomcat-configuration-after-deployment)
241
+
242
+
### How do I deploy a WAR file through Maven plugin and OpenID Connect
243
+
244
+
In case you configured your Java Tomcat project with the [Maven plugin](https://github.com/microsoft/azure-maven-plugins), you can also deploy to Azure App Service through this plugin. If you use the [Azure CLI GitHub action](https://github.com/Azure/cli) it will make use of your Azure login credentials.
245
+
246
+
```yaml
247
+
- name: Azure CLI script file
248
+
uses: azure/cli@v2
249
+
with:
250
+
inlineScript: |
251
+
mvn package azure-webapp:deploy
252
+
```
253
+
254
+
More information on the Maven plugin and how to use and configure it can be found in the [Maven plugin wiki for Azure App Service](https://github.com/microsoft/azure-maven-plugins/wiki/Azure-Web-App).
255
+
256
+
257
+
### How do I deploy a WAR file through Az CLI and OpenID Connect
258
+
259
+
If you use prefer the Azure CLI to deploy to App Service, you can use the GitHub Action for CLI.
260
+
261
+
```yaml
262
+
- name: Azure CLI script
263
+
uses: azure/cli@v2
264
+
with:
265
+
inlineScript: |
266
+
az webapp deploy --src-path '${{ github.workspace }}/target/yourpackage.war' --name ${{ env.AZURE_WEBAPP_NAME }} --resource-group ${{ env.RESOURCE_GROUP }} --async true --type war
267
+
```
268
+
269
+
More information on the GitHub Action for CLI and how to use and configure it can be found in the [Azure CLI GitHub action](https://github.com/Azure/cli).
270
+
More information on the az webapp deploy command, how to use and the parameter details can be found in the [az webapp deploy documentation](/cli/azure/webapp?view=azure-cli-latest#az-webapp-deploy).
271
+
272
+
### How do I deploy to a Container
273
+
274
+
With the Azure Web Deploy action, you can automate your workflow to deploy custom containers to App Service using GitHub Actions. Detailed information on the steps to deploy using GitHub Actions, can be found in the [Deploy to a Container](/azure/app-service/deploy-container-github-action).
275
+
276
+
### How do I update the Tomcat configuration after deployment
277
+
278
+
In case you would like to update any of your web apps settings after deployment, you can use the [App Service Settings](https://github.com/Azure/appservice-settings) action.
279
+
280
+
```yaml
281
+
- uses: azure/appservice-settings@v1
282
+
with:
283
+
app-name: 'my-app'
284
+
slot-name: 'staging' # Optional and needed only if the settings have to be configured on the specific deployment slot
general-settings-json: '{"alwaysOn": "false", "webSocketsEnabled": "true"}' #'General configuration settings as Key Value pairs'
288
+
id: settings
289
+
```
290
+
291
+
More information on this action and how to use and configure it can be found in the [App Service Settings](https://github.com/Azure/appservice-settings) repository.
292
+
238
293
239
294
## Next steps
240
295
@@ -246,4 +301,4 @@ Check out references on Azure GitHub Actions and workflows:
Copy file name to clipboardExpand all lines: articles/app-service/includes/deploy-github-actions/deploy-github-actions-openid-connect.md
+51-1Lines changed: 51 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -120,7 +120,7 @@ jobs:
120
120
az logout
121
121
```
122
122
123
-
# [Java](#tab/java)
123
+
# [Java SE](#tab/java)
124
124
125
125
Build and deploy a Java Spring app to Azure using an Azure service principal. The example uses GitHub secrets for the `client-id`, `tenant-id`, and `subscription-id` values. You can also pass these values directly in the login action.
126
126
@@ -164,6 +164,56 @@ jobs:
164
164
az logout
165
165
```
166
166
167
+
# [Tomcat](#tab/tomcat)
168
+
169
+
```yaml
170
+
name: Build and deploy WAR app to Azure Web App using OpenID Connect
171
+
172
+
env:
173
+
JAVA_VERSION: '11' # set this to the Java version to use
174
+
DISTRIBUTION: microsoft # set this to the Java distribution
175
+
AZURE_WEBAPP_NAME: sampleapp # set this to the name of your web app
You can find this full example using multiple jobs for build and deploy [here](https://github.com/Azure-Samples/onlinebookstore/blob/master/.github/workflows/azure-webapps-java-war-oidc.yml) as well.
0 commit comments