【发布时间】:2022-02-23 20:12:05
【问题描述】:
我在 azure 中创建了一个密钥保管库并存储了机密和证书。我正在使用托管身份访问密钥保管库。从我使用 java 的 Azure VM 我可以使用
从密钥库中获取秘密使用下面的代码,我能够正确地获取秘密。
SecretClient secretClient = new SecretClientBuilder()
.httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))
.vaultUrl("https://testkeyvault.vault.azure.net/")
.credential(new ManagedIdentityCredentialBuilder().build()).buildClient();
KeyVaultSecret keyVaultSecret = secretClient.getSecret("test-secret");
System.out.println(keyVaultSecret.getName());
但是当我尝试使用以下代码获取证书时 -
CertificateClient certificateClient = new CertificateClientBuilder()
.httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))
.vaultUrl("https://testkeyvault.vault.azure.net/")
.credential(new ManagedIdentityCredentialBuilder().build()).buildClient();
KeyVaultCertificateWithPolicy certificate = certificateClient.getCertificate("test-cert");
我得到了例外 -
[main] ERROR com.azure.core.credential.SimpleTokenCache - Failed to acquire a new access token.
[parallel-2] ERROR com.azure.core.credential.SimpleTokenCache - Failed to acquire a new access token.
[parallel-4] ERROR com.azure.core.credential.SimpleTokenCache - Failed to acquire a new access token.
[parallel-6] ERROR com.azure.core.credential.SimpleTokenCache - Failed to acquire a new access token.
[parallel-6] WARN com.azure.security.keyvault.certificates.CertificateAsyncClient - Failed to Retrieve the certificate - test-cert
Max retries 3 times exceeded. Error Details: To convert to a resource string the specified array must be exactly length 1
在 keyvault 访问策略中,我已授予所有权限,包括获取此 VM 的机密和证书的权限。但是获取秘密效果很好,而不是证书。有人可以在这里帮助我吗?
【问题讨论】:
-
您是否检查过 Keyvault 的访问策略。如果您有权在访问策略中获取证书?在我看来,你很可能没有权限。
-
@Jatin 我已经为证书添加了密钥保管库访问中的所有权限。
标签: java azure azure-keyvault