有没有办法在Spring Boot应用程序配置中使用Spring Cloud {cipher}?

Bri*_*ton 13 spring-boot spring-cloud

我有一个使用Spring Cloud Config的Spring Boot应用程序,但我想在Spring Boot apps bootstrap.yml文件中加密Spring Cloud Config密码.有没有办法做到这一点?以下是一个例子.

Spring Boot应用程序bootstrap.yml

spring:
  cloud:
    config:
      uri: http://locahost:8888
      username: user
      password: '{cipher}encryptedpassword'
Run Code Online (Sandbox Code Playgroud)

Ken*_*ger 13

我发现了一些与此有关的事情.

如果使用bootstrap.yml(或application.yml),则密文的格式必须用单引号括起来:

security.user.password: '{cipher}56e611ce4a99ffd99908d2c9aa1461d831722812e4370a5b6900b7ea680ae914'  
Run Code Online (Sandbox Code Playgroud)

如果使用bootstrap.properties(或application.properties),则不得包含密文的格式:

security.user.password= {cipher}56e611ce4a99ffd99908d2c9aa1461d831722812e4370a5b6900b7ea680ae914
Run Code Online (Sandbox Code Playgroud)

[参考文档] [1]显示没有引号的yml,我从来没有工作过.SnakeYaml总是报错:

"expected <block end>, but found Scalar"
Run Code Online (Sandbox Code Playgroud)


Dav*_*yer 9

在配置客户端中支持加密属性(如用户指南中所述).显然,如果你这样做,你必须提供一个密钥在运行时解密属性,所以实际上我并不总是看到好处(我想配置文件有点像一个特殊格式的密钥库,所以你只有一个秘密来保护而不是许多).示例(application.yml):

integration:
  stores:
    test: '{cipher}316f8cdbb776c23e679bf209014788a6eab7522f48f97114328c2c9388e6b3c1'
Run Code Online (Sandbox Code Playgroud)

和键(在bootstrap.yml中):

encrypt:
  key: ${ENCRYPT_KEY:} # deadbeef
Run Code Online (Sandbox Code Playgroud)


edu*_*oni 5

您可以使用 Spring CLI 来加密机密spring encrypt password --key 'SECRET_KEY'

https://cloud.spring.io/spring-cloud-cli/