首页 > 解决方案 > 使用 DataProtectionProvider 连接到 Azure Key Vault

问题描述

我花了很多时间配置 .Net Core 的 DataProtectionProvider 以将密钥存储在 Azure Key Vault 中。问题是我似乎无法创建正确的 Blob URI,或者至少我认为这是问题所在,因为其他一切似乎都井然有序,但我仍然未经授权。

在 Azure 中,我注册了一个应用程序和客户端密码,创建了一个保管库和一个密钥,以及一个几乎为应用程序提供所有权限的访问策略。

这是我的 ConfigureServices 的相关部分:

        string uri = "https://{vault-name}.vault.azure.net/keys/{vault-name}/{key}" + "se=2020-01-01&sp=r&spr=https&sv=2018-11-09&sr=b&sig={sig}";
        string keyIdentifier = "https://{vault-name}.vault.azure.net/keys/{vault-name}";
        string clientId = "{application-id";
        string clientSecret = "{client-secret}";

        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
        services.AddDataProtection()
            .PersistKeysToAzureBlobStorage(new Uri(uri)) // requires Microsoft.AspNetCore.DataProtection.AzureStorage
            .ProtectKeysWithAzureKeyVault(keyIdentifier, clientId, clientSecret); //requires Microsoft.AspNetCore.DataProtection.AzureKeyVault
        services.AddControllers();

我对如何生成 sas 很感兴趣。该文档似乎暗示这与存储帐户有关,但我看不到任何将存储帐户与密钥保管库相关联的明显方法。因此,我从 Azure CLI 尝试了一些不同的方法,但似乎没有任何东西可以通过我过去的身份验证。

任何帮助将非常感激。

标签: azureasp.net-coreazure-keyvault

解决方案


It looks like you are trying to pass the uri for Key Vault to .PeristKeysToAzureBlobStorage(). Instead you need to pass the uri for the blob in storage that is going to hold the key ring. This is noted in the doc for the Azure Storage provider.

You can generate the SAS link through the portal as pictured or you can utilize the CLI to create the link.

enter image description here


推荐阅读