繁体   English   中英

Spring Cloud Config 不解密配置服务器密码

[英]Spring Cloud Config not decrypting the config server password

我在 Spring Cloud Config 上工作了一段时间。 我有保护配置数据的要求。 根据 Spring Cloud 文档,已经配置了 server.jks 并添加到类路径中。 现在我能够加密和解密远程配置数据。

为了使配置服务器安全,我添加了 spring 安全启动器并分配了凭据(密码解密)。 出于某种原因,应用程序抛出异常,认为它在类路径上没有密钥存储。 在谷歌搜索一段时间后,我发现密钥库应该转到 bootstrap.yml 而不是 application.yml。 这也不起作用,请指出我在这里缺少什么。

请在 git SpringConfigData 中找到 yml 文件

例外

java.lang.IllegalStateException: Cannot decrypt: key=security.user.password
    at org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializer.decrypt(EnvironmentDecryptApplicationInitializer.java:195) ~[spring-cloud-context-1.1.0.BUILD-SNAPSHOT.jar:1.1.0.BUILD-SNAPSHOT]
    at org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializer.decrypt(EnvironmentDecryptApplicationInitializer.java:164) ~[spring-cloud-context-1.1.0.BUILD-SNAPSHOT.jar:1.1.0.BUILD-SNAPSHOT]
    at org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializer.initialize(EnvironmentDecryptApplicationInitializer.java:94) ~[spring-cloud-context-1.1.0.BUILD-SNAPSHOT.jar:1.1.0.BUILD-SNAPSHOT]
    at org.springframework.cloud.bootstrap.BootstrapApplicationListener$DelegatingEnvironmentDecryptApplicationInitializer.initialize(BootstrapApplicationListener.java:333) ~[spring-cloud-context-1.1.0.BUILD-SNAPSHOT.jar:1.1.0.BUILD-SNAPSHOT]
    at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:640) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:343) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
    at com.test.TestConfigServerApplication.main(TestConfigServerApplication.java:12) [classes/:na]
Caused by: java.lang.UnsupportedOperationException: No decryption for FailsafeTextEncryptor. Did you configure the keystore correctly?
    at org.springframework.cloud.bootstrap.encrypt.EncryptionBootstrapConfiguration$FailsafeTextEncryptor.decrypt(EncryptionBootstrapConfiguration.java:151) ~[spring-cloud-context-1.1.0.BUILD-SNAPSHOT.jar:1.1.0.BUILD-SNAPSHOT]
    at org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializer.decrypt(EnvironmentDecryptApplicationInitializer.java:187) ~[spring-cloud-context-1.1.0.BUILD-SNAPSHOT.jar:1.1.0.BUILD-SNAPSHOT]
    ... 9 common frames omitted

我遇到过这个问题。 要设置在春季云的最新版本对称加密,你只需要设置encrypt.keybootstap.yml与所需的关键属性(或的.properties)(建议设置键作为OS环境变量,引用文件中的变量。这是为了更安全

但是,正如您发现引导程序文件中的属性不再导入。 您必须将以下依赖项添加到 pom 文件中才能加载该文件中的属性:

<dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

完成此操作后,一切都会顺利进行。

而不是使用环境变量传递的 bootstrap.yml。

-Dencrypt.keyStore.location=classpath:/server.jks -Dencrypt.keyStore.password=springcloudconfigserver -Dencrypt.keyStore.alias=springcloudconfigserver -Dencrypt.keyStore.secret=springcloudconfigserver

配置服务器无法在 bootstrap.yml 中找到非对称安全性的属性。 对称工作得很好

<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-rsa -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-rsa</artifactId>
        <version>1.0.8.RELEASE</version>
    </dependency>

我在配置客户端面临同样的问题。 为了解决这个问题,我在 pom.xml 和 bootstarp.properties/bootstrap.yml 文件中添加了这个依赖项,我在使用对称加密时添加了 encrypt.key 属性。

希望能帮助到你。

我遇到此错误是因为我的应用程序在服务器中使用本地 bootstrap.yml 而不是云配置。 这就是它无法解密并且失败的原因。

确保本地 bootstrap.yml 有这个 prop,它指示使用 config.uri 从服务器读取配置:

spring.cloud.config.enabled: true

简单的答案是将所有属性从 bootstrap.properties 移动到 application.yaml

当我在IntelliJ IDEA 中运行项目并具有以下项目结构时,我遇到了这个问题:

.
├── config
│   └── application.yaml
├── api-users
│   ├── pom.xml
│   └── src
└── config-server
    ├── pom.xml
    └── src

项目在启动的时候也用到了config/application.yaml这个文件,这就是出现这个错误的原因。

config目录重命名为configuration ,这个问题就解决了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM