我一直在修改Spring Cloud Config,但是有一个用例,其中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 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的权限并不重要。只要保管库配置文件处于活动状态,它就可以用作专有后端。
但是,如果我停用了保管库配置文件,则相同的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
用于保险柜。
我相信您的依赖项一定有问题。我还用git和Vault设置了一个Spring Cloud配置服务器,它工作得很好。我认为强制使用1.3.0-BUILD.SNAPSHOT是不够的。Spring cloud config 1.3.0-BUILD.SNAPSHOT取决于spring-vault-core。您可能缺少此依赖性。这可能会导致您在注释之一中提到的bean创建失败。这是带有git和Vault的示例项目的链接。随时检查。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句