-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Allow HTTPS requests to use tls_ciphers
#20179
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
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
c6b0da6
to
0eeb208
Compare
0eeb208
to
63b5b09
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First round, mostly small suggestions. I'll look at the hard parts next. This is huge, thanks for all the hard work!
Co-authored-by: Ilia Kurenkov <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, some minor stuff left! Put a little time on your calendar on monday to brush up on the tls module.
def create_ssl_context(config, overrides=None): | ||
# https://docs.python.org/3/library/ssl.html#ssl.SSLContext | ||
# https://docs.python.org/3/library/ssl.html#ssl.PROTOCOL_TLS_CLIENT | ||
context = ssl.SSLContext(protocol=ssl.PROTOCOL_TLS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got my wires crossed, was thinking about this vulnerability case, which is about a different thing.
In a separate PR we can probably change the protocol constant to be PROTOCOL_TLS_CLIENT
elif isinstance(verify, bool): | ||
tls_config["tls_verify"] = verify | ||
else: | ||
LOGGER.warning( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1 on the warning. Let's decide if this is a blocker for the user. If yes, we crash with an error that explains how to fix it.
If no, we have to flesh out what our backup plan is. In that case a debug
here would make sense to let support/devs know we've hit this condition as they troubleshoot.
# This is used to determine if the adapter was created with a custom context | ||
# for the purpose of reverting to the default context when needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# This is used to determine if the adapter was created with a custom context | |
# for the purpose of reverting to the default context when needed. |
https_adapter = self._https_adapters.get(tls_config_key) | ||
|
||
if https_adapter is not None: | ||
session.mount('https://', https_adapter) | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https_adapter = self._https_adapters.get(tls_config_key) | |
if https_adapter is not None: | |
session.mount('https://', https_adapter) | |
return | |
if tls_config_key in self._https_adapters: | |
session.mount('https://', self._https_adapters[tls_config_key]) | |
return |
simpler
|
||
https_adapter = SSLContextHostHeaderAdapter(context) | ||
else: | ||
# Use SSLContextHTTPSAdapter for consistent TLS configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Use SSLContextHTTPSAdapter for consistent TLS configuration |
That comment is from another version of the code.
else: | ||
updated_ciphers = ":".join(ciphers) | ||
self.tls_ciphers_allowed = updated_ciphers | ||
# Create TLS context for consistent TLS configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Create TLS context for consistent TLS configuration |
Leftover from previous implementation. Not sure we need much explanation here.
for option, value in self.options.items(): | ||
setattr(session, option, value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not for this PR because this existed before, but aren't we supposed to take into account also new_options
here?
What does this PR do?
This PR modifies the behavior of the
RequestsWrapper
to make use ofrequests.Session
for all requests.It extends the allowed TLS ciphers to all those that are allowed by the compile-time configuration.
This was achieved using the
Session
class's HTTPSAdapter
, which passes the customSSLContext
to the underlyingurllib3
functions.Note
Many unit and integration tests that were previously mocking
requests.get
or otherrequests
methods needed to be re-written with these changes in mind.N.B: These test should most likely be rewritten in a subsequent PR to use higher-level mocks. This would prevent future PRs that would change logic inside the
RequestsWrapper
to have to fix hundreds of tests.Motivation
The integration config provides a
tls_ciphers
parameter that was not utilized uniformly throughout HTTPS requests. Most notably, it had no effect on the requests made through the AgentCheck'shttp
attribute.Allowing the modification of cipher suites is essential to support the broadest array of use cases.
For example, some users have endpoints that do not accept any of Python's ssl.SSLCipher default cipher suites, leading to these endpoints being unusable with our checks.
Important
The goal for this PR is to only extend the realm of usable endpoints for end users.
All existing interfaces, inputs, and outputs remain unchanged.
No user action is required to benefit from the improvements.
Review checklist (to be filled by reviewers)
qa/skip-qa
label if the PR doesn't need to be tested during QA.backport/<branch-name>
label to the PR and it will automatically open a backport PR once this one is merged