【问题标题】:Creating Azure Key Vault using .NET assembly (Microsoft.Azure.KeyVault)使用 .NET 程序集 (Microsoft.Azure.KeyVault) 创建 Azure Key Vault
【发布时间】:2016-05-19 11:19:36
【问题描述】:

我正在编写一个 .Net 控制台应用程序来创建 Key Vault,但无法在 Microsoft.Azure.KeyVault 程序集中找到允许创建 Vault 并将服务主体设置到该 Vault 的类/方法。

谁能指点我可以用来创建保险库的程序集/类。

谢谢

【问题讨论】:

    标签: azure azure-keyvault


    【解决方案1】:

    您要查找的类是 Microsoft.Azure.Management.KeyVault 命名空间中的 KeyVaultManagementClient。这是在您可以从 NuGet 获得的管理 KeyVault 程序集中定义的。

    执行此操作的代码的主要部分如下所示。但是,请注意,我已经缩写了一些您必须进一步定义和初始化的内容(属性、订阅凭据等)。如果您想查看完整的解决方案,请查看 .NET Azure SDK 中的示例,尤其是 KeyVaultManagement.Tests 项目。

            // The resource group to create the vault in.
            const string resourceGroupName = "Vaults-Resource-Group";
    
            // The name of the vault to create.
            const string vaultName = "web-app-01-vault";
    
            // Define access policies to keys and secrets (abbreviated just to illustrate...)
            var accessPolicy = new AccessPolicyEntry
            {
                ApplicationId = sp, 
                PermissionsToKeys = new string[] { "all" }, 
                PermissionsToSecrets = new string[] { "backup", "create", "delete" } //etc.  just to name a few
            };
    
            // Define vault properties (abbreviated just to illustrate...)
            VaultProperties vaultProps = new VaultProperties()
            {
                EnabledForTemplateDeployment = true,
                AccessPolicies = new List<AccessPolicyEntry>()
                {
                    accessPolicy
                }
            };
    
            // Initialize 'create parameters' to create the vault in "West US"
            VaultCreateOrUpdateParameters vaultParams = new VaultCreateOrUpdateParameters(vaultProps, "westus");
    
            // Initialize an instance to the mgmt client
            // NOTE: Need to initialize creds derived from SubscriptionCloudCredentials
            KeyVaultManagementClient mgmtClient = new KeyVaultManagementClient(creds);
    
            // Create the vault
            mgmtClient.Vaults.CreateOrUpdateAsync(resourceGroupName, vaultName, vaultParams);
    

    【讨论】:

    【解决方案2】:

    由于某种原因,客户端 SDK 中没有此类功能(或者,至少,即使通过 SDK 的 Github 存储库中放置的代码,我也无法找到该功能)。 REST API 用于创建/更新密钥保管库,因此您可以使用它来创建它。或者 PowerShell - 可以执行 Powershell from C# 并且我尝试这样做 - 它可以工作,但应该进行测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-16
      • 2023-01-16
      • 1970-01-01
      • 2018-05-22
      • 1970-01-01
      • 2021-10-13
      • 2020-05-23
      • 2020-05-04
      相关资源
      最近更新 更多