We also provide spring-cloud-azure-starter-keyvault to support all the features of Key Vault. If you choose to use it, spring.cloud.azure.keyvault.enable is the property to configure and the default value is true. You can then use spring.cloud.azure.keyvault.<keyvault-service>.enable to disable unneeded services.
Basic usage
If you want to authenticate by client-id and client-secret, the following properties are required:
. isn't supported in secret names. If your application has a property name that contains ., such as spring.datasource.url, replace . with - when saving the secret in Azure Key Vault. For example, save spring-datasource-url in Azure Key Vault. In your application, you can still use spring.datasource.url to retrieve the property value.
Napomena
This method cannot satisfy a requirement like spring.datasource-url. When you save spring-datasource-url in Key Vault, only spring.datasource.url and spring-datasource-url is supported to retrieve the property value, but spring.datasource-url isn't supported. To handle this case, see the Use property placeholders section.
Use property placeholders
For example, suppose you're setting this property in your application.properties file:
If you stored 1000 secrets in the Key Vault, and you just want to use 3 of them. You can list the 3 secret names by spring.cloud.azure.keyvault.secret.property-sources[].secret-keys.
Setting refresh interval
By default, the secrets in KeyVaultPropertySource will refresh every 30 minutes. You can configure the time by spring.cloud.azure.keyvault.secret.property-sources[].refresh-interval. For example: spring.cloud.azure.keyvault.secret.property-sources[].refresh-interval=60m means refresh every 60 minutes. Set to 0 to disable auto refresh.
PropertySource priority
If key exists in multiple PropertySources, which will take effect is decided by the priority.
If there is no SystemEnvironmentPropertySource in the PropertySource list, then KeyVaultPropertySource will take the highest priority.
If there is SystemEnvironmentPropertySource in the PropertySource list, then SystemEnvironmentPropertySource have higher priority than KeyVaultPropertySource, which means you can use an environment variable to override the Key Vault secret value in your application.
If there are multiple key vault property sources in the PropertySource list, then the definition order is the priority order. Taking the above sample as an example, key-vault-property-source-1 has a higher priority than key-vault-property-source-2.
Configure token credential for Key Vault property source
If you need to use a specified token credential for Key Vault PropertySource, you can register the TokenCredential bean in the ConfigurableBootstrapContext for KeyVaultEnvironmentPostProcessor, this feature is supported from Spring Cloud Azure 5.20.1. Here is an example to use AzureCliCredential:
Java
publicstaticvoidmain(String[] args){
SpringApplication application = new SpringApplication(PropertySourceApplication.class);
application.addBootstrapRegistryInitializer(registry ->
registry.register(TokenCredential.class, context -> new AzureCliCredentialBuilder().build()));
application.run(args);
}
If common properties like client, credential, profile, proxy, retry aren't configured in spring.cloud.azure.keyvault.secret.property-sources[].xxx, spring.cloud.azure.xxx will be used. See Spring Cloud Azure configuration to get more information about these common properties.
Pridružite se seriji susreta kako biste s kolegama programerima i stručnjacima izgradili skalabilna rješenja umjetne inteligencije temeljena na stvarnim slučajevima upotrebe.