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

时间:2017-02-10 22:40:49

标签: java spring spring-cloud spring-cloud-config

我一直在修改Spring Cloud Config,但有一个用例,配置属性分为两种类型:

  1. 非秘密值,开发人员应该能够查看和维护(例如JDBC URL'等)

  2. 秘密值,只有具有特殊访问权限的指定人员(例如密码)才能查看和维护

  3. 所以我对#34; 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"
                }
            }
        ]
    }
    

    如果我撤销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一起使用,并且有一条注释警告您所有repos应包含相同的标签(例如master)。我想知道这是否是问题,因为Vault的标签总是null

1 个答案:

答案 0 :(得分:3)

我相信您的依赖项肯定存在问题。我还设置了一个带有git和vault的spring cloud配置服务器,它运行得很好。 我认为强制使用1.3.0-BUILD.SNAPSHOT是不够的。 Spring cloud config 1.3.0-BUILD.SNAPSHOT依赖于spring-vault-core。您可能会错过此依赖项。这可能会导致您在其中一条评论中提到的bean创建失败。 以下是a link到git和vault的示例项目。请随意查看。