Repository navigation
Closed
Description
Search before asking
- I searched in the issues and found nothing similar.
Version
- Broker: Pulsar 2.9.3.16 (StreamNative's release)
- Client: Pulsar C++ Client 3.1.1
- OS: Windows 11 (Visual Studio 2019) and Ubuntu 20.04 WSL (GCC 9)
Minimal reproduce step
Set up an account on StreamNative cloud, create the topic my-topic in advance and grant the produce permission. The following example uses test-auth instance under the sndev organization, replace YOUR-KEY-FILE-PATH to the path of the credential file.
#include <pulsar/Client.h>
using namespace pulsar;
int main(int argc, char *argv[]) {
std::string params = R"({
"issuer_url": "https://auth.streamnative.cloud/",
"private_key": "YOUR-KEY-FILE-PATH",
"audience": "urn:sn:pulsar:sndev:test-auth"})";
ClientConfiguration config;
config.setAuth(AuthOauth2::create(params));
Client client("pulsar+ssl://test-auth.sndev.snio.cloud:6651", config);
Producer producer;
auto result =
client.createProducer("persistent://public/default/my-topic", producer);
if (result != ResultOk) {
std::cerr << "Failed to create producer: " << result << std::endl;
return 1;
}
MessageId id;
result = producer.send(MessageBuilder().setContent("hello").build(), id);
if (result == ResultOk) {
std::cout << "Sent to " << id << std::endl;
} else {
std::cerr << "Failed to send: " << result << std::endl;
}
client.close();
return 0;
}What did you expect to see?
It should succeed
What did you see instead?
Ubuntu:
2023-02-01 22:58:13.267 DEBUG [139889604585216] ClientConnection:591 | [<none> -> pulsar+ssl://test-auth.sndev.snio.cloud:6651] Resolved hostname test-auth.sndev.snio.cloud to SECRET_IP:6651
2023-02-01 22:58:14.564 INFO [139889604585216] ClientConnection:387 | [MY_LOCAL_IP:38550 -> SECRET_IP:6651] Connected to broker
2023-02-01 22:58:15.378 ERROR [139889604585216] ClientConnection:497 | [MY_LOCAL_IP:38550 -> SECRET_IP:6651] Failed to establish connection: AuthenticationError
2023-02-01 22:58:15.378 ERROR [139889604585216] ClientConnection:1646 | [MY_LOCAL_IP:38550 -> SECRET_IP:6651] Connection closed with AuthenticationError
Windows:
2023-02-01 23:05:55.508 ERROR [11216] D:\a\pulsar-client-cpp\pulsar-client-cpp\lib\ClientConnection:497 | [MY_LOCAL_IP:6224 -> SECRET_IP:6651] Handshake failed: unregistered scheme (STORE routines)
2023-02-01 23:05:55.508 INFO [11216] D:\a\pulsar-client-cpp\pulsar-client-cpp\lib\ClientConnection:1646 | [MY_LOCAL_IP:6224 -> SECRET_IP:6651] Connection closed with ConnectError
Anything else?
No response
Are you willing to submit a PR?
- I'm willing to submit a PR!
Metadata
Metadata
Assignees
Labels
No labels
Activity
BewareMyPower commentedon Feb 1, 2023
It seems to be caused by the packaging style. It's very similar to this issue: apache/pulsar-client-node#281
I did some experiements with the Python client. Given the following similar Python script.
I tried two ways to install the Python wheel (on Ubuntu 20.04).
1. [OK] Build from source.
The output:
We can see the handshake succeeded and the client connected to the proxy
2. [FAILED] Install the existing wheel
The output:
Conclusion
The cause might be apache/pulsar#16064, which is related to a CVE. We need to document the workround or change the way to build the client library.
/cc @merlimat @shibd @RobertIndie
BewareMyPower commentedon Feb 7, 2023
Updated:
Building the C++ client from source works. I think the main reason is the
LINK_STATIC=ONbuild. I built the C++ client on Ubuntu 20.04 with the dependencies installed from the APT source and it worked well.I think the key point is the libcurl and OpenSSL dependencies. I'm still investigating and testing it.
BewareMyPower commentedon Feb 7, 2023
The root cause is that the OAuth2 client credential flow does not configure any CA cert for verification.
TL; DR, just see the following workaround section.
Workaround
Just take Ubuntu 20.04 for example, whose default CA file is
/etc/ssl/certs/ca-certificates.crt.C++ client: pass the CA cert path to
ClientConfiguration:Python and Node.js clients: though they also have the related configs to set the CA cert path, it does not work actually. (See the following section for detailed explanation). You have to copy the CA cert file to the specific path, which is determined by your system.
# All Python wheels for Linux use /etc/pki/tls/certs/ca-bundle.crt as the path of the CA cert sudo mkdir -p /etc/pki/tls/certs sudo cp /etc/ssl/certs/ca-certificates.crt /etc/pki/tls/certs/ca-bundle.crtAnalysis
From https://curl.se/docs/sslcerts.html we can see
Before Pulsar C++ client 3.0.0, the OAuth2 client credential flow didn't verify the peer, which leads to the CVE-2022-33684. Then apache/pulsar#16064 fixes it by enabling the option to verify the peer.
However, the libcurl dependency is built from source and linked statically by:
When it's built from source, the default path of the CA cert is detected automatically and determined by the OS. e.g. the Python wheels for Linux are built on
manylinux2014images, the bundled path is/etc/pki/tls/certs/ca-bundle.crt. You can see the path from any workflow here:The only workaround for Python and Node.js clients on Linux is copying your CA cert file into that path. The C++ client can work by configuring
tlsTrustCertsFilePathbecause the deb package is compiled on Debian, rpm package is compiled on CentOS, the default path of the CA cert file is the same with the path on Debian-based distros and RedHat-based distros. However, the Python client for Linux is built onmanylinuximage, which is based on a RedHat-based distro, so the path is different with the Debian-based distros.How to reproduce
Create an account on StreamNative cloud to get the client id and client secret. You can switch to your own vendor if you have an Pulsar service with OAuth2 authentication enabled.
TlsOauth2Example.cc
Start a docker container:
docker run -v $PWD:/app -it ubuntu:20.04 /bin/bashRun the following commands inside the container:
You will see the following output:
If you removed the
setTlsTrustCertsFilePathconfig, you will see a more error line:That's because the for TLS connection, the C++ client reads the CA cert file from the config:
pulsar-client-cpp/lib/ClientConnection.cc
Lines 205 to 209 in 0631e36
Solution
We should use the
tlsTrustCertsFilePathfor HTTP requests in OAuth2's client credential flow, just likeHTTPLookupServicedoes:pulsar-client-cpp/lib/HTTPLookupService.cc
Lines 260 to 262 in 0631e36
I will push a PR soon.
[fix] Use ClientConfiguration::getTlsTrustCertsFilePath for the OAuth…
[fix] Use ClientConfiguration::getTlsTrustCertsFilePath for the OAuth…
shibd commentedon Feb 7, 2023
Nice catch! Node.js 1.8.0 oauth2 auth failed is the same as this.
I checked cross-compile logs on the macOS system, and the
cert bundleandpathis not set on arm64.I'll use your PR to verify if this can be fixed.
shibd commentedon Feb 7, 2023
It can solve this problem by configuring
tlsTrustCertsFilePath.