Search code examples
spring-bootspring-security

Spring boot - how to decrypt env variables in yaml file?


Context

I got spring boot app. I'm passing to it variables like this:

    ...
      datasource:
          url: jdbc:postgresql://${DB_SERVER_AND_PORT}/my_db
          username: ${DB_USER}
          password: ${DB_USER_PASSWORD}

Challenge

This env variables can be easily read because they are in plain text. I want to increase security with symmetric encryption.

I looking for something that I can use in my yaml file.

    # example how I want to use it:
    ...
     datasource:
          url: jdbc:postgresql://#{decrypt(${DB_SERVER_AND_PORT}}/my_db
          

The only requirement for encryption is ease of doing it from shell (gitlab pipeline)

Question

If this is possible, how to do this spring boot or spring?


Solution

  • Check out jasypt which provides encryption support for property sources in Spring Boot Applications:

    https://github.com/ulisesbocchio/jasypt-spring-boot