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/migrate-azure-credentials.md
+19-29Lines changed: 19 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,40 +15,24 @@ ms.devlang: csharp
15
15
16
16
# Migrate an application to use passwordless connections with Azure Storage
17
17
18
-
Application requests to Azure Storage must be authenticated using either account access keys or passwordless connections. However, you should prioritize passwordless connections in your applications when possible. This tutorial explores how to migrate from traditional authentication methods to more secure, passwordless connections.
18
+
Application requests to Azure Storage must be authenticated using either account access keys or passwordless connections. However, you should prioritize passwordless connections in your applications when possible. Traditional authentication methods that use passwords or secret keys create additional security risks and complications. Visit the [passwordless connections for Azure services](/azure/developer/intro/passwordless-overview) hub to learn more about the advantages of moving to passwordless connections.
19
19
20
-
## Security risks associated with Shared Key authorization
20
+
The following tutorial explains how to migrate an existing application to connect to Azure Storage 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.
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'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, 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
-
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
-
40
-
### Configure roles and users for local development authentication
22
+
## Configure roles and users for local development authentication
###Sign-in and migrate the app code to use passwordless connections
26
+
## Sign-in and migrate the app code to use passwordless connections
45
27
46
28
For local development, make sure you're authenticated with the same Azure AD account you assigned the role to on your Blob Storage account. You can authenticate via the Azure CLI, Visual Studio, Azure PowerShell, or other tools such as IntelliJ.
Next you need to update your code to use passwordless connections.
51
33
34
+
## [.NET](#tab/dotnet)
35
+
52
36
1. To use `DefaultAzureCredential` in a .NET application, add the **Azure.Identity** NuGet package to your application.
53
37
54
38
```dotnetcli
@@ -74,23 +58,25 @@ Next you need to update your code to use passwordless connections.
74
58
75
59
:::image type="content" source="../blobs/media/storage-quickstart-blobs-dotnet/storage-account-name.png" alt-text="Screenshot showing how to find the storage account name.":::
76
60
77
-
#### Run the app locally
61
+
---
62
+
63
+
### Run the app locally
78
64
79
65
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
66
81
-
###Configure the Azure hosting environment
67
+
## Configure the Azure hosting environment
82
68
83
69
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.
#### Associate the managed identity with your web app
90
76
91
77
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
78
93
-
# [Azure Portal](#tab/azure-portal-associate)
79
+
# [Azure portal](#tab/azure-portal-associate)
94
80
95
81
Complete the following steps in the Azure portal to associate an identity with your app. These same steps apply to the following Azure services:
96
82
@@ -119,7 +105,7 @@ Complete the following steps in the Azure portal to associate an identity with y
119
105
120
106
---
121
107
122
-
####Assign roles to the managed identity
108
+
### Assign roles to the managed identity
123
109
124
110
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.
125
111
@@ -167,10 +153,12 @@ If you connected your services using Service Connector you don't need to complet
167
153
168
154
---
169
155
170
-
####Update the application code
156
+
### Update the application code
171
157
172
158
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
159
160
+
## [.NET](#tab/dotnet)
161
+
174
162
1. On the managed identity overview page, copy the client ID value to your clipboard.
175
163
1. Update the `DefaultAzureCredential` object in the `Program.cs` file of your app to specify this managed identity client ID.
176
164
@@ -187,7 +175,9 @@ You need to configure your application code to look for the specific managed ide
187
175
188
176
3. RedeployyourcodetoAzureaftermakingthischangeinorderfor the configuration updates to be applied.
189
177
190
-
#### Test the app
178
+
---
179
+
180
+
### Test the app
191
181
192
182
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.
0 commit comments