-
Notifications
You must be signed in to change notification settings - Fork 190
VaultPropertySource additonal property transformers #958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
VaultPropertySource additonal property transformers #958
Conversation
Signed-off-by: l.makhnorylov <[email protected]>
| * Specify additional property transformer classes | ||
| * {@link org.springframework.vault.core.util.PropertyTransformer}. | ||
| */ | ||
| Class<? extends PropertyTransformer>[] propertyTransformers() default {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introducing another flavor of property transformation creates ambiguity and takes away the simplicity of use. We have property-prefixing in place and we don't want to give up on simplicity.
The huge benefit of the current design approach is that all property transformations are visible from just looking at the annotation. Any other transformers require navigation and indirection.
Instead, I suggest exploring a design towards annotation-based property mapping. Admittedly, @VaultProperties(mapping = {@PropertyMapping(from="password", to="spring.datasource.password")} reads rather clunky, but that is still a direction worth exploring. Maybe you want to explore textblocks or other syntactical variants so that we come to a design that is simple and allows for addressing your use-case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mp911de i liked the approach with @PropertyMapping as annotation parameter, also i came up with idea of specitying an array of strings, where each 2 items is pair of from-to property names. But i like the variant with @PropertyMapping more
@VaultProperties(mapping = { "url", "spring.datasource.url", "user", "spring.datasource.username", "pwd", "spring.datasource.password" })
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mp911de implemented approach with @PropertyMapping
|
Because there are no tests showing the usage really, this pull request is really difficult to judge in terms of usability. Based on your contribution, here are usage examples of which the first one is based on the current changes while the subsequent ones are variants of various ideas:
@VaultPropertySource(value = "secret/myapp/config", propertyMappings = {
@PropertyMapping(from = "db.username", to = "spring.datasource.username"),
@PropertyMapping(from = "db.password", to = "spring.datasource.password")
})String-based property mappings: @VaultPropertySource(value = "secret/myapp/config", propertyMappings = {
"db.username=spring.datasource.username",
"db.password=spring.datasource.password"})
@VaultPropertySource(value = "secret/myapp/config"
propertyMappings = "username=spring.datasource.username,password=spring.datasource.password"
)External property file property mappings: @VaultPropertySource(
value = "secret/myapp/config",
mappings = "classpath:vault-mappings.properties"
)JSON-like property mappings: @VaultPropertySource(
value = "secret/myapp/config",
mappings = """
{
'spring.datasource.username': '${db.username}',
'spring.datasource.password': '${db.password}'
}
"""
) |
|
Circling back to Spring Cloud Vault (as there is quite elaborate support for property mapping): RequestedSecret rotating = RequestedSecret.rotating("secret/rotating");
PropertyNameTransformer transformer = new PropertyNameTransformer();
transformer.addKeyTransformation("db.username", "spring.datasource.username");
// …
configurer.add(RequestedSecret.rotating("database/mysql/creds/readonly"), transformer);What's the reason for you using |
|
I'd like to keep it declarative, as it supposed to be in Spring, instead of describing secrets in code. My pull request enhances annotation based approach with feature of custom prop name mapping. |
|
Approach with @PropertyMapping is the most elegant in my opinion. |
|
|
|
Configuration is initialized before the context is started as configuration is required to control bean registrations. Here's the documentation showing how to configure Spring Vault through the config data API: https://docs.spring.io/spring-cloud-vault/reference/secret-backends.html#vault.config.backends.configurer |
|
I did as specified in documentation, there are issues:
Could you suggest something? |
|
Good catch about |
|
Sorry, can't make it work. Did as you suggested in last comment, my VaultConfigurer is not called anyways.
My use case is renewable secret |
|
The constructor exception is part of why I see the appetite for annotation-based configuration of Vault property sources with Spring Boot applications, maybe that's an angle we should spend a bit more time on and consider how such an arrangement could be enabled with the config data API. However, configuration class parsing happens after Config Data is loaded so this cycle currently doesn't allow for a simple solution. |
No description provided.