我在上工作了一段时间。我需要保护配置数据的安全。根据Spring文档,我已经配置了server.jks并添加到类路径中。现在我能够加密和解密远程配置数据。
为了确保配置服务器的安全性,我添加了并分配了凭据(密码已解密)。由于某些原因,应用程序正在抛出在类路径上没有密钥存储的异常。在搜索了一段时间之后,我发现密钥存储应该转到bootstrap.yml而不是application.yml。这也没用,我在这里错过了什么?
您可以在GitHub: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发布于 2021-03-19 12:16:14
我遇到了这个问题。要在最新版本的spring中设置对称加密,只需使用所需的密钥在bootstap.yml(或.properties)中设置bootstap.yml属性(建议将密钥设置为OS环境变量并在文件中引用该变量。这是为了更多的安全)
但是,正如您发现的,引导文件中的属性不再导入。必须将以下依赖项添加到pom文件中,以便加载该文件中的属性:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>做完这件事后,每件事都会顺利进行。
发布于 2019-09-12 07:15:03
<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属性。
希望能帮上忙。
发布于 2016-03-23 18:30:34
而不是使用环境变量传递bootstrap.yml。
-Dencrypt.keyStore.location=classpath:/server.jks-Dencrypt.keyStore.password=springcloudconfigserver-Dencrypt.keyStore.alias=springcloudconfigserver-Dencrypt.keyStore.secret=springcloudconfigserver由于安全性不对称,Config Server无法在bootstrap.yml中定位这些属性。对称的作品很好
https://stackoverflow.com/questions/35938714
复制相似问题