Search code examples
springspring-cloud-sleuthzipkin

Configure basic authentication with Spring Sleuth Zipkin


I'm trying to configure my spring boot app to log into a zipkin server. The problem is that this server is protected by a proxy (with basic auth) and I cannot find any documentation describing how to configure authorization with spring-sleuth.

I have tried to use that kind of configuration :

spring.zipkin.baseUrl: http://user:password@zipkin-server:9411

But without success, logs indicating :

ZipkinRestTemplateWrapper    : Created POST request for "http://user:password@zipkin-server:9411/api/v2/spans"
ZipkinRestTemplateWrapper    : Setting request Accept header to [text/plain, application/json, application/*+json, */*]
ZipkinRestTemplateWrapper    : Writing [[B@46d92b65] as "application/json" using [org.springframework.http.converter.ByteArrayHttpMessageConverter@53804b23]
ZipkinRestTemplateWrapper    : POST request for "http://user:password@zipkin-server:9411/api/v2/spans" resulted in 401 (Unauthorized); invoking error handler

I have tried with curl and it works.

Has someone already succeed to configure authentication with spring-sleuth ?


Solution

  • For basic authentication, the username and password are required to be sent as part of the HTTP Header Authorization. The header value is computed as Base64 encoding of the string username:password.So if the username is abcd and password is 1234, the header will look something like this (Chatset used: UTF-8).

    Authorization: Basic YWJjZDoxMjM0

    Sleuth cloud project provides ZipkinRestTemplateCustomizer to configure the RestTemplate used to communicate with the Zipkin server.

    Refer to the documentation for the same: https://cloud.spring.io/spring-cloud-sleuth/reference/html/#sending-spans-to-zipkin

    Note: Base64 encoding is reversible and hence Basic auth credentials are not secured. HTTPS communication should be used along with Basic Authentication.