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
@@ -19,23 +19,23 @@ Application requests to Azure Storage must be authenticated using either account
19
19
20
20
## Security risks associated with Shared Key authorization
21
21
22
-
The following code example demonstrates how to connect to Azure Storage using a storage account key. When you create a storage account, Azure generates access keys for that account. Many developers gravitate towards this solution because it feels familiar to options they have worked with in the past. For example, connection strings for storage accounts also use access keys as part of the string. If your application currently uses access keys, consider migrating to passwordless connections using the steps described later in this document.
22
+
The following code example demonstrates how to connect to Azure Storage using a storage account key. When you create a storage account, Azure generates access keys for that account. Many developers gravitate towards this solution because it feels familiar to options they've worked with in the past. For example, connection strings for storage accounts also use access keys as part of the string. If your application currently uses access keys, consider migrating to passwordless connections using the steps described later in this document.
Storage account keys should be used with caution. Developers must be diligent to never expose the keys in an unsecure location. Anyone who gains access to the key is able to authenticate. For example, if an account key is accidentally checked into source control, sent through an unsecure email, pasted into the wrong chat, or viewed by someone who shouldn't have permission, there's risk of a malicious user accessing the application. Instead, consider updating your application to use passwordless connections.
30
+
Storage account keys should be used with caution. Developers must be diligent to never expose the keys in an unsecure location. Anyone who gains access to the key is able to authenticate. For example, if an account key is accidentally checked into source control, sent through an unsecure email, or viewed by someone who shouldn't have permission, there's risk of a malicious user accessing the application. Instead, consider updating your application to use passwordless connections.
## Steps to migrate an app to use passwordless authentication
37
37
38
-
The following steps explain how to migrate an existing application to use passwordless connections instead of a key-based solution. These same migration steps should apply whether you are using access keys directly, or through connection strings.
38
+
The following steps explain how to migrate an existing application to use passwordless connections instead of a key-based solution. These same migration steps should apply whether you're using access keys directly, or through connection strings.
39
39
40
40
### Configure roles and users for local development authentication
41
41
@@ -47,7 +47,7 @@ For local development, make sure you're authenticated with the same Azure AD acc
Next you will need to update your code to use passwordless connections.
50
+
Next you need to update your code to use passwordless connections.
51
51
52
52
1. To use `DefaultAzureCredential` in a .NET application, add the **Azure.Identity** NuGet package to your application.
53
53
@@ -76,121 +76,52 @@ Next you will need to update your code to use passwordless connections.
76
76
77
77
#### Run the app locally
78
78
79
-
After making these code changes, run your application locally. The new configuration should pick up your local credentials, such as the Azure CLI, Visual Studio, or IntelliJ. The roles you assigned to your local dev user in Azure will allow your app to connect to the Azure service locally.
79
+
After making these code changes, run your application locally. The new configuration should pick up your local credentials, such as the Azure CLI, Visual Studio, or IntelliJ. The roles you assigned to your local dev user in Azure allows your app to connect to the Azure service locally.
80
80
81
81
### Configure the Azure hosting environment
82
82
83
-
Once your application is configured to use passwordless connections and runs locally, the same code can authenticate to Azure services after it is deployed to Azure. For example, an application deployed to an Azure App Service instance that has a managed identity enabled can connect to Azure Storage.
83
+
Once your application is configured to use passwordless connections and runs locally, the same code can authenticate to Azure services after it's deployed to Azure. The sections that follow explain how to configure a deployed application to connect to Azure Blob Storage using a managed identity.
84
84
85
-
#### Create the managed identity using the Azure portal
You need to configure your web app to use the managed identity you created. Assign the identity to your app using either the Azure portal or the Azure CLI.
92
92
93
-
You can use Service Connector to create a connection between an Azure compute hosting environment and a target service using the Azure CLI. The CLI automatically handles creating a managed identity and assigns the proper role, as explained in the [portal instructions](#create-the-managed-identity-using-the-azure-portal).
93
+
# [Azure Portal](#tab/azure-portal-associate)
94
94
95
-
If you're using an Azure App Service, use the `az webapp connection` command:
95
+
Complete the following steps in the Azure portal to associate an identity with your app. These same steps apply to the following Azure services:
You can assign a managed identity to an Azure Container Apps instance with the [az container app identity assign](/cli/azure/containerapp/identity) command.
102
+
1. Navigate to the overview page of your web app.
103
+
1. Select **Identity** from the left navigation.
104
+
1. On the **Identity** page, switch to the **User assigned** tab.
105
+
1. Select **+ Add** to open the **Add user assigned managed identity** flyout.
106
+
1. Select the subscription you used previously to create the identity.
107
+
1. Search for the **MigrationIdentity** by name and select it from the search results.
108
+
1. Select **Add** to associate the identity with your app.
:::image type="content" source="../../../articles/storage/common/media/create-user-assigned-identity-small.png" alt-text="Screenshot showing how to create a user assigned identity." lightbox="../../../articles/storage/common/media/create-user-assigned-identity.png":::
162
111
163
-
You can assign a managed identity to a virtual machine with the [az vm identity assign](/cli/azure/vm/identity) command.
Next, you need to grant permissions to the managed identity you created to access your storage account. You can do this by assigning a role to the managed identity, just like you did with your local development user.
If you connected your services using the Service Connector you do not need to complete this step. The necessary configurations were handled for you:
190
-
191
-
* If you selected a managed identity while creating the connection, a system-assigned managed identity was created for your app and assigned the **Storage Blob Data Contributor** role on the storage account.
192
-
193
-
* If you selected connection string, the connection string was added as an app environment variable.
124
+
Next, you need to grant permissions to the managed identity you created to access your storage account. Grant permissions by assigning a role to the managed identity, just like you did with your local development user.
194
125
195
126
### [Azure portal](#tab/assign-role-azure-portal)
196
127
@@ -204,15 +135,15 @@ If you connected your services using the Service Connector you do not need to co
204
135
205
136
1. On the **Add role assignment** screen, for the **Assign access to** option, select **Managed identity**. Then choose **+Select members**.
206
137
207
-
1. 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.
138
+
1. In the flyout, search for the managed identity you created by name and select it from the results. Choose**Select** to close the flyout menu.
208
139
209
140
:::image type="content" source="media/migration-select-identity-small.png" alt-text="Screenshot showing how to select the assigned managed identity." lightbox="media/migration-select-identity.png":::
210
141
211
142
1. Select **Next** a couple times until you're able to select **Review + assign** to finish the role assignment.
212
143
213
144
### [Azure CLI](#tab/assign-role-azure-cli)
214
145
215
-
To assign a role at the resource level using the Azure CLI, you first must retrieve the resource ID using the az storage account show command. You can filter the output properties using the --query parameter.
146
+
To assign a role at the resource level using the Azure CLI, you first must retrieve the resource ID using the [az storage account](/cli/azure/storage/account) show command. You can filter the output properties using the `--query` parameter.
216
147
217
148
```azurecli
218
149
az storage account show \
@@ -221,7 +152,7 @@ az storage account show \
221
152
--query id
222
153
```
223
154
224
-
Copy the output ID from the preceding command. You can then assign roles using the az role command of the Azure CLI.
155
+
Copy the output ID from the preceding command. You can then assign roles using the [az role assignment](/cli/azure/role/assignment) command of the Azure CLI.
If you connected your services using Service Connector you don't need to complete this step. The necessary role configurations were handled for you when you ran the Service Connector CLI commands.
167
+
233
168
---
234
169
170
+
#### Update the application code
171
+
172
+
You need to configure your application code to look for the specific managed identity you created when it is deployed to Azure. In some scenarios, explicitly setting the managed identity for the app also prevents other environment identities from accidentally being detected and used automatically.
173
+
174
+
1. On the managed identity overview page, copy the client ID value to your clipboard.
175
+
1. Update the `DefaultAzureCredential` object in the `Program.cs` file of your app to specify this managed identity client ID.
176
+
177
+
```csharp
178
+
// TODO: Update the <your-storage-account-name> and <your-managed-identity-client-id> placeholders
3. RedeployyourcodetoAzureaftermakingthischangeinorderfor the configuration updates to be applied.
189
+
235
190
#### Test the app
236
191
237
-
After making these code changes, browse to your hosted application in the browser. Your app should be able to connect to the storage account successfully. Keep in mind that it may take several minutes for the role assignments to propagate through your Azure environment. Your application is now configured to run both locally and in a production environment without the developers having to manage secrets in the application itself.
192
+
After deploying the updated code, browse to your hosted application in the browser. Your app should be able to connect to the storage account successfully. Keep in mind that it may take several minutes for the role assignments to propagate through your Azure environment. Your application is now configured to run both locally and in a production environment without the developers having to manage secrets in the application itself.
The following steps demonstrate how to create a user-assigned managed identity for various web hosting services. The managed identity can securely connect to other Azure services using the app configurations you set up previously.
2
+
3
+
### [Service Connector](#tab/service-connector)
4
+
5
+
Some app hosting environments support Service Connector, which helps you connect Azure compute services to other backing services. Service Connector automatically configures network settings and connection information.
6
+
7
+
The following compute services are currently supported:
8
+
9
+
* Azure App Service
10
+
* Azure Spring Cloud
11
+
* Azure Container Apps (preview)
12
+
13
+
For this migration guide, you'll use App Service. The steps are similar on Azure Spring Apps and Azure Container Apps.
14
+
15
+
> [!NOTE]
16
+
> Azure Spring Apps currently only supports Service Connector using connection strings.
17
+
18
+
1. On the main overview page of your App Service, select **Service Connector** from the left navigation.
19
+
20
+
1. Select **+ Create** from the top menu and the **Create connection** panel will open. Enter the following values:
21
+
22
+
***Service type**: Choose **Service bus**.
23
+
***Subscription**: Select the subscription you would like to use.
24
+
***Connection Name**: Enter a name for your connection, such as *connector_appservice_servicebus*.
25
+
***Client type**: Leave the default value selected or choose the specific client you'd like to use.
26
+
27
+
Select **Next: Authentication**.
28
+
29
+
1. Select **User assigned managed identity**.
30
+
1. Select the subscription and **MigrationIdentity** user identity you configured in the previous section.
31
+
1. Select **Next: Networking**.
32
+
1. Leave the default values selected, and then choose **Next: Review + Create**.
33
+
1. After Azure validates your settings, select **Create**.
34
+
35
+
The Service Connector will automatically assign the managed identity an **Azure Service Bus Data Owner** role for the service bus you selected.
36
+
37
+
### [Azure portal](#tab/app-service)
38
+
39
+
You can assign the correct roles to your user-assigned managed identity through the storage account settings pages.
40
+
41
+
1. On the overview page of your storage account, select **Access control (IAM)**.
42
+
1. Select **+ Add** at the top of the page and then choose **Add role assignment** from the drop down menu.
43
+
1. On the **Add role assignment** page, leave the default **Assignment type** toggled and select **Next**.
44
+
1. On the **Role** tab, search for *Storage Blob Data Contributor* and select the matching result. Then select **Next**.
45
+
1. On the **Members** tab, make sure the following values are set:
0 commit comments