confluentinc / librdkafka

The Apache Kafka C/C++ library
Other
7.37k stars 3.11k forks source link

Failed to acquire SASL OAUTHBEARER token: SSL certificate problem: unable to get local issuer certificate #4761

Open kishkulk opened 1 week ago

kishkulk commented 1 week ago

Description

I am trying to set sasl.oauthbearer.token.endpoint.url to https endpoint

if (rd_kafka_conf_set(conf, "sasl.oauthbearer.token.endpoint.url", "https://<IP>:<https_port>/realms/master/protocol/openid-connect/token", errstr, sizeof(errstr)) != RD_KAFKA_CONF_OK) {
    fprintf(stderr, "Failed to set sasl.oauthbearer.token.endpoint.url: %s\n", errstr);
    return 1;
}

the above code fails while trying to connect the oauth token provider with error

%3|1718691008.556|OIDC|rdkafka#producer-1| [thrd:background]: Failed to retrieve OIDC token from "https://<IP>:<https_port>/realms/master/protocol/openid-connect/token": SSL certificate problem: unable to get local issuer certificate (-1)
%3|1718691008.561|ERROR|rdkafka#producer-1| [thrd:background]: Failed to acquire SASL OAUTHBEARER token: SSL certificate problem: unable to get local issuer certificate

When using the same system, the curl command functions correctly when I configure CURL_CA_BUNDLE to the CA certificate file from the OAuth token provider. I attempted to execute the librdkafka sample with the CURL_CA_BUNDLE environment variable, but unfortunately, it did not work. Consequently, I had to make corrections to the librdkafka code, specifically in rdhttp.c, where I needed to

 rd_http_error_t *rd_http_req_init(rd_http_req_t *hreq, const char *url) {
 const char *ca_bundle_path = getenv("CURL_CA_BUNDLE");
 if (ca_bundle_path) {
  curl_easy_setopt(hreq->hreq_curl, CURLOPT_CAINFO, ca_bundle_path);
 }
 ...
 }

since the librdkafka uses the curl I was thinking the curl environment variables should work.

How to reproduce

set sasl.oauthbearer.token.endpoint.url to a https endpoint

Checklist