Skip to content
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

Respect HTTP_PROXY/HTTPS_PROXY #10209

Merged
merged 42 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
72459fb
Add http proxy to web clients
atburke Feb 7, 2022
05fa8b5
Add tests
atburke Feb 8, 2022
37cd786
Reduce arg ambiguity
atburke Feb 9, 2022
e2df595
Make error assertions more specific
atburke Feb 9, 2022
8281dfc
Fix linting
atburke Feb 9, 2022
59088d7
Merge branch 'master' into atburke/tsh-https-proxy
atburke Feb 9, 2022
700abc2
Add messages to assertions
atburke Feb 9, 2022
d41122a
Change fake proxy address in tests
atburke Feb 9, 2022
d225e71
Add http proxy support for ssh
atburke Feb 10, 2022
810d958
Move proxy utils to api
atburke Feb 15, 2022
dd5e232
Add proxy-aware context dialer
atburke Feb 15, 2022
7981450
Fix incorrect address in makeProxySSHClient
atburke Feb 16, 2022
726297f
Merge branch 'master' into atburke/tsh-https-proxy
atburke Feb 19, 2022
1823b90
Merge branch 'master' into atburke/tsh-https-proxy
atburke Feb 22, 2022
f57114d
Merge branch 'master' into atburke/tsh-https-proxy
atburke Mar 1, 2022
ad44ccf
Add docs
atburke Mar 1, 2022
de6c715
Add NO_PROXY tests
atburke Mar 1, 2022
df6c5e2
Simplify bodyclose workaround
atburke Mar 2, 2022
bde8fb2
Stop caching env vars
atburke Mar 3, 2022
bbc3af7
Split makeProxySSHClient
atburke Mar 3, 2022
79e3f3f
Remove leftover teleport imports from api
atburke Mar 10, 2022
fcf43ee
Make dialALPNWithDeadline a member of directDial
atburke Mar 11, 2022
e24d3d0
Add DialProxyWithDialer for custom dialers
atburke Mar 11, 2022
749d889
Make tlsConfig mandatory
atburke Mar 14, 2022
4e2a20a
Bring back tlsRoutingEnabled flag
atburke Mar 14, 2022
cad2d6c
Move tls config configuration to its own function
atburke Mar 15, 2022
0edbc1d
Merge branch 'master' into atburke/tsh-https-proxy
atburke Mar 21, 2022
df2853e
Remove siddontang logger from proxy.go
atburke Mar 22, 2022
926f7bb
Merge branch 'master' into atburke/tsh-https-proxy
atburke Mar 22, 2022
23fdd82
Address review comments
atburke Mar 22, 2022
a94ce4b
Fix error message checks in tests
atburke Mar 22, 2022
dd2cb23
Fix missed url update
atburke Mar 22, 2022
2815f4c
Fix no_proxy value in tests
atburke Mar 22, 2022
5238d5a
Merge branch 'master' into atburke/tsh-https-proxy
atburke Mar 23, 2022
4f14ec4
Merge branch 'master' into atburke/tsh-https-proxy
atburke Mar 23, 2022
b343ff8
Tweak newWebClient arg description
atburke Mar 23, 2022
0774cc4
Merge branch 'atburke/tsh-https-proxy' of github.com:gravitational/te…
atburke Mar 23, 2022
b6dff62
Fix newWebClient signature in tests
atburke Mar 23, 2022
b861f75
Merge branch 'master' into atburke/tsh-https-proxy
atburke Mar 23, 2022
f5b3b71
Merge branch 'master' into atburke/tsh-https-proxy
atburke Mar 23, 2022
e127340
Merge branch 'master' into atburke/tsh-https-proxy
atburke Mar 23, 2022
76dfcbe
Merge branch 'master' into atburke/tsh-https-proxy
atburke Mar 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/client/webclient/webclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func newWebClient(insecure bool, pool *x509.CertPool) *http.Client {
RootCAs: pool,
InsecureSkipVerify: insecure,
},
Proxy: http.ProxyFromEnvironment,
},
}
}
Expand Down
10 changes: 10 additions & 0 deletions api/client/webclient/webclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net"
"net/http"
"net/http/httptest"
"os"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -289,3 +290,12 @@ func TestExtract(t *testing.T) {
})
}
}

func TestNewWebClientRespectHTTPProxy(t *testing.T) {
atburke marked this conversation as resolved.
Show resolved Hide resolved
os.Setenv("HTTPS_PROXY", "localhost:9999")
atburke marked this conversation as resolved.
Show resolved Hide resolved
defer os.Unsetenv("HTTPS_PROXY")
client := newWebClient(false, nil)
atburke marked this conversation as resolved.
Show resolved Hide resolved
_, err := client.Get("https://example.com")
// Client should try to proxy through nonexistent server at localhost.
require.Error(t, err)
atburke marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 2 additions & 0 deletions lib/client/https_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func NewInsecureWebClient() *http.Client {
return &http.Client{
Transport: &http.Transport{
TLSClientConfig: tlsConfig,
Proxy: http.ProxyFromEnvironment,
},
}
}
Expand All @@ -54,6 +55,7 @@ func newClientWithPool(pool *x509.CertPool) *http.Client {
return &http.Client{
Transport: &http.Transport{
TLSClientConfig: tlsConfig,
Proxy: http.ProxyFromEnvironment,
},
}
}
Expand Down
42 changes: 42 additions & 0 deletions lib/client/https_client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright 2022 Gravitational, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package client

import (
"os"
"testing"

"github.com/stretchr/testify/require"
)

func TestNewInsecureWebClientHTTPProxy(t *testing.T) {
os.Setenv("HTTPS_PROXY", "localhost:9999")
defer os.Unsetenv("HTTPS_PROXY")
client := NewInsecureWebClient()
_, err := client.Get("https://example.com")
// Client should try to proxy through nonexistent server at localhost.
require.Error(t, err)
atburke marked this conversation as resolved.
Show resolved Hide resolved
}

func TestNewClientWithPoolHTTPProxy(t *testing.T) {
atburke marked this conversation as resolved.
Show resolved Hide resolved
os.Setenv("HTTPS_PROXY", "localhost:9999")
defer os.Unsetenv("HTTPS_PROXY")
client := newClientWithPool(nil)
_, err := client.Get("https://example.com")
// Client should try to proxy through nonexistent server at localhost.
require.Error(t, err)
atburke marked this conversation as resolved.
Show resolved Hide resolved
}