简体   繁体   English

使用微服务 AppRole 到 Spring 云配置服务器和 Vault 集成

[英]Using Microservice AppRole to Spring Cloud Config Server and Vault integration

How to connect a Microservice with AppRole[in vault] to Spring Cloud Config Server with Vault backend.如何将带有 AppRole [in vault] 的微服务连接到带有 Vault 后端的 Spring 云配置服务器。

I can see examples using the root token like curl -X GET http://localhost:8888/my-service/default -H "X-Config-Token: s.TmqaRA2lASdNhJZqqZy7y8pX".我可以看到使用根令牌的示例,例如 curl -X GET http://localhost:8888/my-service/default -H "X-Config-Token: s.TmqaRA2lASdNhJZqqZy7y8pX"。 But I could not find any example that use approle to connect spring cloud config service.但我找不到任何使用 approle 连接 spring 云配置服务的示例。

But I do not want pass root token from micro services to spring cloud config server, instead each service will have app role defined which should be able to connect the spring cloud config which in turn connect to Vault and get data.但我不想将根令牌从微服务传递到 spring 云配置服务器,而是每个服务都定义了应用角色,应该能够连接 spring 云配置,然后连接到 Vault 并获取数据。

I had the same issue when using a Spring Cloud Config Server as a central configuration broker.使用 Spring 云配置服务器作为中央配置代理时,我遇到了同样的问题。

I found the followingGitHub issue which provided a solution.我发现以下GitHub 问题提供了解决方案。 In short you have to add the spring-vault-core dependency to your dependencies in order to add a valid token resolver for the AppRole authentication:简而言之,您必须将 spring-vault-core 依赖项添加到您的依赖项中,以便为 AppRole 身份验证添加有效的令牌解析器:

Maven: Maven:

<dependency>
    <groupId>org.springframework.vault</groupId>
    <artifactId>spring-vault-core</artifactId>
</dependency>

Gradle: Gradle:

implementation "org.springframework.vault:spring-vault-core"

This should fix the issue directly.这应该可以直接解决问题。 Of course the following configuration has to bet set then:当然,下面的配置必须下注设置:

spring:
  cloud:
    config:
      server:
        vault:
          port: 443
          host: myvault.domain.com
          scheme: https
          backend: mybackend
          kv-version: 2 #required if secrets engine version is v2 (default: v1/1)
          timeout: 5 #seconds
          authentication: APPROLE
          app-role:
            secret-id: 1234567-234567-23456-12341
            role-id: 987654-3456-9865-1235
            role: my-role-name #optional
            app-role-path: approle #optional if non default (default: approle)

After adding the dependency, configuring and starting the service, the following log message appears:添加依赖、配置并启动服务后,出现以下日志消息:

2021-04-30 12:40:31.211 INFO 53327 --- [nio-8888-exec-2] osvaLifecycleAwareSessionManager: Scheduling Token renewal 2021-04-30 12:40:31.211 INFO 53327 --- [nio-8888-exec-2] osvaLifecycleAwareSessionManager:调度令牌更新

The X-Config-Token header is then not required anymore.然后不再需要X-Config-Token header。

For more information regardin the Vault setup, visit:有关 Vault 设置的更多信息,请访问:

  1. AppRole Auth Method AppRole 认证方法
  2. Setting up the AppRole auth method for a service为服务设置 AppRole 身份验证方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 配置Spring Cloud Config Server和Spring Cloud Vault以进行生产 - Configuring Spring Cloud Config Server and Spring Cloud Vault for production 带有Zookeeper或HashiCorp Vault后端的Spring Cloud Config Server - Spring Cloud Config Server with Zookeeper or HashiCorp Vault Backend 微服务不从 spring-cloud-config-server 微服务中获取属性 - microservice doesn't fetch properties from spring-cloud-config-server microservice Spring Cloud Config + HashiCorp Vault 无法连接 - Spring Cloud Config + HashiCorp Vault Cannot connect Spring 云配置库奇怪请求 - Spring Cloud Config Vault Strange Request 将 Spring Cloud Config Server 与 vault 后端集成,在 GET 请求上出现 I/O 错误,连接被拒绝 - Integrating Spring Cloud Config Server with vault backend giving I/O error on GET request with connection refused Spring 云微服务服务器端口转换异常 - Spring cloud microservice server port cast exception 仅在弹簧云微服务实例中使用https - Using https only with spring cloud microservice instances 如何将Spring Cloud Config与Git and Vault复合环境存储库一起使用? - How to use Spring Cloud Config with a Git and Vault composite environment repository? 带有配置服务器的 Spring Cloud Eureka - Spring Cloud Eureka with Config Server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM