簡體   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