Spring Boot 2.4 introduced volume mounted configuration as a popular feature of kubernetes.
For example, you can declare the following in your application.properties:
spring.config.import=configtree:/etc/config
If you have the following mounted content:
etc/
+- config/
+- my/
| +- application
+- test
You end up with my.application and test properties in your Spring Environment.
Now I'm wondering what is the best approach regarding spring.datasource.password and spring.datasource.username and e.g. spring.something.else.password.
- Use
spring.config.import=configtree:/etc/secrets. Create two secrets, postgres-secret and another-secret, mount the first one to/etc/secrets/spring/datasourceand the second one to/etc/secrets/spring/something/else? - Use
spring.config.import=file:/etc/secrets/postgres.properties,file:/etc/secrets/somethingelse.properties, definingspring.datasource.passwordetc in it. So the whole .properties is base64 encoded as the secret. - Mount all secrets in
/etc/secrets/, making sure the filename matches the property name (spring.datasource.password). - Introduce a new property (e.g.
pg.password), using it inspring.datasource.passwordand do one of [1-3] for that (etc/secrets/pg/password,/etc/secrets/postgres.properties).
So basically, how can I best integrate e.g. db secret properties and other secret properties to be picked up by spring boot, while also keeping the configuration low. E.g. mapping secret password of secret pg-secret to map to /etc/secrets/spring/datasource/password is a lot to type for every single key in a secret.