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.
This is the same PR than #225, had to re-open because the build process is broken when sending test coverage.
Description
This PR adds MITM support:
I've also:
Development.md
which now includes instructions on how to run locally for multiple scenarios:.vscode/launch.json
to allow debugging easily in Vscodeconfig *Config
argument fromlogProxy
as it was un-usedextractContextLogFields
are added to accommodate the MITM codepctx.RoundTripper
which is normally used forhttp
proxy request is now also used by the MITM outbound request. By default it pools requests and keep them idle for a short period of time to potentially re-use. (even whenResponse.Body.Close()
is run) This doesn't work well withInstrumentedConn
that logsCANONICAL-PROXY-CN-CLOSE
once the connection is closed.There are multiple ways to go around this but I chose to run
proxy.Tr.CloseIdleConnections
as thiscloses any connections which were previously connected from previous requests but are now sitting idle in a "keep-alive" state
. This proxy is not primarily intended to support browser traffic and the performance gain of keeping this connection is negligible for our use-case.Alternatives considered:
req.Header.Set("Connection", "close")
would work but the header is wiped in goproxy which calls removeProxyHeaders which deletes the Connection header.Testing
I have added automated tests for ACL and the whole MITM flow.
HTTP Proxy (happy path) ✅
See set-up from Development.md HTTP Proxy)
HTTP CONNECT Proxy (happy path) ✅
See set-up from Development.md HTTP CONNECT Proxy)
HTTP CONNECT Proxy over TLS (happy path) ✅
See set-up from Development.md HTTP CONNECT Proxy over TLS)
MITM (Man in the middle) Proxy (happy path) ✅
See set-up from Development.md MITM (Man in the middle) Proxy)
Accept-Language: el
was correctly sentNotice the
mitm_req_headers
,mitm_req_method
andmitm_req_url
fieldsMITM (Man in the middle) Proxy over TLS (happy path) ✅
See set-up from Development.md MITM (Man in the middle) Proxy over TLS)
Accept-Language: el
was correctly sent (weather is in Greek)Notice the
mitm_req_headers
,mitm_req_method
,mitm_req_url
(MITM),inbound_remote_x509_cn
andinbound_remote_x509_ou
(TLS) fields.MITM config not configured with ACL configured ✅
Miss-configuration fails gracefully