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

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

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

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

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

所以我对“Composite Environment Repositories”的支持非常感兴趣,目前在快照版本中可用。似乎我可以将 Git 用于开发人员管理的属性,将 Vault 用于 secret 属性,并对其进行配置,以便在发生冲突时 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 配置文件处于 Activity 状态,它就会充当独占后端。

但是,如果我停用保管库配置文件,则相同的 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)。我想知道这是否是问题所在,因为 Vault 的标签始终为 null

最佳答案

我相信你的依赖关系一定有问题。我还使用 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 的示例项目。请随时查看。

关于java - 如何将 Spring Cloud Config 与 Git 和 Vault 复合环境存储库一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42169804/

相关文章:

Java 正则表达式帮助 : Splitting String on spaces, "=>"和逗号

spring - Spring Integration Kafka 消费者的回滚偏移量

java - @PreDestroy 没有被调用以用于 Runnable

spring - 配置服务器配置无效

spring - 请求 'OPTIONS/logout'与'POST/logout不匹配

java - 将 spring-cloud 版本从 Camden.SR4 升级到 Camden.SR5 后,调度程序没有订阅者错误

java - Eclipse 代码格式化程序不适用于 Java 泛型代码?

java - 如何在SignatureChecker的verifyMessageSignature方法中提取publicKey属性

Java Android 在 FrameLayout 中创建 View

java - Spring Custom Validator - 使用参数插入消息