首页 文章

配置Spring Cloud Config Server和Spring Cloud Vault进行 生产环境

提问于
浏览
5

我正在尝试设置由Spring Cloud Vault秘密管理支持的Spring Cloud Config Server . 我对Spring比较新,但我在这里尝试了以下说明和示例: -

http://cloud.spring.io/spring-cloud-vault-config/

如果您按照默认设置(如http,localhost和8200用于保险库 endpoints )和tls_disable = 1来关闭SSL,则一切正常 . 然而,对于任何真实环境而言,这些都不是实用的设置,并且几乎没有任何示例可以帮助解决这有人可以帮助一个有效的例子吗?

我已成功设置了启用TLS的保险库 . 我已成功设置一个使用自签名证书连接的配置服务器 . 我甚至可以将一个秘密值注入配置服务器并通过 @Value@PostConstruct 公开它 .

所有这些都有效 . 但是,当我尝试利用Spring Conig endpoints 访问Vault时,我得到以下内容: -

{
  "timestamp": 1486413850574,
  "status": 500,
  "error": "Internal Server Error",
  "exception": "org.springframework.web.client.ResourceAccessException",
  "message": "I/O error on GET request for \"http://127.0.0.1:8200/v1/secret/myapp\": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect",
  "path": "/myapp/default"
}

即使我在 bootstrap.yml 中设置了覆盖,配置服务器也使用默认值 . : -

server:
    port: 8888

spring:
    profiles:
        active: vault

spring.cloud.vault:
    host: myhost.mydomain.com
    port: 8200
    scheme: https
    authentication: TOKEN
    token: 0f1887c3-d8a8-befd-a5a2-01e4e066c50
    ssl:
        trust-store: configTrustStore.jks
        trust-store-password: changeit

正如您所看到的,它应该指向myhost.mydomain.com而不是127.0.0.1,它应该使用https,而不是http作为协议方案 .

我不确定为什么它将这些默认值用于配置服务器 endpoints ,但在spring cloud Vault启动期间使用了正确的设置 . 我正在使用Spring Dalsten.M1和Spring Cloud Vault 1.0.0.M1的所有最新稳定版本 . 我意识到这些是里程碑版本 . 我也尝试过Camden和Brixton组合,但没有运气 . 如果需要,我可以提供代码 .

任何帮助非常感谢 .

3 回答

  • 1

    正如我在回答spensergibb时提到的那样,我自己解决了这个问题 . 根据他的评论,我将澄清我的意图,因为这将有助于对该问题的共同理解 . 我试图做两件事: -

    • 站起来使用Vault作为后端的配置服务器(与默认的GIT后端相对),并将Vault API暴露给客户端应用程序(通过TLS),以便他们可以检索自己的机密 . 我不希望我的所有客户端应用程序直接连接到Vault . 我希望他们通过让配置服务器连接到Vault来从配置服务器获取配置 . 直到昨晚我都无法实现这一目标,除非我将所有内容设置为默认情况下禁用TLS并使用环回地址,端口8200用于Vault软件等 . 显然默认设置对于我们任何部署的环境都不实用 . 我会提到spencergibb发布的链接确实帮助我理解为什么这不起作用,但原因的微妙之处在于我之前错过了它 . 请继续阅读我的解释 .

    • 我希望配置服务器直接从Vault配置自己 . 也就是说,通过Spring Cloud Vault Config连接到Vault . 如文档中所述,这对我来说很有效 . 然而,这个目标有点微不足道,因为我目前没有真正的用例 . 但我想知道是否可以这样做,因为我没有找到真正的原因,这似乎是整合Vault的第一步 .

    这两种功能之间的区别帮助我理解问题源于Spring Cloud Config Server和Spring Cloud Vault似乎使用两个不同的bean来注入Vault配置属性 . Spring Cloud Config Server使用带有@ConfigurationProperties(“spring.cloud.config.server.vault”)注释的VaultEnvironmentRepository,Spring Cloud Vault使用带有@ConfigurationProperties(“spring.cloud.vault”)注释的VaultProperties .

    这导致我为我的bootstrap yml添加了两个不同的配置 .

    server:
        port: 8888
    
    spring:
        profiles:
            active: local, vault
    
        application:
            name: quoting-domain-configuration-server
    
        cloud:
            vault:
                host: VDDP03P-49A26EF.lm.lmig.com
                port: 8200
                scheme: https
                authentication: TOKEN
                token: 0f1997c3-d8a8-befd-a5a2-01e4e066c50a
                ssl:
                    trust-store: configTrustStore.jks
                    trust-store-password: changeit
    
            config:
                server:
                    vault:
                        host: VDDP03P-49A26EF.lm.lmig.com
                        port: 8200
                        scheme: https
                        authentication: TOKEN
                        token: 0f1997c3-d8a8-befd-a5a2-01e4e066c50a
    

    请注意相同的配置详细信息只是不同的yml路径 . 这是我错过的一个微妙点,因为我首先让目标1号首先工作,并假设相同的配置适用于这两个目标 . (注意:令牌和密码是人为设计的) .

    这几乎可以工作,除了SSL握手错误 . 如您所见,spring.cloud.config.server.vault路径上没有设置SSL属性 . VaultProperties bean不支持它们 . 我不知道如何处理这个问题(也许是另一个我找不到的非特定于库的特定bean) . 我的解决方案是简单地自己强制执行证书配置: -

    @SpringBootApplication
    @EnableConfigServer
    public class Application
    {
        public static void main(String[] args)
        {
            System.setProperty("javax.net.ssl.trustStore",
                Application.class.getResource("/configTrustStore.jks").getFile());
            System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
            SpringApplication.run(Application.class, args);
        }
    }
    

    这个SSL解决方案非常难看 . 我确信必须有更好的方法来完成这一部分 . 所以我愿意接受其他建议 . 但是,一旦我完成了上述所有步骤,现在一切正常

  • 0

    谢谢为了你的写作 . 我正在努力让这个工作 . 我能够获得连接到Spring Cloud Config服务器和Vault服务器的客户端服务,但我无法让Spring Cloud Config服务器连接到Vault服务器 .

    将配置复制到Spring Cloud Config服务器后,我甚至都很挣扎 . 虽然我最终使用了你的配置,但我能够将其削减相当多 . 关键是令牌不属于Spring Cloud Config服务器 . 它属于客户端 .

    我在浏览器中尝试 http://localhost:8888/{application}/default 但得到以下内容:

    Whitelabel Error Page
    
    This application has no explicit mapping for /error, so you are seeing this as a fallback.
    
    Thu May 11 14:21:31 EDT 2017
    There was an unexpected error (type=Bad Request, status=400).
    Missing required header: X-Config-Token
    

    我使用PostMan发送带有包含Vault令牌的 X-Config-Token 标头的请求并且它有效 .

    这是我的最终配置 .

    server:
      port: ${PORT:8888}
    
    management:
      context-path: /manage
      security:
        enabled: true
    
    spring:
      profiles:
        active: git,vault
    
      application:
        name: config-server
    
      cloud:
        config:
          server:
            git:
              order: 1
              uri: file:///temp/config-server/config
    
            vault:
              order: 0
              host: localhost
              port: 8200
              scheme: http
    

    所以看起来你需要将令牌添加到客户端 . 也许使用 spring.cloud.config.token .

  • 1

    代替

    @SpringBootApplication
    @EnableConfigServer
    public class Application
    {
        public static void main(String[] args)
        {
            System.setProperty("javax.net.ssl.trustStore",
                Application.class.getResource("/configTrustStore.jks").getFile());
            System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
            SpringApplication.run(Application.class, args);
        }
    }
    

    bootstrap yml ->
    javax.net.ssl.trustStore: /configTrustStore.jks
    javax.net.ssl.trustStorePassword: changeit
    

相关问题