Skip to content

PropertySource to read a property's value from file #20842

Closed
@skuzzle

Description

@skuzzle

I want to use docker-swarm secrets in my Dockerized Spring-Boot application. These secrets are mounted as special files into the docker container: the secret text is accessible by reading the file at /run/secrets/<secret_name>. This is deemed best-practice in secret handling regarding containers (as opposed to injecting the secret text as environment variable, which isn't even supported by docker-swarm).

It would be great if Spring-Boot offered a way to set a property's value from the content of a file so I can write something like this:

spring.data.mongodb.password=${fileContent./var/run/secrets/mongo_db_password}

This would be similar to how RandomValuePropertySource works. Looking at its source it should be straight forward to provide a PropertySource implementation for reading file content. However, I wasn't able to properly inject my custom PropertySource into the Spring-Boot application start up process.

I also wonder if there might be already some spring magic that would allow to set a property's value from file?

If this is a valid feature request, I'd be happy to help out with a pull request and a PropertySource implementation thats handled similar to the RandomValuePropertySource. Otherwise it would be great to provide some information on how I could properly inject my PropertySource into the start up process.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions