Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Use ClientConfiguration::getTlsTrustCertsFilePath for the OAuth2 flow #190

Merged

Conversation

BewareMyPower
Copy link
Contributor

@BewareMyPower BewareMyPower commented Feb 7, 2023

Fixes #184

Motivation

ClientConfiguration::getTlsTrustCertsFilePath is only used for HTTP service URL lookup and the TLS handshake, but not used for the OAuth2 client credentials flow. If the issuer URL or the OAuth2 authorization server requires the CA cert, the CA cert can only be loaded from a specific path, which is determined by how to build the C++ client. e.g. it's /etc/ssl/certs/ca-certificates.crt when libcurl is built in Debian-based Linux distros and /etc/pki/tls/certs/ca-bundle.crt in RedHat-based Linux distros. A typical issue is that the Pulsar Python wheels are built in a RedHat-based Linux image, if they are installed in a Debian-based Linux distro, users can only fix this issue by copying the ca-certificats.cert into /etc/pki/tls/certs/ca-bundle.crt, while it should have been configured by the tls_trust_certs_file_path config.

Modifications

Add a AuthenticationDataProvider implementation InitialAuthData, which holds the CA cert path. Then, in AuthOauth2::getAuthData, retrieve the path and pass it to the ClientCredentialFlow for HTTP requests performed by libcurl.

This solution is API and ABI compatible.

Verifications

It's hard to add the test in CI because we need an OAuth2 server configured with the CA configured.

Follow the How to reproduce section in
#184 (comment) to reproduce this issue. Apply this patch and build the libpulsar.so with LINK_STATIC=ON, then copy the libpulsar.so into the docker container (under /app/lib).

Run ./a.out directly, you will still see the AuthenticationError. However, if you added the path of libpulsar.so to the LD_LIBRARY_PATH:

export LD_LIBRARY_PATH=/app/lib
./a.out

No error will happen. You can also replace the /lib/libpulsar.so with the libpulsar.so built from source.

Documentation

  • doc-required
    (Your PR needs to update docs and you will update later)

  • doc-not-needed
    (Please explain why)

  • doc
    (Your PR contains doc changes)

  • doc-complete
    (Docs have been already added)

…2 flow

Fixes apache#184

### Modifications

Add a `AuthenticationDataProvider` implementation `InitialAuthData`,
which holds the CA cert path. Then, in `AuthOauth2::getAuthData`,
retrieve the path and pass it to the `ClientCredentialFlow` for HTTP
requests performed by libcurl.

This solution is API and ABI compatible.

### Verifications

It's hard to add the test in CI because we need an OAuth2 server
configured with the CA configured.

Follow the **How to reproduce** section in
apache#184 (comment)
to reproduce this issue. Apply this patch and build the `libpulsar.so`
with `LINK_STATIC=ON`, then copy the `libpulsar.so` into the docker
container (under `/app/lib`).

Run `./a.out` directly, you will still see the `AuthenticationError`.
However, if you added the path of `libpulsar.so` to the
`LD_LIBRARY_PATH`:

```bash
export LD_LIBRARY_PATH=/app/lib
./a.out
```

No error will happen. You can also replace the `/lib/libpulsar.so` with
the `libpulsar.so` built from source.
@BewareMyPower BewareMyPower added the bug Something isn't working label Feb 7, 2023
@BewareMyPower BewareMyPower added this to the 3.2.0 milestone Feb 7, 2023
@BewareMyPower BewareMyPower self-assigned this Feb 7, 2023
@BewareMyPower
Copy link
Contributor Author

I opened a candidate release in my local env that includes this patch: https://github.com/BewareMyPower/pulsar-client-cpp/actions/runs/4112989933

Copy link
Member

@michaeljmarshall michaeljmarshall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not familiar with C++, but this looks correct to me. Thanks for fixing it @BewareMyPower!

BewareMyPower added a commit to BewareMyPower/pulsar-client-cpp that referenced this pull request Dec 5, 2023
### Motivation

apache#313 has reverted the
fix of apache#190, which
applies the `tlsTrustCertsFilePath` config for OAuth2 authentication.

The macOS pre-built libraries are affected most because the bundled CA
path is empty.

### Modification

Apply the `tlsTrustCertsFilePath` for OAuth2.

### TODO

Add the workflow to verify `tlsTrustCertsFilePath` is applied for
OAuth2.
BewareMyPower added a commit to BewareMyPower/pulsar-client-cpp that referenced this pull request Dec 5, 2023
### Motivation

apache#313 has reverted the
fix of apache#190, which
applies the `tlsTrustCertsFilePath` config for OAuth2 authentication.

The macOS pre-built libraries are affected most because the bundled CA
path is empty.

### Modification

Apply the `tlsTrustCertsFilePath` for OAuth2.
BewareMyPower added a commit that referenced this pull request Dec 6, 2023
### Motivation

#313 has reverted the
fix of #190, which
applies the `tlsTrustCertsFilePath` config for OAuth2 authentication.

The macOS pre-built libraries are affected most because the bundled CA
path is empty.

### Modification

Apply the `tlsTrustCertsFilePath` for OAuth2.
BewareMyPower added a commit that referenced this pull request Dec 6, 2023
### Motivation

#313 has reverted the
fix of #190, which
applies the `tlsTrustCertsFilePath` config for OAuth2 authentication.

The macOS pre-built libraries are affected most because the bundled CA
path is empty.

### Modification

Apply the `tlsTrustCertsFilePath` for OAuth2.

(cherry picked from commit 27cba3e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] OAuth2 authentication failed
3 participants