【问题标题】:Spring Cloud Config (Vault backend) teminating too earlySpring Cloud Config(Vault 后端)过早终止
【发布时间】:2017-08-11 23:57:00
【问题描述】:

我正在使用 Spring Cloud Config Server 为我的客户端应用程序提供配置。为了方便秘密配置,我使用 HashiCorp Vault 作为后端。对于其余的配置,我使用的是 GIT 存储库。所以我已经在复合模式下配置了配置服务器。在下面查看我的配置服务器bootstrap.yml:-

server:
    port: 8888

spring:
    profiles:
        active: local, git, vault

    application:
        name: my-domain-configuration-server

    cloud:
        config:
            server:
                git:
                    uri: https://mygit/my-domain-configuration
                    order: 1
                vault:
                    order: 2
                    host: vault.mydomain.com
                    port: 8200
                    scheme: https
                    backend: mymount/generic

这一切都按预期工作。但是,我使用的令牌是受 Vault 身份验证策略保护的。见下文:-

{
    "rules": "path "mymount/generic/myapp-app,local" {
                  policy = "read"
              }

              path "mymount/generic/myapp-app,local/*" {
                  policy = "read"
              }

              path "mymount/generic/myapp-app" {
                  policy = "read"
              }

              path "mymount/generic/myapp-app/*" {
                  policy = "read"
              }

              path "mymount/generic/application,local" {
                  policy = "read"
              }

              path "mymount/generic/application,local/*" {
                  policy = "read"
              }

              path "mymount/generic/application" {
                  policy = "read"
              }

              path "mymount/generic/application/*" {
                  policy = "read"
              }"
}

我的问题是我没有在所有这些范围内存储秘密。我需要指定所有这些路径,以便我可以授权令牌从mymount/generic/myapp-app,local 读取一个秘密。如果我不授权所有其他路径,VaultEnvironmentRepository.read() 方法将返回 403 HTTP 状态代码(禁止)并抛出 VaultException。这会导致完全无法检索应用程序的任何配置,包括基于 GIT 的配置。这是非常有限的,因为客户端应用程序可能有多个与检索配置项无关的 Spring 配置文件。问题是配置服务器将尝试检索客户端提供的所有活动配置文件的配置。

有没有办法在配置服务器上启用容错或宽容,以便 VaultEnvironmentRepository 不会中止并返回它实际授权返回的任何配置?

【问题讨论】:

    标签: spring-cloud-config hashicorp-vault spring-cloud-vault-config


    【解决方案1】:

    您绝对需要本地配置文件吗?您是否无法仅使用 Config Server 中的“vault”和“git”配置文件并在每个 Spring Boot 应用程序中使用“默认”配置文件?

    如果您使用上述建议,那么您在规则 (.hcl) 文件中需要的唯一两个路径是:

    path "mymount/generic/application" {
      capabilities = ["read", "list"]
    }
    

    path "mymount/generic/myapp-app" {
      capabilities = ["read", "list"]
    }
    

    这假设您正在将配置写入

    vault write mymount/generic/myapp-app
    

    而不是

    vault write mymount/generic/myapp-app,local
    

    或类似的。

    【讨论】:

    • 同意,即便如此,我的问题说明如果我添加任何未在 Vault 中配置的配置文件,问题仍然存在。我需要一种机制来允许我使用未在 Vault 中配置的配置文件。 “本地”配置文件仅用于此处的说明。
    猜你喜欢
    • 2018-01-12
    • 2022-01-08
    • 1970-01-01
    • 2016-12-22
    • 1970-01-01
    • 2018-12-19
    • 2018-05-21
    • 2018-07-25
    • 2017-06-23
    相关资源
    最近更新 更多