Spring Config Server:使用特定路径从Vault获取机密

问题描述

我正在尝试从连接到两个源的配置服务器获取我的微服务配置:git和Vault(用于秘密)。我有下面的配置: 在配置服务器中:

server:
  port: 8888

spring:
  profiles:
    active: git,vault
  cloud:
    config:
      server:
        vault:
          port: 8200
          host: 127.0.0.1
          kvVersion: 2
        git:
          order: 2
          uri: git@gitlab.git

并在bootstrap.yml的客户端中:

spring:
  application:
    name: my-service-name

  cloud:
    config:
      uri: http://localhost:8888
      token: //token
      label: dev

但是在我的保险库中,我的路径是这样的:

secret/cad
     |--my-service-name

当我直接在/secret/my-service-name中创建秘密时,我可以访问我的秘密,但是如何在/secret/cad/my-service-name

中配置对秘密的访问权限

谢谢。

解决方法

您可以创建实现VaultConfigurer的自定义配置类,在其中可以覆盖自定义路径

@配置 公共类CustomVaultConfiguraton实现VaultConfigurer {

 @override
 public void addSecretsBackends(SecretBackendConfigurer configures){

 configures.add("customPath");

} }

在spring.factories中添加上述配置类 org.springframework.cloud.bootstrap.BootstrapConfiguration = \ packagename.CustomVaultConfiguration

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...