[英]Spring Cloud Config Server with Zookeeper or HashiCorp Vault Backend
[英]Configuring Spring Cloud Config Server and Spring Cloud Vault for production
我正在尝试设置由Spring Cloud Vault秘密管理支持的Spring Cloud Config Server。 我是Spring的新手,但我尝试过按照以下说明和示例进行操作:-
http://cloud.spring.io/spring-cloud-vault-config/
只要您遵循保管库端点的默认设置(如http,localhost和8200)并使用tls_disable = 1关闭SSL,一切都可以正常工作。 但是,对于任何实际环境而言,这些设置都不是实际的设置,并且在任何地方都很少有有助于此目的的示例。 任何人都可以提供工作示例的帮助吗?
我已使用TLS启用成功设置了保管库。 我已经成功设置了使用自签名证书进行连接的配置服务器。 我什至可以将一个秘密值注入配置服务器,并通过@Value
和@PostConstruct
公开它。
所有这些都在起作用。 但是,当我尝试利用Spring Conig端点访问保管库时,得到以下信息:
{
"timestamp": 1486413850574,
"status": 500,
"error": "Internal Server Error",
"exception": "org.springframework.web.client.ResourceAccessException",
"message": "I/O error on GET request for \"http://127.0.0.1:8200/v1/secret/myapp\": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect",
"path": "/myapp/default"
}
即使我在bootstrap.yml
设置了覆盖,配置服务器仍使用默认值。
server:
port: 8888
spring:
profiles:
active: vault
spring.cloud.vault:
host: myhost.mydomain.com
port: 8200
scheme: https
authentication: TOKEN
token: 0f1887c3-d8a8-befd-a5a2-01e4e066c50
ssl:
trust-store: configTrustStore.jks
trust-store-password: changeit
如您所见,它应该指向myhost.mydomain.com而不是127.0.0.1,并且应该使用https而不是http作为协议方案。
我不确定为什么它在配置服务器端点上使用这些默认值,但是在Spring Cloud Vault启动期间使用正确的设置。 我正在使用Spring Dalsten.M1和Spring Cloud Vault 1.0.0.M1的所有最新稳定版本。 我意识到这些都是里程碑式的发布。 我也尝试过卡姆登(Camden)和布里克斯顿(Brixton)的连击,没有运气。 如果需要,我可以提供代码。
任何帮助,不胜感激。
正如我在对spensergibb的回复中提到的那样,我自己已经解决了一些问题。 根据他的评论,我将澄清我的意图,因为这将有助于对该问题的共识。 我正在尝试做两件事:
站起来使用Vault作为后端(与默认的GIT后端相反)的配置服务器,并将Vault API公开给客户端应用程序(通过TLS),以便它们可以检索自己的机密。 我不希望我的所有客户端应用程序都直接连接到Vault。 我希望他们通过使配置服务器连接到保险柜,从配置服务器获取配置。 直到昨晚,我才能实现此目标,除非我将所有设置都设置为默认设置,并且禁用TLS并使用回送地址,Vault软件的端口8200等。显然,默认设置对我们所有已部署环境都不适用。 我会提到spencergibb发布的链接确实帮助我理解了为什么它不起作用,但是原因的微妙之处是我以前错过了它的原因。 请继续阅读以获取我的解释。
我希望配置服务器直接从Vault配置自身。 也就是说,通过Spring Cloud Vault Config连接到Vault。 如文档中所述,这对我立即起作用。 但是,这个目标有些微不足道,因为目前我没有实际的用例。 但是我想了解是否可以完成此操作,因为我没有真正理由不这样做,这似乎是集成Vault的良好第一步。
这两种功能之间的区别使我理解问题出在以下事实:Spring Cloud Config Server和Spring Cloud Vault似乎正在使用两个不同的bean注入Vault配置属性。 Spring Cloud Config Server使用带有@ConfigurationProperties(“ spring.cloud.config.server.vault”)注释的VaultEnvironmentRepository,而Spring Cloud Vault使用带有@ConfigurationProperties(“ spring.cloud.vault”)注释的VaultProperties。
这导致我向引导yml添加了两个不同的配置。
server:
port: 8888
spring:
profiles:
active: local, vault
application:
name: quoting-domain-configuration-server
cloud:
vault:
host: VDDP03P-49A26EF.lm.lmig.com
port: 8200
scheme: https
authentication: TOKEN
token: 0f1997c3-d8a8-befd-a5a2-01e4e066c50a
ssl:
trust-store: configTrustStore.jks
trust-store-password: changeit
config:
server:
vault:
host: VDDP03P-49A26EF.lm.lmig.com
port: 8200
scheme: https
authentication: TOKEN
token: 0f1997c3-d8a8-befd-a5a2-01e4e066c50a
请注意相同的配置详细信息。 只是不同的yml路径。 考虑到我首先要使目标编号1开始工作并假定相同的配置对两个目标都适用,所以这是我错过的一个细微之处。 (注意:令牌和密码是伪造的)。
除了SSL握手错误外,这几乎可以工作。 如您所见,在spring.cloud.config.server.vault路径上没有设置SSL属性。 VaultProperties bean不支持它们。 我不确定如何处理(也许是我找不到的另一个非Vault特定的bean)。 我的解决方案是像这样简单地强制自己配置证书:
@SpringBootApplication
@EnableConfigServer
public class Application
{
public static void main(String[] args)
{
System.setProperty("javax.net.ssl.trustStore",
Application.class.getResource("/configTrustStore.jks").getFile());
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
SpringApplication.run(Application.class, args);
}
}
这个SSL解决方案非常难看。 我确信必须有更好的方法来完成这一部分。 因此,我愿意接受其他建议。 但是,一旦我完成上述所有步骤,便可以正常使用。
感谢您的来信。 我在努力工作。 我能够获得客户端服务以连接到Spring Cloud Config服务器和Vault服务器,但是我无法获得Spring Cloud Config服务器以连接到Vault服务器。
将您的配置复制到我的Spring Cloud Config服务器后,我什至感到挣扎。 当我最终将它与您的配置一起使用时,我可以将其削减很多。 关键是令牌不属于Spring Cloud Config服务器。 它属于客户端。
我在浏览器中尝试使用http://localhost:8888/{application}/default
,但得到以下信息:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu May 11 14:21:31 EDT 2017
There was an unexpected error (type=Bad Request, status=400).
Missing required header: X-Config-Token
我使用PostMan发送带有Vault令牌的X-Config-Token
标头发送请求,该请求有效。
这是我的最终配置。
server:
port: ${PORT:8888}
management:
context-path: /manage
security:
enabled: true
spring:
profiles:
active: git,vault
application:
name: config-server
cloud:
config:
server:
git:
order: 1
uri: file:///temp/config-server/config
vault:
order: 0
host: localhost
port: 8200
scheme: http
因此,看起来您需要将令牌添加到客户端。 也许使用spring.cloud.config.token
。
代替
@SpringBootApplication
@EnableConfigServer
public class Application
{
public static void main(String[] args)
{
System.setProperty("javax.net.ssl.trustStore",
Application.class.getResource("/configTrustStore.jks").getFile());
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
SpringApplication.run(Application.class, args);
}
}
写
bootstrap yml ->
javax.net.ssl.trustStore: /configTrustStore.jks
javax.net.ssl.trustStorePassword: changeit
虽然我迟到了。 但是我能够将Spring Cloud Config Server配置为使用Vault作为通过证书进行CERT身份验证的后端。 而且,您不需要在GET请求中发送X-Config-Token。 因此,您的配置服务器GET请求将以与GITHUB作为后端相同的方式工作。因为我的实现将即时获取令牌并通过附加标头更改传入的请求。 我建议检查我的教程和github存储库中的所有步骤。
这是我的教程: https : //medium.com/@java.developer.raman/enable-spring-config-server-to-use-cert-authentication-with-vault-as-back-end-ff84e1ef2de7?sk= 45a26d7f1277437d91a5cff3d5997287
和GitHub存储库: https : //github.com/java-developer-raman/config-server-vault-backend
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.