简体   繁体   English

仅使用计算机上安装的证书访问 Azure KeyVault 机密

[英]Accessing Azure KeyVault secrets only with a certificate installed on the machine

I use the following code to access my Azure KeyVault我使用以下代码访问我的 Azure KeyVault

public static string GetKeyVaultSecret(string keyVaultName, string secretName)
{
    string secret = "";
    string secretUrl = $"https://{keyVaultName}.vault.azure.net/secrets/{secretName}";
    AzureServiceTokenProvider azureServiceTokenProvider = new AzureServiceTokenProvider();
    var keyVaultClient = new KeyVaultClient(
        new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));
    Task.Run(async () => {
        var secretObject = await keyVaultClient.GetSecretAsync(secretUrl).ConfigureAwait(false);
        secret = secretObject.Value;
    }).GetAwaiter().GetResult();
    return secret;
}

This works perfectly when I am logged in under my account.当我在我的帐户下登录时,这非常有效。 But of a login as a service account I get the error:但是作为服务帐户登录时,我收到错误消息:

Parameters: Connection String: [No connection string specified], Resource:
https://vault.azure.net, Authority: https://login.windows.net/5a47d63b-1b7e-4d2d-9333-750184dcbc99. 
Exception Message: Tried to get token using Active Directory Integrated Authentication.
 Access token could not be acquired. unknown_user_type: Unknown User Type

I would like only the certificate to be used to authenticate and authorize access to the KeyVault and not in addition any Azure Active Directory account我只想使用证书来验证和授权对 KeyVault 的访问,而不是任何 Azure Active Directory 帐户

You'll need to set a connection string environment variable that points to the certificate and can be read by the application.您需要设置一个指向证书并且可由应用程序读取的连接字符串环境变量。

在此处输入图片说明

This is taken from https://docs.microsoft.com/en-us/dotnet/api/overview/azure/service-to-service-authentication#use-a-certificate-in-local-keystore-to-sign-into-azure-ad这取自https://docs.microsoft.com/en-us/dotnet/api/overview/azure/service-to-service-authentication#use-a-certificate-in-local-keystore-to-sign-天蓝色广告

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 ASP.NET 核心应用程序访问 Azure KeyVault 中的证书 - Accessing certificate in Azure KeyVault from ASP.NET Core app 在本地环境中访问 Azure KeyVault - Accessing Azure KeyVault in Local Environment 使用 KeyVault 机密覆盖 Azure 应用服务中和本地的应用设置 - Using KeyVault secrets to override appsettings in Azure App Service and locally 有没有办法将证书从 azure 密钥库导入 azure web 应用程序中的 Z303CB0EF5825EDB9082DAZ61? - Is there a way to import certificate from azure keyvault to azure web app in .NET? 使用 Azure.Security.KeyVault 通过 SecretId / SecretIdentifier 而不是 Microsoft.Azure.KeyVault 检索证书(PFXcontent) - Using Azure.Security.KeyVault to retrieve certificate (PFXcontent) via SecretId / SecretIdentifier instead of Microsoft.Azure.KeyVault 从Azure KeyVault加载X509证书 - Loading X509Certificate from Azure KeyVault 为旧版安全令牌服务访问 Azure KeyVault 中的证书 - Accessing Certificates in Azure KeyVault for Legacy Security Token Service VS2022 配置 Azure keyvault 看不到本地 secrets.json - VS2022 Configure Azure keyvault not seeing local secrets.json Asp.Net MVC 5 - 如何实现 Azure.Security.KeyVault.Secrets 代码 - Asp.Net MVC 5 - how to Implement Azure.Security.KeyVault.Secrets code 使用 Azure KeyVault 和 Visual Studio 管理用户机密不适用于 ASP .Net Core - Managing User Secrets with Azure KeyVault and Visual Studio not working for ASP .Net Core
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM