带有k2 v2的Spring Cloud Vault-如何在启动时避免403?

时间:2019-03-18 16:36:07

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

问题

有人知道如何配置bootstrap.yml来告诉Spring Cloud Vault转到k2 v2的正确路径,而不先尝试其他路径吗?

详细信息

我可以成功地连接到运行k2 v2的保管库,但是Spring Cloud将始终尝试连接到保管库中不存在的路径,并在启动时抛出403。

Status 403 Forbidden [secret/application]: permission denied; nested exception is org.springframework.web.client.HttpClientErrorException$Forbidden: 403 Forbidden

上面的路径secret/application不存在,因为k2 v2将data放在路径中。例如:secret/data/application

这不是停止显示的方法,因为Spring Cloud Vault 确实会检查其他路径,包括路径中带有data项的正确路径,但事实是毫无意义的403在启动过程中抛出的东西就像是我脑海中的碎片。

最终,它会尝试正确的k2 v2路径

2019-03-18 12:22:46.611  INFO 77685 --- [  restartedMain] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='vault', propertySources=[LeaseAwareVaultPropertySource {name='secret/data/my-app'}

我的配置

    spring.cloud.vault:
      kv:
        enabled: true
        backend: secret
        profile-separator: '/'
        default-context: my-app
        application-name: my-app
      host: localhost
      port: 8200
      scheme: http
      authentication: TOKEN
      token: my-crazy-long-token-string

感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

在bootstrap.yml中添加以下行,这将禁用通用后端

spring.cloud.vault:
  generic:
    enabled: false

有关更多信息,https://cloud.spring.io/spring-cloud-vault/reference/html/#vault.config.backends.generic

答案 1 :(得分:0)

除了已接受的答案之外,关闭(或仅删除)fail-fast 选项也很重要:

spring.cloud.vault:
  fail-fast: false