将 Vault 与 Spring 云配置服务器集成时,不会从 Vault 中读取属性

Properties are not read from Vault on Integrating Vault with Spring Cloud Config Server

我正在尝试将 Spring 引导配置服务器与 git 和保管库一起使用,我所有的 spring 引导客户端应用程序将通过传递保管库配置通过配置服务器检索保管库属性令牌。

我正在使用 spring 引导 2.1。8.RELEASE 以下是我的 spring 引导配置服务器的 POM.xml 文件。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.8.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.ps.psc</groupId>
<artifactId>psc-config-server</artifactId>
<version>0.0.1</version>
<name>psc-config-server</name>
<description>Spring configuration server</description>

<properties>
    <java.version>1.8</java.version>
    <spring-cloud.version>Greenwich.SR2</spring-cloud.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-bus-amqp</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-vault-config</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-monitor</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-configuration-processor</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

bootstrap.yml 文件

spring:
  profiles:
    active:
    - git
    - vault
  cloud:
    config:
      enabled: true
      server:
        git:
          order: 2
          username: ********
          password: ********
          uri: https://*******@bitbucket.org/krushna/configuration.git
          search-paths:
          - payment*
        vault:
          host: 127.0.0.1
          port: 8200
          scheme: http
          order: 1
          skip-ssl-validation: true
          kv-version: 1
    vault:
      authentication: TOKEN
      token: s.PB5cAJ9WhOuWamIOuFVkzpbl
      scheme: http
      host: 127.0.0.1
      port: 8200
      config:
        order: 1

我的application.yml文件

server:
 port: 7000
spring:
  application:
  name: configserver

通过上述配置,我的配置服务器只能从 GIT 中读取属性,而不是从保险库中读取属性。

我在保险库中编写了如下属性。

vault write secret/payment password=test@123

如果我像下面这样进行 curl 调用

curl -X "GET" "http://127.0.0.1:7000/payment/default" -H "X-Config-Token: s.PB5cAJ9WhOuWamIOuFVkzpbl"

我只从 git 获取属性,请在下方回复。

{
"name": "payment",
"profiles": ["default"],
"label": null,
"version": "e9b941d22f6b7cd3083a731d168f78fa4ec0fc42",
"state": null,
"propertySources": [{
    "name": "https://******@bitbucket.org/krushna/configuration.git/application.properties",
    "source": {
        "foofromGit": "bar"
    }
}]
}

我在这里做什么?我尝试了多个选项,例如不同的 KV 版本,仅配置 spring cloude config vault 等

编辑:

我使用了如下的 vault conf。

backend "file" {
    path = "vault"
}
listener "tcp" {
    tls_disable = 1
}

并直接卷曲到 vault 我现在可以读取值了。

curl -X GET -H "X-Vault-Token:s.PB5cAJ9WhOuWamIOuFVkzpbl" http://127.0.0.1:8200/v1/secret/payment/

回复:

{
    "request_id": "35c8793e-3530-81c1-7917-3e922ef4065b",
    "lease_id": "",
    "renewable": false,
    "lease_duration": 2764800,
    "data": {
        "password": "test@123"
    },
    "wrap_info": null,
    "warnings": null,
    "auth": null
}

我可以通过将 git 和 spring cloude config vault 配置详细信息从 bootstrap.yml 移动到 application.yml 来解决问题,如下所示。

bootstrap.yml

spring:
  application:
    name: configserver
  cloud:
    vault:
      authentication: TOKEN
      token: s.jyFarEyroi5pJNOxPnhT4f3D
      scheme: http
      host: 127.0.0.1
      port: 8200
      config:
        order: 1

Application.yml

server:
  port: 7000
spring:
  profiles:
    active: git, vault
  cloud:
    config:
      server:
        git:
          uri: https://krushna@bitbucket.org/krushna/configuration.git
          search-paths:
          - payment*
        vault:
          port: 8200
          host: 127.0.01
          skip-ssl-validation: true
          scheme: http

我仍然不清楚这是如何解决问题的?我只知道 bootstrap 会先加载,我正在从保管库读取 git 凭证,然后 application.yml 有 spring 云配置库和 git 的其他详细信息。

非常欢迎对此进行任何解释