c# - 尝试连接时来自 Azure Vault 的 GetSecret 抛出 NullReferenceException
问题描述
我有以下问题:
我正在尝试使用证书凭据连接到 Azure Vault。
当试图阅读一个秘密时,我得到AuthenticationFailedException
一个内部的NullReferenceException
.
为简洁起见,我只包括 NullReferenceException 的堆栈跟踪:
This exception was originally thrown at this call stack:
Azure.Identity.AadIdentityClient.CreateClientAssertionJWT(string, string, System.Security.Cryptography.X509Certificates.X509Certificate2)
Azure.Identity.AadIdentityClient.CreateClientCertificateAuthRequest(string, string, System.Security.Cryptography.X509Certificates.X509Certificate2, string[])
Azure.Identity.AadIdentityClient.Authenticate(string, string, System.Security.Cryptography.X509Certificates.X509Certificate2, string[], System.Threading.CancellationToken)
Azure.Identity.ClientCertificateCredential.GetToken(Azure.Core.TokenRequestContext, System.Threading.CancellationToken)
编码:
string keyVaultUrl = "https://somevault.vault.azure.net/";
var clientId = "<Application (client) ID>";
var tenantId = "<Directory (tenant) ID>";
X509Certificate2 clientCertificate = new X509Certificate2(@"someCerFile.cer");
ClientCertificateCredential certificateCreadential = new ClientCertificateCredential(tenantId, clientId, clientCertificate);
var client = new SecretClient(new Uri(keyVaultUrl), certificateCreadential);
var secret = client.GetSecret("Password"); //This line throws the exception
保险库配置是根据此处概述的步骤完成的:
https://docs.microsoft.com/en-us/azure/key-vault/general/authentication
有任何想法吗?
解决方案
不幸的是,这个例外不是很有帮助。但是,我相信这里的问题是您需要给 X509Certificate2 提供私钥,以便ClientCertificateCredential
可以签署客户端断言。该.cer
文件只是证书的公共部分。您将需要提供一个.pfx
包含证书和私钥的文件。
推荐阅读
- node.js - 错误 ts(2322) 试图在 Typescript 中定义通用函数签名
- soundcloud - Soundcloud - 回调弹出窗口未关闭
- python - Python:如何以堆叠/分层的方式绘制一系列区域?
- python - Python中集合的pop()的时间复杂度是多少?
- angular - 使用 ngif 进行 Angular 表单验证
- tmux - 如何在 tmux 绑定键映射中使用 env 变量?
- amazon-ecs - ECS容器在健康检查中发送404状态码
- swiftui - matchGeometryEffect 不适用于 PageTabView
- html - HTML5 中的 void 元素是否允许结束标记?
- r - 使用 R 中的 apply() 函数查找 2 个矩阵的每一行的加权特征