0

How can my spring boot application running inside a container access docker secrets mounted as a volume inside that same container?

Commonly suggested methods I DO NOT want to use:

  • Echo the secret into an environment variable - this is insecure.
  • Pass the secret in as a command line argument - this is messy with multiple secrets and hurts the local dev experience
  • Manually read the secret from a file by implementing my own property loader - Spring must have a native way to do this
stewartie4
  • 190
  • 1
  • 8

1 Answers1

3

Spring boot 2.4 introduced this feature as part of Volume mounted config trees using the spring.config.import property.
To read docker secrets mounted as a volume from the default location set:

spring.config.import = configtree:/run/secrets/

The property name will be derived from the secret filename and the value from the file contents. This can then be accessed like any other spring property.

stewartie4
  • 190
  • 1
  • 8