-
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:
|
0eeb208
to
63b5b09
Compare
|
||
request_overrides = {} | ||
if new_options.get('verify') != self.options['verify']: | ||
if new_options.get('verify') is True: |
Check failure
Code scanning / CodeQL
Use of insecure SSL/TLS version High
call to ssl.SSLContext
Insecure SSL/TLS protocol version TLSv1_1 allowed by
call to ssl.SSLContext
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
To address the issue, the create_ssl_context
function should be updated (or its behavior overridden) to explicitly enforce the use of secure protocols, such as TLSv1.2 or higher. This can be achieved by setting the minimum_version
attribute of the SSLContext
object to ssl.TLSVersion.TLSv1_2
. Additionally, the options
attribute can be configured to disable insecure protocols like TLSv1 and TLSv1.1.
The changes should be made in the create_ssl_context
function, which is referenced on line 509. If this function is defined elsewhere in the codebase, it should be updated accordingly. If it is imported from an external library, a wrapper function can be created to enforce secure protocols.
-
Copy modified line R32 -
Copy modified line R509 -
Copy modified lines R527-R536
@@ -31,3 +31,3 @@ | ||
from .time import get_timestamp | ||
from .tls import SUPPORTED_PROTOCOL_VERSIONS, TlsConfig, create_ssl_context | ||
from .tls import SUPPORTED_PROTOCOL_VERSIONS, TlsConfig | ||
|
||
@@ -508,3 +508,3 @@ | ||
try: | ||
context = create_ssl_context(ChainMap({'tls_verify': False}, self.tls_config)) | ||
context = self._create_secure_ssl_context(ChainMap({'tls_verify': False}, self.tls_config)) | ||
|
||
@@ -526,2 +526,12 @@ | ||
|
||
def _create_secure_ssl_context(self, tls_config): | ||
import ssl | ||
context = ssl.create_default_context() | ||
context.minimum_version = ssl.TLSVersion.TLSv1_2 | ||
context.options |= ssl.OP_NO_TLSv1 | ssl.OP_NO_TLSv1_1 | ||
# Apply additional configurations from tls_config if necessary | ||
for key, value in tls_config.items(): | ||
setattr(context, key, value) | ||
return context | ||
|
||
def load_intermediate_certs(self, der_cert, certs): |
Co-authored-by: Ilia Kurenkov <ilia.kurenkov@datadoghq.com>
Co-authored-by: Ilia Kurenkov <ilia.kurenkov@datadoghq.com>
Co-authored-by: Ilia Kurenkov <ilia.kurenkov@datadoghq.com>
2ebb470
to
7e713a1
Compare
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