簡體   English   中英

您可以參考 application.properties 中的 Azure Key Vault 機密嗎?

[英]Can you reference Azure Key Vault secrets inside application.properties?

我有一個記錄:

@ConfigurationProperties("service.api")
@ConstructorBinding
public record ServiceApiConfig(String clientId, String clientSecret) {}

和一個 application.properties 文件:

service.api.client_id=client_id
service.api.client_secret=client_secret

當我進行本地開發時,綁定有效。

我想做的是使用 Azure 服務(Azure Spring 應用程序、Key Vault 等),我的問題是我是否可以在 application.properties 文件中引用存儲在 Key Vault 中的機密。 像這樣的東西:

service.api.client_id=<name-of-the-id-kept-in-the-vault>
service.api.client_secret=<name-of-the-secret-kept-in-the-vault>

我看過的教程讓我認為進行綁定的唯一方法是在 java 類中的字段上使用@Value("${nameOfTheSecret}")注釋。 是否有可能以我想要的方式做到這一點?

您可以在application.properties文件中引用 Azure Key Vault 機密,方法是添加要從 Z2A2D595E6ED9A0B24F027F2B63B134 引導應用程序連接的 azure 密鑰庫的以下屬性:

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.net/
spring.cloud.azure.keyvault.secret.property-sources[0].profile.tenant-id=<your tenant ID>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM