【Azure Spring Cloud】Spring Cloud Azure 4.0 调用Key Vault遇见认证错误 AADSTS90002: Tenant not found.
问题描述
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]….. 中,可以尝试以下配置:
- spring.cloud.azure.keyvault.profile.cloud-type: azure_china
- 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当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2021-10-20 【Azure Developer】如何验证 Azure AD的JWT Token (JSON Web 令牌)?
2020-10-20 【应用服务 App Service】App Service发生错误请求时,如何查看IIS Freb日志,从中得知错误所发生的模块,请求中所携带的Header信息