简体   繁体   English

如何将Spring Cloud Config与Git and Vault复合环境存储库一起使用?

[英]How to use Spring Cloud Config with a Git and Vault composite environment repository?

I've been tinkering with Spring Cloud Config, but have a use case where config properties are divided into two types: 我一直在修改Spring Cloud Config,但是有一个用例,其中config属性分为两种类型:

  1. Non-secret values, which developers should be able to view and maintain (eg JDBC URL's, etc) 非秘密值,开发人员应能够查看和维护(例如JDBC URL等)

  2. Secret values, which should be viewed and maintained only by designated people with special access (eg passwords) 秘密值,只有具有特殊访问权限的指定人员才能查看和维护(例如密码)

So I'm very interested in the support for " Composite Environment Repositories ", currently available in the snapshot versions. 因此,我对快照版本中当前提供的对“ Composite Environment Repositories ”的支持非常感兴趣。 It seems like I would be able to use Git for the developer-managed properties, Vault for the secret properties, and configure it such that Vault would always take precedence over Git in the event of a conflict. 似乎我可以对开发人员管理的属性使用Git,对秘密属性使用Vault,并对其进行配置,以便在发生冲突时Vault始终优先于Git。

However, I'm finding that not only does Vault always take precedence... it's being used as the exclusive backend. 但是,我发现Vault不仅总是优先考虑……它还被用作独家后端。 No properties from Git are returned at all. Git的任何属性都不会返回。

My application.yml looks like this: 我的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

I have written a property to Vault like this: 我已经像这样将属性写入保险柜:

vault write secret/foo foo=vault

And I am calling my config server like this: 我这样调用我的配置服务器:

curl -X "GET" "http://127.0.0.1:8888/foo/default" -H "X-Config-Token: a9384085-f048-7c99-ebd7-e607840bc24e"

However, the JSON response payload only includes the Vault property. 但是,JSON响应有效负载仅包含Vault属性。 Nothing from Git: Git一无所有:

{
    "name": "foo",
    "profiles": [
        "default"
    ],
    "label": null,
    "version": null,
    "state": null,
    "propertySources": [
        {
            "name": "vault:foo",
            "source": {
                "foo": "vault"
            }
        }
    ]
}

It doesn't matter if I reverse the order settings in application.yml , to give Git higher priority than Vault. 是否颠倒application.ymlorder设置以赋予Git比Vault更高的优先级并不重要。 As long as the Vault profile is active, it acts as the exclusive backend. 只要保管库配置文件处于活动状态,它就可以用作专有后端。

However, if I deactivate the vault profile, then the same curl operation does return results from the Git backend: 但是,如果我停用了保管库配置文件,则相同的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"
            }
        }
    ]
}

Is there anything I could be missing? 我有什么想念的吗? Some reason why the Git properties and Vault properties don't... well, "composite" together? 为什么Git属性和Vault属性不...好吧,“复合”在一起?

The only example in the documentation shows Git and Subversion being used together, and there's a note warning you that all repos should contain the same label (eg master ). 文档中唯一的示例显示了Git和Subversion一起使用,并且有一条注释警告您所有存储库都应包含相同的标签(例如master )。 I'm wondering if that's the issue, as the label is always null for Vault. 我想知道这是否是问题,因为保险柜的标签始终为null

I believe there must be something wrong with your dependencies. 我相信您的依赖项一定有问题。 I also set up a spring cloud config server with git and vault which works just fine. 我还用git和Vault设置了一个Spring Cloud配置服务器,它工作得很好。 I think forcing usage of 1.3.0-BUILD.SNAPSHOT is not enough. 我认为强制使用1.3.0-BUILD.SNAPSHOT是不够的。 Spring cloud config 1.3.0-BUILD.SNAPSHOT depends on spring-vault-core. Spring cloud config 1.3.0-BUILD.SNAPSHOT取决于spring-vault-core。 You might be missing this dependency. 您可能缺少此依赖性。 And that might be causing the failing bean creation that you mentioned in one of your comments. 这可能会导致您在注释之一中提到的bean创建失败。 Here is a link to a sample project with git and vault. 这是带有git和Vault的示例项目的链接 Feel free to check it out. 随时检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM