【发布时间】:2017-06-29 10:00:08
【问题描述】:
我一直在修改 Spring Cloud Config,但是有一个用例,其中配置属性分为两种类型:
开发人员应该能够查看和维护的非机密值(例如 JDBC URL 等)
秘密值,只能由具有特殊访问权限(例如密码)的指定人员查看和维护
所以我对“Composite Environment Repositories”的支持非常感兴趣,目前在快照版本中可用。似乎我可以将 Git 用于开发人员管理的属性,将 Vault 用于秘密属性,并对其进行配置,以便在发生冲突时 Vault 始终优先于 Git。
但是,我发现 Vault 不仅始终具有优先权……它还被用作独家后端。根本不返回来自 Git 的属性。
我的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"
}
}
]
}
如果我反转application.yml 中的order 设置,让Git 比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 一起使用,并且有一个注释警告您所有 repos 应该包含相同的标签(例如master)。我想知道这是否是问题所在,因为 Vault 的标签始终为 null。
【问题讨论】:
-
嗨,史蒂夫,感谢您的报告。下个礼拜我会看看这个。
-
你用的是什么版本的Spring Cloud?我刚试过这个,得到了这个,它对我有用。
-
1.2.3(快照)。我刚刚在github.com/spring-cloud-samples/configserver 修改了示例项目
-
当我尝试强制将
1.3.0-BUILD.SNAPSHOT用于spring-cloud-config-server时,启动失败,因为lib-internal 类EnvironmentRepositoryConfiguration$VaultConfiguration无法创建Spring beanvalutEnvironmentRepository(肯定是错字错误!) . -
我想知道 Maven POM 是否也必须从
Camden.BUILD-SNAPSHOT提升spring-cloud-dependencies的版本。如果您有一个使用任何依赖项组合的示例,那么 Maven 或 Gradle 脚本的副本将不胜感激!
标签: java spring spring-cloud spring-cloud-config