![](/img/trans.png)
[英]Spring Cloud Config Server with Zookeeper or HashiCorp Vault Backend
[英]Spring cloud server not accessing all profiles from Vault backend
我是 HashiCorp Vault 的新手,并设置了 Spring Cloud 配置服务器,将 Vault 作为存储秘密、密钥等的后端。
问题是我能够访问存储在默认级别的机密,例如:
curl -X "GET" "http://localhost:8888/myapp/default" -H "X-Config-Token: XXX"
但是,我无法访问存储在 Vault 中的个人资料特定机密。 无论我将机密存储在哪个配置文件中,API 始终返回默认值而不是配置文件特定值。
例如:
curl -X "GET" "http://localhost:8888/myapp/prod" -H "X-Config-Token: XXX"
这是我存储在 Vault 开发实例上的秘密(1.1.3 版):
1. vault kv put secret/myapp foo=myappsdefault
2. vault kv put secret/myapp/prod foo=myappsprod
Spring 云配置服务器 application.yml:
spring:
profiles:
active: vault
cloud.config.server.vault.kvVersion: 2
server:
port: 8888
Spring 云服务器 pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
<relativePath/>
</parent>
<properties>
<spring-cloud.version>Finchley.SR2</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
预期的:
curl -X "GET" "http://localhost:8888/myapp/prod" -H "X-Config-Token: XXX"
{
"name": "myapp",
"profiles": [
"prod"
],
"label": null,
"version": null,
"state": null,
"propertySources": [
{
"name": "vault:myapp",
"source": {
"foo": "myappsprod"
}
}
],
}
实际的:
{
"name": "myapp",
"profiles": [
"prod"
],
"label": null,
"version": null,
"state": null,
"propertySources": [
{
"name": "vault:myapp",
"source": {
"foo": "myappsdefault"
}
}
],
}
以下是保管库输出:
vault kv get secret/myapp/prod
=== Data ===
Key Value
--- -----
foo myappsprod
vault kv get secret/myapp
=== Data ===
Key Value
--- -----
foo myappsdefault
所以问题变成了为什么 spring 云服务器只查询默认配置文件机密而不是特定于环境的?
顺便提一下,这些配置文件被应用于我存储在 repo 中的 GIT 文件,同时将 Spring Cloud 服务器与 GIT 作为后端集成,我期待与 Vault 类似的东西。
经过与配置的挣扎。 我尝试在我的 application.yml 中添加其他属性,这对我有帮助。
application.yml 的快照:
server:
port: 8888
spring:
profiles:
active: vault
cloud:
config:
server:
vault:
port: 8200
host: 127.0.0.1
kvVersion: 1
backend: kv
profileSeparator: /
#skipSslValidation: true
#defaultKey: signing
management:
endpoints:
web:
exposure:
include: '*'
附加的事情是:1.我将后端从秘密更改为 kv(我的自定义秘密引擎) 2.配置文件分隔符为 /(在 .yml 中使用 /)
在我的情况下,'profileSeparator' 键起到了作用
这也不起作用,该应用程序始终返回默认配置文件输出。 这是 bootstrap.yaml
spring:
application:
name: myapp
cloud:
vault:
host: 127.0.0.1
port: 8200
scheme: http
token: ****
kvVersion: 2
backend: kv
profileSeparator: "/"
kv:
enabled: true
POM.xml 具有以下依赖项
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<spring.cloud-version>Hoxton.SR9</spring.cloud-version>
</properties>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-vault-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-vault-config</artifactId>
</dependency>
任何线索都会有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.