問題描述
Springboot 集成azure keyvault 報錯,代碼參考的官方文檔:https://docs.microsoft.com/en-us/azure/developer/java/spring-framework/configure-spring-boot-starter-java-app-with-azure-key-vault搬瑰。 在運行時候款票,報錯: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.
問題解答
通常遇見 tenant not found問題,就是Azure的環(huán)境設(shè)置不對引起的泽论,因為參考的文檔為Global Azure的代碼艾少,所以在配置Key Vault信息的時候,默認指向的是Global的Azure環(huán)境翼悴。
如在文章中的 “Add Key Vault configuration” 部署缚够,只有 client-id, client-secret, endpoint, tenant 信息,沒有配置 cloud-type=AZURE_CHINA 的信息鹦赎,所以默認指向為Global Azure谍椅,所以存在China Azure中的Tenant當(dāng)然在Global Azure中是無法發(fā)現(xiàn)的。
解決辦法
在 src/main/resources/application.properties 配置文件中古话,添加 **spring.cloud.azure.keyvault.secret.property-sources[0].profile.cloud-type=AZURE_CHINA **
如下圖:
spring.cloud.azure.keyvault.secret.property-sources[0].credential.client-id=<your client ID>
spring.cloud.azure.keyvault.secret.property-sources[0].credential.client-secret=<your client key>
spring.cloud.azure.keyvault.secret.property-sources[0].endpoint=https://contosokv.vault.azure.cn/
spring.cloud.azure.keyvault.secret.property-sources[0].profile.tenant-id=<your tenant ID>
spring.cloud.azure.keyvault.secret.property-sources[0].profile.cloud-type=AZURE_CHINA
即可成功解決問題雏吭!
參考資料
Read a secret from Azure Key Vault in a Spring Boot application : https://learn.microsoft.com/en-us/azure/developer/java/spring-framework/configure-spring-boot-starter-java-app-with-azure-key-vault#add-key-vault-configuration-to-the-app
當(dāng)在復(fù)雜的環(huán)境中面臨問題,格物之道需:濁而靜之徐清陪踩,安以動之徐生杖们。 云中悉抵,恰是如此!
標(biāo)簽: AADSTS90002, AADSTS90002: Tenant 'xxxxxxxx-...' not found, src/main/resources/application.properties, spring.cloud.azure.keyvault.secret, property-sources[0].profile.cloud-type=AZURE_CHINA