Skip to content

Set extra proxy headers in all tsh HTTP requests#19766

Merged
vitorenesduarte merged 30 commits into
masterfrom
vitor/extra-proxy-headers
Jan 11, 2023
Merged

Set extra proxy headers in all tsh HTTP requests#19766
vitorenesduarte merged 30 commits into
masterfrom
vitor/extra-proxy-headers

Conversation

@vitorenesduarte
Copy link
Copy Markdown
Contributor

Fixes #16541.

Before this commit, the tsh HTTP requests that had the extra headers were those that did not use roundtrip.
This commit leverages http.RoundTripper.RoundTrip to ensure that all requests have the the extra headers.

Before this commit, the `tsh` HTTP requests that had the extra headers
were those that did not use `roundtrip`.
This commit leverages `http.RoundTripper.RoundTrip` to ensure that all
requests have the the extra headers.
Copy link
Copy Markdown
Contributor

@ibeckermayer ibeckermayer left a comment

Choose a reason for hiding this comment

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

Some tests testing the logic of whether requests get downgraded or not would be nice.

Also try a grep -rn NewInsecureWebClient\(\), there seem to be some stragglers left over.

Comment thread api/client/proxy/proxy.go
Comment thread api/client/proxy/proxy.go Outdated
Comment thread lib/client/weblogin.go Outdated
Comment thread lib/client/weblogin.go Outdated
Vitor Enes and others added 3 commits January 4, 2023 19:07
Co-authored-by: Isaiah Becker-Mayer <isaiah@goteleport.com>
@vitorenesduarte vitorenesduarte force-pushed the vitor/extra-proxy-headers branch from 9f71114 to 0107a14 Compare January 4, 2023 21:56
@vitorenesduarte
Copy link
Copy Markdown
Contributor Author

Thanks for the review @ibeckermayer. Could you please take another look?

Some tests testing the logic of whether requests get downgraded or not would be nice.

I improved existing tests and added new ones in 9641dd1.

Also try a grep -rn NewInsecureWebClient\(\), there seem to be some stragglers left over.

Thanks. I've added NewInsecureWebClient back.

Comment thread api/client/proxy/proxy.go Outdated
Comment thread lib/client/weblogin_test.go Outdated
Comment thread lib/client/weblogin_test.go Outdated
defer httpSvr.Close()
// TestHttpRoundTripperDowngrade tests that the round tripper downgrades https requests to http
// when HTTP_PROXY is set to "http://localhost:*" (i.e. there's an http proxy running on localhost).
func TestHttpRoundTripperDowngrade(t *testing.T) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I get that this is testing the HttpRoundTripper under the hood, however its bad practice to write tests for one package in another. For example, consider if we swap out the underlying transport mechanism in SSHAgentLogin. Now this test is bunk, and might just get deleted. At the very least, we would need to rewrite it to test HTTPRoundTripper in its own package at that point.

Another reason this is bad practice is that tests are a form of documentation. If somebody wants to use HTTPRoundTripper for something else, it's best that the tests testing its core behavior are close by so they can see how it works.

I would say move these comprehensive tests of HTTPRoundTripper's behavior close to TestProxyAwareRoundTripper. And if you think its worthwhile to also have unit tests ensuring this behavior for client.SSHAgentLogin and client.HostCredentials, then add those to the client package.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. Moved the tests in 451646b.

@vitorenesduarte vitorenesduarte enabled auto-merge (squash) January 11, 2023 10:16
@vitorenesduarte vitorenesduarte merged commit d72ac18 into master Jan 11, 2023
@github-actions
Copy link
Copy Markdown
Contributor

@vitorenesduarte See the table below for backport results.

Branch Result
branch/v10 Failed
branch/v11 Failed
branch/v9 Failed

@vitorenesduarte
Copy link
Copy Markdown
Contributor Author

vitorenesduarte commented Jan 11, 2023

Manually backported to v11: #20071
Manually backporting to < v11 resulted in conflicts due to #15874 not being on those branches.

UPDATE:
Manually backported to v10: #20111

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom header is not added in http2

3 participants