无效的 Spring Config 服务器配置(Vault 作为后端)

问题描述 投票:0回答:2

我想创建一个带有保管库后端的配置服务器,并按照以下步骤操作:

  1. 安装保管库
  2. 使用以下命令创建并运行服务器:
storage "raft" {
  path    = "./vault/data"
  node_id = "node1"
}

listener "tcp" {
  address     = "127.0.0.1:8200"
  tls_disable = "true"
}

api_addr = "http://127.0.0.1:8200"
cluster_addr = "https://127.0.0.1:8201"
ui = true

  1. 检查服务器状态
Key                     Value
---                     -----
Seal Type               shamir
Initialized             true
Sealed                  false
Total Shares            5
Threshold               3
Version                 1.14.1
Build Date              2023-07-21T10:15:14Z
Storage Type            raft
Cluster Name            vault-cluster-d9454c69
Cluster ID              36c8d03f-522d-d9e9-4ae4-cceea7074298
HA Enabled              true
HA Cluster              https://127.0.0.1:8201
HA Mode                 active
Active Since            2023-08-08T09:12:40.45953Z
Raft Committed Index    40
Raft Applied Index      40

Vault 之前已通过 cli 命令解封。

  1. 设置 Spring 配置
server:
  port: 8888

spring:
  application:
    name: config-server
  cloud:
    config:
      server:
        vault:
          host: localhost
          port: 8200
          scheme: https
          backend: kv
          token: <<added token from vault operator init command>>



  1. 春季应用
@SpringBootApplication
@EnableConfigServer
public class CloudConfigServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(CloudConfigServerApplication.class, args);
    }

}

当我尝试运行这个时:

***************************
APPLICATION FAILED TO START
***************************

Description:

Invalid config server configuration.

Action:

If you are using the git profile, you need to set a Git URI in your configuration.  If you have set spring.cloud.config.server.bootstrap=true, you need to use a composite configuration.

尝试了不同的事情和资源,但找不到这个问题的解决方案。谁能帮忙看看是什么问题?

更新

我将方案更改为http并运行服务器

server:
  port: 8888

spring:
  application:
    name: config-server
  cloud:
    config:
      server:
        vault:
          host: localhost
          port: 8200
          scheme: http
          backend: kv
          token: <<added token from vault operator init command>>

仍然显示相同的错误。在尝试连接之前感觉 spring 失败了

java spring spring-boot hashicorp-vault
2个回答
0
投票

根据文档:

您正在指示

下的配置
spring.application.cloud.config.server.vault

但它应该在:

spring.cloud.vault

0
投票

您需要启用

vault
配置文件。

server:
  port: 8888

spring:
  profiles:
    active: vault
  application:
    name: config-server
  cloud:
    config:
      server:
        vault:
          host: localhost
          port: 8200
          scheme: http
          backend: kv
          authentication: TOKEN
          kv-version: 2
          token: <<root token>>

关于 kv 版本,kv 版本 2 在其 API 中添加了

/data
路径。似乎互联网上
vault kv put secret/application foo=bar baz=bam
模式中的每个示例都不起作用。以下其余 api 调用会在 v2 API 的
config-server
路径中创建键值。

创建数据

curl --location 'http://127.0.0.1:8200/v1/kv/data/config-server' \
--header 'X-Vault-Token: <<vault root token>>' \
--header 'Content-Type: application/json' \
--data '{"data":{"foo":"baz"}}'

获取数据

curl --location 'http://localhost:8200/v1/kv/data/config-server' \
--header 'X-Vault-Token: <<vault root token>>'

通过 spring 配置服务器检查

curl --location 'http://localhost:8888/config-server/default' \
--header 'X-Config-Token: <<vault root token>>'

请注意,此处使用的应用程序名称是

config-server
。此外,v1 类型似乎适用于 documentation 中的示例。

© www.soinside.com 2019 - 2024. All rights reserved.