Spring Cloud Vault相互TLS身份验证问题

时间:2020-05-22 20:38:16

标签: spring-boot ssl spring-cloud hashicorp-vault spring-cloud-vault-config

我正在尝试设置一个Spring Boot应用程序,以通过TLS与我的Vault服务器通信。我想使用相互证书认证。我可以使用TLS设置Vault服务器,并且可以使用CLI使用客户端证书登录到该服务器。但是,spring boot应用程序无法将其客户端证书提交给Vault服务器-每次我运行我的应用程序时,Vault服务器都会打印:

http: TLS handshake error from 127.0.0.1:33288: tls: client didn't provide a certificate

客户端(我的Spring Boot应用程序)打印:

org.springframework.vault.authentication.VaultLoginException:
Cannot login using org.springframework.web.client.ResourceAccessException:
I/O error on POST request for "https://localhost:8200/v1/auth/cert/login": 
Received fatal alert: bad_certificate;
nested exception is javax.net.ssl.SSLHandshakeException:
Received fatal alert: bad_certificate
... (a stack trace for VaultLoginException)

这是我的bootstrap.yml

spring:
    application.name: vault-demo

    cloud.vault:
        host: localhost
        port: 8200
        scheme: https
        uri: https://localhost:8200
        connection-timeout: 5000
        read-timeout: 15000
        config.order: -10

        authentication: CERT        

        ssl:
            trust-store: classpath:keystore.jks
            trust-store-password: changeit

            key-store: classpath:client-cert.jks
            key-store-password: changeit
            cert-auth-path: cert

我找不到需要在spring.cloud.vault.*下配置的各种属性的任何文档。

我的client-cert.jks商店具有客户端证书和密钥。启用S​​SL详细日志,可以看到以下内容:

*** ServerHelloDone
Warning: no suitable certificate found - continuing without client authentication
*** Certificate chain

表示客户端在其信任库中找到了服务器的证书,但未将客户端的证书发送到服务器。

此外,如果我使用curl发送登录请求,则成功:

curl -k --request POST \
--cert work/ca/certs/client.cert.pem \
--key work/ca/private/client.decrypted.key.pem \
--data @payload.json \
https://localhost:8200/v1/auth/cert/login

# gives me back a JSON with newly issued token.

我也尝试使用配置类,并将javax.net.ssl.keyStore和相关属性作为JAVA_OPTS传递,但是绝对没有区别-保管箱一直说客户没有发送证书:< / p>

@Configuration
public class AppConfig extends AbstractVaultConfiguration {

    @Value("${vault.uri}")
    URI vaultUri;

    @Override
    public VaultEndpoint vaultEndpoint() {
        return VaultEndpoint.from(vaultUri);
    }

    @Override
    public ClientAuthentication clientAuthentication() {
        try {
            RestTemplate restTemplate = new RestTemplate();
            HttpClientBuilder httpClientBuilder = HttpClients.custom()
                    .setSSLContext(SSLContext.getDefault())
                        .useSystemProperties();

            restTemplate.setRequestFactory(
                    new HttpComponentsClientHttpRequestFactory(
                            httpClientBuilder.build()));

            return new ClientCertificateAuthentication(restTemplate);

        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }
}

任何人都可以指出我想念/做错了什么吗?

1 个答案:

答案 0 :(得分:0)

问题是我的保险柜配置未正确指定tls_client_ca_file属性。将其设置为根CA证书,一切正常。也不需要添加AppConfig类。