天天看點

【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]….. 中,可以嘗試以下配置:

  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​​

繼續閱讀