我一直在修改 Spring Cloud Config,但有一个用例,其中配置属性分为两种类型:
非秘密值,开发人员应该能够查看和维护(例如 JDBC URL 等)
秘密值,只能由具有特殊访问权限的指定人员查看和维护(例如密码)
所以我对支持“复合环境存储库”,目前在快照版本中可用。似乎我可以使用 Git 作为开发人员管理的属性,使用 Vault 作为秘密属性,并对其进行配置,以便在发生冲突时 Vault 始终优先于 Git 。
然而,我发现 Vault 不仅总是优先......它被用作独家的后端。根本不返回任何来自 Git 的属性。
My application.yml
看起来像这样:
spring:
profiles:
active: git, vault
cloud:
config:
server:
vault:
order: 1
git:
uri: https://github.com/spring-cloud-samples/config-repo
basedir: target/config
order: 2
我已经向 Vault 写入了一个属性,如下所示:
vault write secret/foo foo=vault
我这样调用我的配置服务器:
curl -X "GET" "http://127.0.0.1:8888/foo/default" -H "X-Config-Token: a9384085-f048-7c99-ebd7-e607840bc24e"
但是,JSON 响应负载仅包含 Vault 属性。 Git 没有任何内容:
{
"name": "foo",
"profiles": [
"default"
],
"label": null,
"version": null,
"state": null,
"propertySources": [
{
"name": "vault:foo",
"source": {
"foo": "vault"
}
}
]
}
如果我反转也没关系order
设置在application.yml
,给予 Git 比 Vault 更高的优先级。只要 Vault 配置文件处于活动状态,它就会充当独占后端。
但是,如果我停用 Vault 配置文件,则相同的 curl 操作会从 Git 后端返回结果:
{
"name": "foo",
"profiles": [
"default"
],
"label": "master",
"version": "30f5f4a144dba41e23575ebe46369222b7cbc90d",
"state": null,
"propertySources": [
{
"name": "https://github.com/spring-cloud-samples/config-repo/foo.properties",
"source": {
"democonfigclient.message": "hello spring io",
"foo": "from foo props"
}
},
{
"name": "https://github.com/spring-cloud-samples/config-repo/application.yml",
"source": {
"info.description": "Spring Cloud Samples",
"info.url": "https://github.com/spring-cloud-samples",
"eureka.client.serviceUrl.defaultZone": "http://localhost:8761/eureka/",
"foo": "from-default"
}
}
]
}
有什么我可能会错过的吗?为什么 Git 属性和 Vault 属性不……嗯,“复合”在一起的某些原因?
文档中唯一的示例显示了 Git 和 Subversion 一起使用,并且有一条注释警告您所有存储库应包含相同的标签(例如master
)。我想知道这是否是问题所在,因为标签总是null
对于避难所。