Spring boot - 如何解密yaml文件中的环境变量?

问题描述 投票:0回答:1

背景

我有 Spring Boot 应用程序。我向它传递这样的变量:

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

挑战

这个环境变量可以很容易地读取,因为它们是纯文本的。 我想通过对称加密来提高安全性。

我正在寻找可以在我的 yaml 文件中使用的东西。

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

加密的唯一要求是易于从 shell(gitlab 管道)进行加密

问题

如果可以的话,这个spring boot或者spring怎么做?

spring-boot spring-security
1个回答
0
投票

查看 jasypt,它为 Spring Boot 应用程序中的属性源提供加密支持:

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

© www.soinside.com 2019 - 2024. All rights reserved.