Skip to content

Commit

Permalink
aws: Fix proxy dial to pick all proxies
Browse files Browse the repository at this point in the history
The current proxy dial function does not consider proxy
information provided in some environment variables like
http_proxy etc when checking if the service principal
provided is reachable. Adding a function that checks a few
env variables and dials the service to see if it is reachable.
  • Loading branch information
rna-afk committed Mar 28, 2022
1 parent af9c1b8 commit 250dcdb
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions pkg/asset/installconfig/aws/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net"
"net/http"
"net/url"
"sort"
"strings"
Expand Down Expand Up @@ -329,12 +330,26 @@ func validateEndpointAccessibility(endpointURL string) error {
if port == "" {
port = "https"
}
conn, err := proxy.Dial(context.Background(), "tcp", net.JoinHostPort(URL.Hostname(), port))
if err != nil {
return err
err = dialURL(context.Background(), net.JoinHostPort(URL.Hostname(), port))
return err
}

func dialURL(ctx context.Context, URL string) error {
// DefaultClient picks the http and https proxy environment variables.
req, err := http.NewRequestWithContext(context.Background(), "CONNECT", URL, nil)
if err == nil {
_, err := http.DefaultClient.Do(req)
if err == nil {
return nil
}
}
// Proxy Dial picks up the ALL_PROXY environment variable and handles sock5 proxy dialing to URL.
conn, err := proxy.Dial(context.Background(), "tcp", URL)
if err == nil {
conn.Close()
return nil
}
conn.Close()
return nil
return err
}

var requiredServices = []string{
Expand Down

0 comments on commit 250dcdb

Please sign in to comment.