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: always load the default certs on our custom SSL context #196

Merged
merged 12 commits into from
Jul 9, 2024

Conversation

pyrooka
Copy link
Member

@pyrooka pyrooka commented Jul 2, 2024

This is a follow-up PR of this one. In the linked PR we had to specify and older version of the requests package to avoid a regression.

This PR contains the fix for that, so we can continue using always the latest version. Furthermore, the HTTPS related tests have been improved and moved to the directory of the unit tests, to always include them in our builds.

ibm_cloud_sdk_core/http_adapter.py Show resolved Hide resolved
test/test_http_adapter.py Show resolved Hide resolved
Comment on lines 71 to 73
service = BaseService(service_url='https://raw.githubusercontent.com', authenticator=NoAuthAuthenticator())
assert service.disable_ssl_verification is False
prepped = service.prepare_request('GET', url='/IBM/python-sdk-core/main/README.md')
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not too happy with this solution, but I found this to be the most reliable way to reproduce the problem. Actually the only way because I was not able to trigger the exception in any of my local experiments. I totally understand if you have concerns about this, so let's discuss.

Comment on lines 50 to 53
with pytest.raises(SSLError):
with pytest.raises(SSLError, match="certificate verify failed: self-signed certificate"):
Copy link
Member Author

Choose a reason for hiding this comment

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

Just a small tweak to make sure we catch the exact same error that we want.

@pyrooka pyrooka force-pushed the nb/https-test-improvements branch from 99404de to e783e05 Compare July 2, 2024 12:44
@pyrooka pyrooka force-pushed the nb/https-test-improvements branch from e783e05 to d975630 Compare July 2, 2024 14:31
@pyrooka pyrooka marked this pull request as ready for review July 2, 2024 14:39
@pyrooka pyrooka self-assigned this Jul 2, 2024
Copy link
Member

@ricellis ricellis left a comment

Choose a reason for hiding this comment

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

I think this is a good change to workaround the requests issues. I supect the comment wasn't directed at me, but I had one thought around the external wesbite test, but I wouldn't consider that a blocker to merging this anyway.

Comment on lines 103 to 105
service = BaseService(service_url='https://raw.githubusercontent.com', authenticator=NoAuthAuthenticator())
assert service.disable_ssl_verification is False
prepped = service.prepare_request('GET', url='/IBM/python-sdk-core/main/README.md')
Copy link
Member

Choose a reason for hiding this comment

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

I'm not too happy with this solution, but I found this to be the most reliable way to reproduce the problem. Actually the only way because I was not able to trigger the exception in any of my local experiments. I totally understand if you have concerns about this, so let's discuss.

The only other thing I can think of is listing the certs available and checking it is more than 0, but I don't know if we have enough visibility to be able to do that.

Certainly using a website that has a public certificate chain leading to some default root cert is a surefire way to prove that it can successfully negotiate a connection using the loaded default certs. However, whilst connecting to github proves we have some default certs it doesn't necessarily prove we have the certificate we need so perhaps switching to some cloud.ibm.com site would offer more value since it will likely use the same root certifcate chain as our services do? Maybe something like https://cloud.ibm.com/status or with a filter like https://cloud.ibm.com/status/security?component=ibm-cloud&location=global if it's too large a page otherwise?

Copy link
Member Author

Choose a reason for hiding this comment

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

The only other thing I can think of is listing the certs available and checking it is more than 0, but I don't know if we have enough visibility to be able to do that.

That's a clever idea but I can't tell either - at least off the to of my head. I think I'll take a look because this sounds interesting.

...perhaps switching to some cloud.ibm.com site would offer more value...

Agreed, it makes sense!

Copy link
Member

@dpopp07 dpopp07 left a comment

Choose a reason for hiding this comment

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

All looks good to me! 👍

Copy link
Member

@padamstx padamstx left a comment

Choose a reason for hiding this comment

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

LGTM, but there are test failures in the Travis build :(

test/test_http_adapter.py Outdated Show resolved Hide resolved
@pyrooka pyrooka requested a review from padamstx July 9, 2024 10:10
Copy link
Member

@padamstx padamstx left a comment

Choose a reason for hiding this comment

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

LGTM

ssl_context = service.http_adapter.poolmanager.connection_pool_kw.get("ssl_context")
assert ssl_context is not None
# In some cases (especially in Ubuntu containers that we use for testing on Travis)
# the default CA certifications are stored in a different place, so let's try to
Copy link
Member

Choose a reason for hiding this comment

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

A really minor nit...

Suggested change
# the default CA certifications are stored in a different place, so let's try to
# the default CA certificates are stored in a different place, so let's try to

Signed-off-by: Norbert Biczo <[email protected]>
@pyrooka pyrooka merged commit ff14a4b into main Jul 9, 2024
4 checks passed
@pyrooka pyrooka deleted the nb/https-test-improvements branch July 9, 2024 19:15
ibm-devx-sdk pushed a commit that referenced this pull request Jul 9, 2024
## [3.20.2](v3.20.1...v3.20.2) (2024-07-09)

### Bug Fixes

* always load the default certs on our custom SSL context ([#196](#196)) ([ff14a4b](ff14a4b))
@ibm-devx-sdk
Copy link

🎉 This PR is included in version 3.20.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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.

5 participants