Intercept HTTPS CONNECT tunnels in mocked backend mode#6725
Draft
cbeauchesne wants to merge 1 commit intomainfrom
Draft
Intercept HTTPS CONNECT tunnels in mocked backend mode#6725cbeauchesne wants to merge 1 commit intomainfrom
cbeauchesne wants to merge 1 commit intomainfrom
Conversation
Contributor
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
In mocked_backend mode, the agent sends HTTPS requests to backend (trace.agent.datadoghq.com, api.datadoghq.com, etc.) using HTTP_PROXY, which means it opens HTTPS CONNECT tunnels through the proxy. When the real backend is unreachable, mitmproxy fails the tunnel at the TLS setup, and
request()is not fired.And because
request()never fired, the existing mock logic (which returns synthetic202/200responses) was bypassed entirely for these flows.Furthermore, if any of those requests is a connectivity checks for the agent, it then consider that the backend is down, and does not try to send any data. In conequence, any assertion on agent side fails.
Changes
mocked_backend=True, starts a minimal asyncio TLS server on127.0.0.1:11112using the mitmproxy CA cert. It accepts connections and keeps them alive. Mitmproxy uses it purely to complete the TLS handshake leg; no actual data is forwarded through it.http_connect()hook: logs every CONNECT before any tunnel is established. For mocked agent flows, redirects theCONNECTdestination to the stub server and saves the original (host, port) in _original_connects, keyed byclient_conn.id.response(): restores the original (host, port) from _original_connects when building the saved JSON, so thefile correctly reflects the real backend destination rather than 127.0.0.1.
ssl_insecure=True(don't verify the stub server's self-signed cert) when in mocked mode.Workflow
🚀 Once your PR is reviewed and the CI green, you can merge it!
🛟 #apm-shared-testing 🛟
Reviewer checklist
tests/ormanifests/is modified ? I have the approval from R&P teambuild-XXX-imagelabel is present