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/app-service/overview-managed-identity.md
+55-44Lines changed: 55 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ description: Learn how managed identities work in Azure App Service and Azure Fu
4
4
author: mattchenderson
5
5
6
6
ms.topic: article
7
-
ms.date: 03/04/2020
7
+
ms.date: 04/14/2020
8
8
ms.author: mahender
9
9
ms.reviewer: yevbronsh
10
10
@@ -17,7 +17,8 @@ ms.reviewer: yevbronsh
17
17
18
18
This topic shows you how to create a managed identity for App Service and Azure Functions applications and how to use it to access other resources. A managed identity from Azure Active Directory (AAD) allows your app to easily access other AAD-protected resources such as Azure Key Vault. The identity is managed by the Azure platform and does not require you to provision or rotate any secrets. For more about managed identities in AAD, see [Managed identities for Azure resources](../active-directory/managed-identities-azure-resources/overview.md).
19
19
20
-
Your application can be granted two types of identities:
20
+
Your application can be granted two types of identities:
21
+
21
22
- A **system-assigned identity** is tied to your application and is deleted if your app is deleted. An app can only have one system-assigned identity.
22
23
- A **user-assigned identity** is a standalone Azure resource that can be assigned to your app. An app can have multiple user-assigned identities.
23
24
@@ -54,6 +55,7 @@ The following steps will walk you through creating a web app and assigning it an
54
55
```azurecli-interactive
55
56
az login
56
57
```
58
+
57
59
2. Create a web application using the CLI. For more examples of how to use the CLI with App Service, see [App Service CLI samples](../app-service/samples-cli.md):
58
60
59
61
```azurecli-interactive
@@ -81,10 +83,10 @@ The following steps will walk you through creating a web app and assigning it an
@@ -100,18 +102,20 @@ The following steps will walk you through creating a web app and assigning it an
100
102
An Azure Resource Manager template can be used to automate deployment of your Azure resources. To learn more about deploying to App Service and Functions, see [Automating resource deployment in App Service](../app-service/deploy-complex-application-predictably.md) and [Automating resource deployment in Azure Functions](../azure-functions/functions-infrastructure-as-code.md).
101
103
102
104
Any resource of type `Microsoft.Web/sites` can be created with an identity by including the following property in the resource definition:
105
+
103
106
```json
104
107
"identity": {
105
108
"type": "SystemAssigned"
106
-
}
109
+
}
107
110
```
108
111
109
-
> [!NOTE]
112
+
> [!NOTE]
110
113
> An application can have both system-assigned and user-assigned identities at the same time. In this case, the `type` property would be `SystemAssigned,UserAssigned`
111
114
112
115
Adding the system-assigned type tells Azure to create and manage the identity for your application.
113
116
114
117
For example, a web app might look like the following:
118
+
115
119
```json
116
120
{
117
121
"apiVersion": "2016-08-01",
@@ -135,6 +139,7 @@ For example, a web app might look like the following:
135
139
```
136
140
137
141
When the site is created, it has the following additional properties:
142
+
138
143
```json
139
144
"identity": {
140
145
"type": "SystemAssigned",
@@ -145,7 +150,6 @@ When the site is created, it has the following additional properties:
145
150
146
151
The tenantId property identifies what AAD tenant the identity belongs to. The principalId is a unique identifier for the application's new identity. Within AAD, the service principal has the same name that you gave to your App Service or Azure Functions instance.
147
152
148
-
149
153
## Add a user-assigned identity
150
154
151
155
Creating an app with a user-assigned identity requires that you create the identity and then add its resource identifier to your app config.
@@ -173,21 +177,23 @@ First, you'll need to create a user-assigned identity resource.
173
177
An Azure Resource Manager template can be used to automate deployment of your Azure resources. To learn more about deploying to App Service and Functions, see [Automating resource deployment in App Service](../app-service/deploy-complex-application-predictably.md) and [Automating resource deployment in Azure Functions](../azure-functions/functions-infrastructure-as-code.md).
174
178
175
179
Any resource of type `Microsoft.Web/sites` can be created with an identity by including the following block in the resource definition, replacing `<RESOURCEID>` with the resource ID of the desired identity:
180
+
176
181
```json
177
182
"identity": {
178
183
"type": "UserAssigned",
179
184
"userAssignedIdentities": {
180
185
"<RESOURCEID>": {}
181
186
}
182
-
}
187
+
}
183
188
```
184
189
185
-
> [!NOTE]
190
+
> [!NOTE]
186
191
> An application can have both system-assigned and user-assigned identities at the same time. In this case, the `type` property would be `SystemAssigned,UserAssigned`
187
192
188
193
Adding the user-assigned type tells Azure to use the user-assigned identity specified for your application.
189
194
190
195
For example, a web app might look like the following:
196
+
191
197
```json
192
198
{
193
199
"apiVersion": "2016-08-01",
@@ -215,6 +221,7 @@ For example, a web app might look like the following:
215
221
```
216
222
217
223
When the site is created, it has the following additional properties:
224
+
218
225
```json
219
226
"identity": {
220
227
"type": "UserAssigned",
@@ -229,7 +236,6 @@ When the site is created, it has the following additional properties:
229
236
230
237
The principalId is a unique identifier for the identity that's used for AAD administration. The clientId is a unique identifier for the application's new identity that's used for specifying which identity to use during runtime calls.
231
238
232
-
233
239
## Obtain tokens for Azure resources
234
240
235
241
An app can use its managed identity to get tokens to access other resources protected by AAD, such as Azure Key Vault. These tokens represent the application accessing the resource, and not any specific user of the application.
@@ -245,56 +251,61 @@ There is a simple REST protocol for obtaining a token in App Service and Azure F
245
251
246
252
An app with a managed identity has two environment variables defined:
247
253
248
-
-MSI_ENDPOINT - the URL to the local token service.
249
-
-MSI_SECRET - a header used to help mitigate server-side request forgery (SSRF) attacks. The value is rotated by the platform.
254
+
-IDENTITY_ENDPOINT - the URL to the local token service.
255
+
-IDENTITY_HEADER - a header used to help mitigate server-side request forgery (SSRF) attacks. The value is rotated by the platform.
250
256
251
-
The **MSI_ENDPOINT** is a local URL from which your app can request tokens. To get a token for a resource, make an HTTP GET request to this endpoint, including the following parameters:
257
+
The **IDENTITY_ENDPOINT** is a local URL from which your app can request tokens. To get a token for a resource, make an HTTP GET request to this endpoint, including the following parameters:
252
258
253
-
> |Parameter name|In|Description|
254
-
> |-----|-----|-----|
255
-
> |resource|Query|The AAD resource URI of the resource for which a token should be obtained. This could be one of the [Azure services that support Azure AD authentication](../active-directory/managed-identities-azure-resources/services-support-managed-identities.md#azure-services-that-support-azure-ad-authentication) or any other resource URI.|
256
-
> |api-version|Query|The version of the token API to be used. "2017-09-01" is currently the only version supported.|
257
-
> |secret|Header|The value of the MSI_SECRET environment variable. This header is used to help mitigate server-side request forgery (SSRF) attacks.|
258
-
> |clientid|Query|(Optional unless for user-assigned) The ID of the user-assigned identity to be used. If omitted, the system-assigned identity is used.|
> | resource | Query | The AAD resource URI of the resource for which a token should be obtained. This could be one of the [Azure services that support Azure AD authentication](../active-directory/managed-identities-azure-resources/services-support-managed-identities.md#azure-services-that-support-azure-ad-authentication) or any other resource URI. |
262
+
> | api-version | Query | The version of the token API to be used. Please use "2019-08-01" or later. |
263
+
> | X-IDENTITY-HEADER | Header | The value of the IDENTITY_HEADER environment variable. This header is used to help mitigate server-side request forgery (SSRF) attacks. |
264
+
> | client_id | Query | (Optional) The client ID of the user-assigned identity to be used. Cannot be used on a request that includes `principal_id`, `mi_res_id`, or `object_id`. If all ID parameters (`client_id`, `principal_id`, `object_id`, and `mi_res_id`) are omitted, the system-assigned identity is used. |
265
+
> | principal_id | Query | (Optional) The principal ID of the user-assigned identity to be used. `object_id` is an alias that may be used instead. Cannot be used on a request that includes client_id, mi_res_id, or object_id. If all ID parameters (`client_id`, `principal_id`, `object_id`, and `mi_res_id`) are omitted, the system-assigned identity is used. |
266
+
> | mi_res_id | Query | (Optional) The Azure resource ID of the user-assigned identity to be used. Cannot be used on a request that includes `principal_id`, `client_id`, or `object_id`. If all ID parameters (`client_id`, `principal_id`, `object_id`, and `mi_res_id`) are omitted, the system-assigned identity is used. |
259
267
260
268
> [!IMPORTANT]
261
-
> If you are attempting to obtain tokens for user-assigned identities, you must include the `clientid` property. Otherwise the token service will attempt to obtain a token for a system-assigned identity, which may or may not exist.
269
+
> If you are attempting to obtain tokens for user-assigned identities, you must include one of the optional properties. Otherwise the token service will attempt to obtain a token for a system-assigned identity, which may or may not exist.
262
270
263
271
A successful 200 OK response includes a JSON body with the following properties:
264
272
265
-
> |Property name|Description|
266
-
> |-------------|----------|
267
-
> |access_token|The requested access token. The calling web service can use this token to authenticate to the receiving web service.|
268
-
> |expires_on|The time when the access token expires. The date is represented as the number of seconds from 1970-01-01T0:0:0Z UTC until the expiration time. This value is used to determine the lifetime of cached tokens.|
269
-
> |resource|The App ID URI of the receiving web service.|
270
-
> |token_type|Indicates the token type value. The only type that Azure AD supports is Bearer. For more information about bearer tokens, see [The OAuth 2.0 Authorization Framework: Bearer Token Usage (RFC 6750)](https://www.rfc-editor.org/rfc/rfc6750.txt).|
> | access_token | The requested access token. The calling web service can use this token to authenticate to the receiving web service. |
276
+
> | client_id | The client ID of the identity that was used. |
277
+
> | expires_on | The timespan when the access token expires. The date is represented as the number of seconds from "1970-01-01T0:0:0Z UTC" (corresponds to the token's `exp` claim). |
278
+
> | not_before | The timespan when the access token takes effect, and can be accepted. The date is represented as the number of seconds from "1970-01-01T0:0:0Z UTC" (corresponds to the token's `nbf` claim). |
279
+
> | resource | The resource the access token was requested for, which matches the `resource` query string parameter of the request. |
280
+
> | token_type | Indicates the token type value. The only type that Azure AD supports is FBearer. For more information about bearer tokens, see [The OAuth 2.0 Authorization Framework: Bearer Token Usage (RFC 6750)](https://www.rfc-editor.org/rfc/rfc6750.txt). |
271
281
272
-
This response is the same as the [response for the AAD service-to-service access token request](../active-directory/develop/v2-oauth2-client-creds-grant-flow.md#get-a-token).
282
+
This response is the same as the [response for the AAD service-to-service access token request](../active-directory/develop/v1-oauth2-client-creds-grant-flow.md#service-to-service-access-token-response).
273
283
274
284
> [!NOTE]
275
-
> Environment variables are set up when the process first starts, so after enabling a managed identity for your application, you may need to restart your application, or redeploy its code, before `MSI_ENDPOINT`and `MSI_SECRET` are available to your code.
285
+
> An older version of this protocol, using the "2017-09-01" API version, used the `secret` header instead of `X-IDENTITY-HEADER` and only accepted the `clientid` property for user-assigned. It also returned the `expires_on` in a timestamp format. MSI_ENDPOINT can be used as an alias for IDENTITY_ENDPOINT, and MSI_SECRET can be used as an alias for IDENTITY_HEADER.
276
286
277
287
### REST protocol examples
278
288
279
289
An example request might look like the following:
280
290
281
-
```
282
-
GET /MSI/token?resource=https://vault.azure.net&api-version=2017-09-01 HTTP/1.1
291
+
```http
292
+
GET /MSI/token?resource=https://vault.azure.net&api-version=2019-08-01 HTTP/1.1
0 commit comments