简体   繁体   中英

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

I have a record:

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

and an application.properties file:

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

and the binding works when I'm doing local development.

What I want to do is to use Azure services (Azure Spring Apps, Key Vault, etc.) and my question is whether I can, inside application.properties file, reference secrets stored in the Key Vault. Something like this:

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

Tutorials I've seen make me think that the only way to do the binding is by using @Value("${nameOfTheSecret}") annotation on fields in java classes. Is it possible to do it in a way that I want?

You can reference Azure Key Vault secrets inside the application.properties file by adding the below properties of azure key vault which you want to connect from the spring boot application:

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM