简体   繁体   English

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

[英]Spring Cloud Config Server - Where to set encrypt.key to enable /encrypt endpoint

I have a Spring Cloud Config app with the Spring Cloud Security dependencies. 我有一个Spring Cloud Config应用程序和Spring Cloud Security依赖项。 I'm trying to hit the /encrypt endpoint to encrypt a password. 我正试图点击/ encrypt端点来加密密码。

According to the docs at http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_key_management I believe I need to set a symmetric key using "encrypt.key". 根据http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_key_management上的文档,我认为我需要使用“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. 我试过的所有组合导致{“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. 如果我将一个密钥发送到/ key,/ encrypt可以正常工作,所以我很确定其他所有内容都已正确设置。 It also works fine using the environment variable ENCRYPT_KEY, or by using a system property encrypt.key. 它也可以使用环境变量ENCRYPT_KEY或使用系统属性encrypt.key正常工作。 I just can't figure out where to place the encrypt.key within a configuration file. 我只是无法弄清楚将encrypt.key放在配置文件中的位置。 Is there a sample on this? 这有样品吗?

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. 不确定为什么application.properties或application.yml在这种情况下不起作用。 Setting this key must have more of an impact on the startup process than it would appear. 设置此密钥必须对启动过程产生比对其更大的影响。

Setting Spring Cloud Version to 'Brixton.SR5' worked for me. 将Spring Cloud Version设置为'Brixton.SR5'对我有用。 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中的application.properties/yml或bootstrap.properties / mysl中设置'encrypt.key'不再有效。

check properties tag of pom.xml file. 检查pom.xml文件的属性标记。 If you are using version 2 or 3 of Dalston, change it to: 如果您使用的是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 参考: https//github.com/spring-cloud/spring-cloud-config/issues/767

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] 自举。[特性,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] 应用程序。[特性,YML]

    where the "application" is injected as the "spring.config.name" in the SpringApplication (ie 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.key in your application.[properties,yml] file (or the alternative name if specified) 因此,在应用程序中设置encrypt.key应该足够了。[properties,yml]文件(如果指定了替代名称)

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

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