Web 应用程序与 Azure 资源通信的最佳实践?

Best practices for web app communicates to azure resources?

Net Core 应用程序和我的应用程序与各种 Azure 资源(例如 Storage Account V2)进行通信。我的应用程序已部署到 azure 应用程序服务中。我的 Web 应用程序可以通过多种方式连接到存储帐户。其中第一种方法是使用如下所示的连接字符串

   CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_azureStorageClient.AzureStorageAccount03ConnectionString);

在上面的代码中,我传递了连接字符串。我可以从 Azure Key Vault 获取连接字符串,并且可以避免在 appsettings.json 中对连接字符串进行硬编码。这是安全的我可以理解,但是如果有人不小心更改或重新生成存储帐户中的访问密钥,那么我的应用程序将无法运行。

我发现了另一种使用在 Azure 门户中注册的应用程序并在存储帐户中提供 RBAC 的方法。

 TokenCredential credential = new ClientSecretCredential(
        _authenticationConfig.TenantId, clientId, _authenticationConfig.ClientSecret, new TokenCredentialOptions()); 

通过这种方式,我还可以避免使用连接字符串,并且可以根据角色访问存储帐户。但在这种情况下,我最终也会在 code/key 保险库中管理客户端密码和客户端 ID。

我找到了使用托管身份的最后一个选项。我觉得这是更可靠的方式,所以 far.No 在代码或 keyvault 中秘密。这是我的全部理解,我的结论是第三种方式更可靠,我正在尝试通过整个应用程序实施。所以我想知道我所有的理解都是正确的,我可以摆脱前两种方法而采用第三种方法,它没有任何问题吗?有人可以帮助我理解我的正确理解,或者如果我以错误的方式理解事物,那么有人可以帮助我设计最佳实践吗?任何帮助将不胜感激。非常感谢

尽可能使用 managed identities as they allow you to access azure resource withouth having to expose secrets. An early blog post 微软声明:

Your code needs credentials to authenticate to cloud services, but you want to limit the visibility of those credentials as much as possible. Ideally, they never appear on a developer’s workstation or get checked-in to source control. Azure Key Vault can store credentials securely so they aren’t in your code, but to retrieve them you need to authenticate to Azure Key Vault. To authenticate to Key Vault, you need a credential! A classic bootstrap problem. Through the magic of Azure and Azure AD, MSI provides a “bootstrap identity” that makes it much simpler to get things started.

Here 是支持服务的概述。如您所见,大多数服务都支持托管身份。

Here 是一个分步教程,向您展示如何使用托管标识连接到 Azure 存储。