【问题标题】:Is there a way a spring cloud config client can decrypt cipher text fetched from a config server?春天云配置客户端有没有办法解密从配置服务器获取的密文?
【发布时间】:2016-02-02 23:34:29
【问题描述】:

我们的配置服务器相对不安全,只有少数客户端需要加密属性。理想情况下,我们希望服务器只有公钥,每个客户端都可以使用私钥进行解密。麻烦的是,默认情况下,配置服务器总是会尝试为你解密密文。为了防止这种情况,我禁用了这样的默认行为:

@SpringBootApplication(exclude = EncryptionAutoConfiguration.class)
@EnableConfigServer
public class ConfigServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class, args);
    }
}

现在,当客户端应用程序从配置服务器获取属性时,它会得到如下内容:

      "source": {
        "username": foobar,
        "password": "{cipher}CiBNmK+y3ZLsXHVgaJMAiuNyLQo3p0e..."
      }

我已经实现了一个 TextEncrypter bean 并对其进行了测试以确保它在客户端上正常工作。在客户端应用程序启动时,我希望 EnvironmentDecryptApplicationInitializer 类能够处理客户端的本地引导和应用程序属性以及从配置服务器获取的属性。但是我看到只考虑客户端的本地文件。如果我的密文出现在本地bootstrap.yml 中,那么它会被正确解密。但是,如果密文来自配置服务器,则不会被解密。有没有办法包含从配置服务器获取的属性?

【问题讨论】:

  • 我想是的。你用的是什么版本?
  • 我们使用的是 spring-boot 1.2.6 和 spring-cloud-config 1.0.3。如果可能的话,我们更愿意使用发布版本。

标签: spring-boot spring-cloud


【解决方案1】:

这实际上非常简单。根据这个问题:

https://github.com/spring-cloud/spring-cloud-config/issues/365

您所要做的就是像配置云配置服务器一样配置云配置客户端。这意味着,如果您使用的是对称加密,您所要做的就是

1.) 将以下内容添加到 Spring Cloud Config Server 上的 application.properties 中,以便服务器在发送到客户端之前不会解密属性:

spring.cloud.config.server.encrypt.enabled=false

2.) 在 Spring Cloud Config Client 上,您只需将加密密钥添加到 bootstrap.properties 文件:

encrypt.key=supersecretpassword

就是这样。当客户端读取这些属性时,它们将被解密。

对于非对称加密,我假设您可以通过将对称密钥属性添加到客户端上的 bootstrap.properties 文件中来执行完全相同的操作:

encrypt.keyStore.location:classpath:/server.jks
encrypt.keyStore.password:letmein
encrypt.keyStore.alias:mytestkey
encrypt.keyStore.secret:changeme

【讨论】:

  • 比我预期的要容易得多......很好的答案!效果很好
【解决方案2】:

我们放弃了客户端解密。相反,我们使用了默认行为……配置服务器解密密码。为了安全起见,我们将配置服务器放在一个特殊的安全组 (aws) 中,并强制服务器仅通过 https 进行通信。

【讨论】:

    【解决方案3】:

    如果您想再试一次,我们可以让它工作。

    在配置服务器上:

    spring.cloud.config.server.encrypt.enabled=false
    

    在客户端,我们使用spring-cloud-config-aws-kms。这样我们就可以为每个服务授权一个可以访问密钥的角色。如果您想做其他事情,上面的项目显示了需要什么。

    【讨论】:

    • 我正在对自己的 EnvironmentDecryptApplicationInitializer bean 和 TextEncryptor 实现进行一些试验。启动时,客户端应用程序可以使用 TextEncryptor 成功读取和解密密文,但由于某种原因,它再次尝试使用 EncryptionBootstrapConfiguration 解密属性,但失败了。你做了什么来禁用这种行为吗?'
    猜你喜欢
    • 2017-01-08
    • 2019-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-17
    • 2018-01-22
    • 2018-08-23
    • 2022-09-29
    相关资源
    最近更新 更多