【Azure Spring Cloud】Spring Cloud Azure 4.0 调用Key Vault遇见认证错误 AADSTS90002: Tenant not found. - LuBu0505/My-Code GitHub Wiki

问题描述

Spring Cloud Azure 4.0 调用 Key Vault 的代码中,没有找到设置 authority-host 的配置项,导致认证出现错误

Caused by: com.microsoft.aad.msal4j.MsalServiceException: AADSTS90002: Tenant 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' not found. Check to make sure you have the correct tenant ID and are signing into the correct cloud. Check with your subscription administrator, this may happen if there are no active subscriptions for the tenant. Trace ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Correlation ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

问题解释

以上错误是在参考文档“从 azure-spring-boot-starter-keyvault-secrets 到 spring-cloud-azure-starter-keyvault-secrets” 完成迁移后,无法访问 Key Vault 了. 提示 Tenant_id 无效, 可能登入的不正确的 Cloud. 因为在迁移前,登录的为中国区Azure AAD,而修改后,因为没有找到指定 authority-host 为 https://login.partner.microsoftonline.cn 的配置项,所以默认的认证host变为 Global Azure,所以提示Tenant Id 无效。

解决方式

Azure Spring 4.0中对于China Azure做了很多配置项,可以在全局指定,也可以在服务中指定。

如果在 spring.cloud.azure.keyvault.secret.property-source[n]….. 中,可以尝试以下配置:

  1. spring.cloud.azure.keyvault.profile.cloud-type: azure_china
  2. spring.cloud.azure.keyvault.secret.profile.environment.active-directory-endpoint: https://login.partner.microsoftonline.cn

参考资料

4.0 迁移指南 : https://learn.microsoft.com/zh-cn/azure/developer/java/spring-framework/spring-cloud-azure-appendix#migration-guide-for-40

自 3.10.x 起的 4.0 中的新增功能 : https://learn.microsoft.com/zh-cn/azure/developer/java/spring-framework/spring-cloud-azure?tabs=maven#whats-new-in-40-since-310x 

azure-spring-boot-starter-keyvault-secrets 到 spring-cloud-azure-starter-keyvault-secrets : https://learn.microsoft.com/zh-cn/azure/developer/java/spring-framework/spring-cloud-azure-appendix#sdk-configuration-changes-3

当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!

分类: 【Azure Spring Cloud】

标签: Azure Key VaultAzure Spring CloudSpring Cloud Azure 4.0AADSTS90002: Tenant not found.