阅读背景:

Spring Cloud Config Server - 在哪里设置encrypt.key以启用/加密端点

来源:互联网 

I have a Spring Cloud Config app with the Spring Cloud Security dependencies. I'm trying to hit the /encrypt endpoint to encrypt a password.

我有一个Spring Cloud Config应用程序和Spring Cloud Security依赖项。我正试图点击/ encrypt端点来加密密码。

According to the docs at https://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_key_management I believe I need to set a symmetric key using "encrypt.key". But I can't figure out where to put this; all combinations I've tried result in {"description":"No key was installed for encryption service","status":"NO_KEY"} when I attempt to POST to /encrypt.

根据https://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_key_management上的文档,我认为我需要使用“encrypt.key”设置对称密钥。但我无法弄清楚在哪里放这个;我试过的所有组合导致{“description”:“没有为加密服务安装密钥”,“status”:“NO_KEY”}当我尝试POST /加密时。

If I POST a key to /key, the /encrypt works perfectly, so I'm pretty sure that everything else is setup correctly. It also works fine using the environment variable ENCRYPT_KEY, or by using a system property encrypt.key. I just can't figure out where to place the encrypt.key within a configuration file. Is there a sample on this?

如果我将一个密钥发送到/ key,/ encrypt可以正常工作,所以我很确定其他所有内容都已正确设置。它也可以使用环境变量ENCRYPT_KEY或使用系统属性encrypt.key正常工作。我只是无法弄清楚将encrypt.key放在配置文件中的位置。这有样品吗?

4 个解决方案

#1


Thanks @pVilaca, this is indeed what the documentation says, but setting the key in application.properties or application.yml won't work.

感谢@pVilaca,这确实是文档所说的,但是在application.properties或application.yml中设置密钥将不起作用。

Through experimentation I've found that the only place you can set the encrypt.key property is an ENCRYPT_KEY environment variable, a system property, bootstrap.properties, bootstrap.yml, or calling the /key endpoint.

通过实验,我发现你可以设置encrypt.key属性的唯一地方是ENCRYPT_KEY环境变量,系统属性,bootstrap.properties,bootstrap.yml或调用/ key端点。

Not sure why application.properties or application.yml don't work in this case. Setting this key must have more of an impact on the startup process than it would appear.

不确定为什么application.properties或application.yml在这种情况下不起作用。设置此密钥必须对启动过程产生比对其更大的影响。

#2


Setting Spring Cloud Version to 'Brixton.SR5' worked for me. For some reason, setting 'encrypt.key' in either application.properties/yml or bootstrap.properties/yml in later Spring Cloud Version does not work anymore.

将Spring Cloud Version设置为'Brixton.SR5'对我有用。出于某种原因,在以后的Spring Cloud Version中的application.properties/yml或bootstrap.properties / mysl中设置'encrypt.key'不再有效。

#3


check properties tag of pom.xml file. If you are using version 2 or 3 of Dalston, change it to:

检查pom.xml文件的属性标记。如果您使用的是Dalston的第2版或第3版,请将其更改为:

<spring-cloud.version>Dalston.SR1</spring-cloud.version>

and it should be working fine. In my case i was using version 3 and changing it to version 1 resolved the issue for me.

它应该工作正常。在我的情况下,我使用版本3并将其更改为版本1解决了我的问题。

Reference: https://github.com/spring-cloud/spring-cloud-config/issues/767

#4


If you're using spring cloud with spring boot, that is the method that is described on the documentation that you mentioned, you've two 'main' properties files.

如果你使用spring spring和spring boot,那就是你提到的文档中描述的方法,你有两个'主'属性文件。

  • bootstrap.[properties,yml]

    To modify the startup behaviour you can change the location of the config server using bootstrap.properties (like application.properties but for the bootstrap phase of an application context)

    要修改启动行为,可以使用bootstrap.properties更改配置服务器的位置(如application.properties,但适用于应用程序上下文的引导阶段)

  • application.[properties,yml]

    where the "application" is injected as the "spring.config.name" in the SpringApplication (i.e. what is normally "application" in a regular Spring Boot app)

    其中“应用程序”作为SpringApplication中的“spring.config.name”注入(即常规Spring Boot应用程序中通常为“application”)

source: Spring Cloud Config Documentation

来源:Spring Cloud Config文档

So, it should be enough to set the encrypt.keyin your application.[properties,yml] file (or the alternative name if specified)

因此,在应用程序中设置encrypt.key应该足够了。[properties,yml]文件(如果指定了替代名称)


分享到: