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/storage/common/multiple-identity-scenarios.md
+31-29Lines changed: 31 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,40 +6,40 @@ services: storage
6
6
author: alexwolfmsft
7
7
ms.service: storage
8
8
ms.topic: how-to
9
-
ms.date: 08/01/2022
9
+
ms.date: 09/23/2022
10
10
ms.author: alexwolf
11
11
ms.subservice: common
12
12
ms.custom: devx-track-csharp
13
13
---
14
14
15
15
# Configure passwordless connections between multiple Azure apps and services
16
16
17
-
Applications often require secure connections between multiple Azure services simultaneously. For example, an enterprise Azure App Service instance might connect to several different storage accounts, an Azure SQL database instance, a service bus, and more.
17
+
Applications often require secure connections between multiple Azure services simultaneously. For example, an enterprise Azure App Service instance might connect to several different storage accounts, an Azure SQL database instance, a service bus, and more.
18
18
19
19
[Managed identities](/azure/active-directory/managed-identities-azure-resources/overview) are the recommended authentication option for secure, passwordless connections between Azure resources. Developers do not have to manually track and manage many different secrets for managed identities, since most of these tasks are handled internally by Azure. This tutorial explores how to manage connections between multiple services using managed identities and the Azure Identity client library.
20
20
21
21
## Compare the types of managed identities
22
22
23
23
Azure provides the following types of managed identities:
24
24
25
-
***System-assigned managed identities** are directly tied to a single Azure resource. When you enable a system-assigned managed identity on a service, Azure will create a linked identity and handle administrative tasks for that identity internally. When the Azure resource is deleted, the identity is also deleted.
26
-
***User-assigned managed identities** are independent identities that are created by an administrator and can be associated with one or more Azure resources. The lifecycle of the identity is independent of those resources.
25
+
***System-assigned managed identities** are directly tied to a single Azure resource. When you enable a system-assigned managed identity on a service, Azure will create a linked identity and handle administrative tasks for that identity internally. When the Azure resource is deleted, the identity is also deleted.
26
+
***User-assigned managed identities** are independent identities that are created by an administrator and can be associated with one or more Azure resources. The lifecycle of the identity is independent of those resources.
27
27
28
28
You can read more about best practices and when to use system-assigned identities versus user-assigned identities in the [identities best practice recommendations](/azure/active-directory/managed-identities-azure-resources/managed-identity-best-practice-recommendations).
29
29
30
30
## Explore DefaultAzureCredential
31
31
32
-
Managed identities are generally implemented in your application code through a class called `DefaultAzureCredential` from the `Azure.Identity` client library. `DefaultAzureCredential` supports multiple authentication methods and automatically determines which should be used at runtime. You can read more about this approach in the [DefaultAzureCredential overview](/dotnet/api/overview/azure/Identity-readme#defaultazurecredential).
32
+
Managed identities are generally implemented in your application code through a class called `DefaultAzureCredential` from the `Azure.Identity` client library. `DefaultAzureCredential` supports multiple authentication methods and automatically determines which should be used at runtime. You can read more about this approach in the [DefaultAzureCredential overview](/dotnet/api/overview/azure/Identity-readme#defaultazurecredential).
33
33
34
34
## Connect an Azure hosted app to multiple Azure services
35
35
36
36
You have been tasked with connecting an existing app to multiple Azure services and databases using passwordless connections. The application is an ASP.NET Core Web API hosted on Azure App Service, though the steps below apply to other Azure hosting environments as well, such as Azure Spring Apps, Virtual Machines, Container Apps and AKS.
37
37
38
38
This tutorial applies to the following architectures, though it can be adapted to many other scenarios as well through minimal configuration changes.
39
39
40
-
:::image type="content" source="media/architecture-diagram-multiple-services-small.png" alt-text="A diagram showing the user assigned identity relationships." lightbox="media/architecture-diagram-multiple-services.png":::
40
+
:::image type="content" source="media/architecture-diagram-multiple-services-small.png" alt-text="Diagram showing the user assigned identity relationships." lightbox="media/architecture-diagram-multiple-services.png":::
41
41
42
-
The following steps demonstrate how to configure an app to use a system-assigned managed identity and your local development account to connect to multiple Azure Services.
42
+
The following steps demonstrate how to configure an app to use a system-assigned managed identity and your local development account to connect to multiple Azure Services.
43
43
44
44
### Create a system-assigned managed identity
45
45
@@ -49,33 +49,33 @@ The following steps demonstrate how to configure an app to use a system-assigned
49
49
50
50
3) Toggle the **Status** setting to **On** to enable a system assigned managed identity for the service.
51
51
52
-
:::image type="content" source="media/enable-system-assigned-identity.png" alt-text="A screenshot showing how to assign a system assigned managed identity." :::
52
+
:::image type="content" source="media/enable-system-assigned-identity.png" alt-text="Screenshot showing how to assign a system assigned managed identity." :::
53
53
54
54
### Assign roles to the managed identity for each connected service
55
-
55
+
56
56
1) Navigate to the overview page of the storage account you would like to grant access your identity access to.
57
57
58
58
3) Select **Access Control (IAM)** from the storage account navigation.
59
59
60
60
4) Choose **+ Add** and then **Add role assignment**.
61
61
62
-
:::image type="content" source="media/assign-role-system-identity.png" alt-text="A screenshot showing how to assign a system-assigned identity." :::
62
+
:::image type="content" source="media/assign-role-system-identity.png" alt-text="Screenshot showing how to assign a system-assigned identity." :::
63
63
64
64
5) In the **Role** search box, search for *Storage Blob Data Contributor*, which grants permissions to perform read and write operations on blob data. You can assign whatever role is appropriate for your use case. Select the *Storage Blob Data Contributor* from the list and choose **Next**.
65
65
66
66
6) On the **Add role assignment** screen, for the **Assign access to** option, select **Managed identity**. Then choose **+Select members**.
67
67
68
68
7) In the flyout, search for the managed identity you created by entering the name of your app service. Select the system assigned identity, and then choose **Select** to close the flyout menu.
69
69
70
-
:::image type="content" source="media/migration-select-identity.png" alt-text="A screenshot showing how to select a system-assigned identity." :::
70
+
:::image type="content" source="media/migration-select-identity.png" alt-text="Screenshot showing how to select a system-assigned identity." :::
71
71
72
72
8) Select **Next** a couple times until you're able to select **Review + assign** to finish the role assignment.
73
73
74
74
9) Repeat this process for the other services you would like to connect to.
75
75
76
76
#### Local development considerations
77
77
78
-
You can also enable access to Azure resources for local development by assigning roles to a user account the same way you assigned roles to your managed identity.
78
+
You can also enable access to Azure resources for local development by assigning roles to a user account the same way you assigned roles to your managed identity.
79
79
80
80
1) After assigning the **Storage Blob Data Contributor** role to your managed identity, under **Assign access to**, this time select **User, group or service principal**. Choose **+ Select members** to open the flyout menu again.
81
81
@@ -115,9 +115,9 @@ var serviceBusClient = new ServiceBusClient("<your-namespace>", new DefaultAzure
Inside of your project, add dependency`azure-identity` to your pom.xml. This library contains all the necessary entities to implement `DefaultAzureCredential`. You can also add any other Azure dependencies that are relevant to your app. For this example, the `azure-storage-blob` and `azure-messaging-servicebus` dependencies are added in order to connect to Blob Storage and Key Vault.
120
+
Inside your project, add the`azure-identity`dependency to your *pom.xml* file. This library contains all the necessary entities to implement `DefaultAzureCredential`. You can also add any other Azure dependencies that are relevant to your app. For this example, the `azure-storage-blob` and `azure-messaging-servicebus` dependencies are added in order to connect to Blob Storage and Key Vault.
121
121
122
122
```xml
123
123
<dependencyManagement>
@@ -171,9 +171,9 @@ class Demo {
171
171
}
172
172
```
173
173
174
-
#### [spring](#tab/spring)
174
+
#### [Spring](#tab/spring)
175
175
176
-
Inside of your project, only need to add service dependencies you use. For this example, the `spring-cloud-azure-starter-storage-blob` and `spring-cloud-azure-starter-servicebus` dependencies are added in order to connect to Blob Storage and Key Vault.
176
+
Inside your project, only need to add service dependencies you use. For this example, the `spring-cloud-azure-starter-storage-blob` and `spring-cloud-azure-starter-servicebus` dependencies are added in order to connect to Blob Storage and Key Vault.
177
177
178
178
```xml
179
179
<dependencyManagement>
@@ -239,9 +239,10 @@ This overall process ensures that your app can run securely locally and in Azure
239
239
240
240
Although the apps in the previous example all shared the same service access requirements, real environments are often more nuanced. Consider a scenario where multiple apps all connect to the same storage accounts, but two of the apps also access different services or databases.
To configure this setup in your code, make sure your application registers separate services to connect to each storage account or database. Make sure to pull in the correct managed identity client IDs for each service when configuring `DefaultAzureCredential`. The following code example configures the following service connections:
245
+
245
246
* Two connections to separate storage accounts using a shared user-assigned managed identity
246
247
* A connection to Azure Cosmos DB and Azure SQL services using a second shared user-assigned managed identity
247
248
@@ -263,7 +264,7 @@ BlobServiceClient blobServiceClient = new BlobServiceClient(
@@ -289,9 +290,9 @@ using (SqlConnection conn = new SqlConnection(ConnectionString1))
289
290
290
291
```
291
292
292
-
### [java](#tab/java)
293
+
### [Java](#tab/java)
293
294
294
-
Add the following to your `pom.xml`:
295
+
Add the following to your *pom.xml* file:
295
296
296
297
```xml
297
298
<dependencyManagement>
@@ -374,9 +375,9 @@ class Demo {
374
375
}
375
376
```
376
377
377
-
### [spring](#tab/spring)
378
+
### [Spring](#tab/spring)
378
379
379
-
Add the following to your `pom.xml`:
380
+
Add the following to your *pom.xml* file:
380
381
381
382
```xml
382
383
<dependencyManagement>
@@ -409,7 +410,8 @@ Add the following to your `pom.xml`:
409
410
</dependency>
410
411
</dependencies>
411
412
```
412
-
Add the following to your `application.yml`:
413
+
414
+
Add the following to your *application.yml* file:
413
415
414
416
```yaml
415
417
spring:
@@ -433,7 +435,7 @@ spring:
433
435
Add the following to your code:
434
436
435
437
> [!NOTE]
436
-
> Spring Cloud Azure doesn't support configure multiple clients of the same service, the following codes create multiple beans for this situation.
438
+
> Spring Cloud Azure doesn't support configure multiple clients of the same service, the following codes create multiple beans for this situation.
437
439
438
440
```java
439
441
@Configuration
@@ -476,15 +478,15 @@ public class ExampleService {
476
478
477
479
You can also associate a user-assigned managed identity as well as a system-assigned managed identity to a resource simultaneously. This can be useful in scenarios where all of the apps require access to the same shared services, but one of the apps also has a very specific dependency on an additional service. Using a system-assigned identity also ensures that the identity tied to that specific app is deleted when the app is deleted, which can help keep your environment clean.
These types of scenarios are explored in more depth in the [identities best practice recommendations](/azure/active-directory/managed-identities-azure-resources/managed-identity-best-practice-recommendations).
482
484
483
485
## Next steps
484
486
485
487
In this tutorial, you learned how to migrate an application to passwordless connections. You can read the following resources to explore the concepts discussed in this article in more depth:
486
488
487
-
- For more information on authorizing access with managed identity, visit [Authorize access to blob data with managed identities for Azure resources](/azure/storage/blobs/authorize-managed-identity).
488
-
-[Authorize with Azure roles](/azure/storage/blobs/authorize-access-azure-active-directory)
489
-
- To learn more about .NET Core, see [Get started with .NET in 10 minutes](https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/intro).
490
-
- To learn more about authorizing from a web application, visit [Authorize from a native or web application](/azure/storage/common/storage-auth-aad-app)
489
+
* For more information on authorizing access with managed identity, visit [Authorize access to blob data with managed identities for Azure resources](/azure/storage/blobs/authorize-managed-identity).
490
+
*[Authorize with Azure roles](/azure/storage/blobs/authorize-access-azure-active-directory)
491
+
* To learn more about .NET Core, see [Get started with .NET in 10 minutes](https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/intro).
492
+
* To learn more about authorizing from a web application, visit [Authorize from a native or web application](/azure/storage/common/storage-auth-aad-app).
0 commit comments