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 29, 2022
1 parent af9c1b8 commit 82d8d7b
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 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,25 @@ 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.
_, err := http.Get(URL)
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 {
if conn != nil {
conn.Close()
}
return nil
}
conn.Close()
return nil
return err
}

var requiredServices = []string{
Expand Down

0 comments on commit 82d8d7b

Please sign in to comment.