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 24, 2022
1 parent af9c1b8 commit 45bb469
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 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,28 @@ 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 = proxyDialURL(context.Background(), net.JoinHostPort(URL.Hostname(), port))
return err
}

func proxyDialURL(ctx context.Context, URL string) error {
conn, err := proxy.Dial(context.Background(), "tcp", URL)
if err == nil {
conn.Close()
return nil
}
// DefaultClient picks the http and https proxy environment variables.
req, err := http.NewRequestWithContext(context.Background(), "CONNECT", URL, nil)
if err == nil {
resp, err := http.DefaultClient.Do(req)
if err == nil {
if resp.StatusCode == 200 {
return nil
}
return fmt.Errorf("error reaching service endpoint %s: %s", URL, resp.Status)
}
}
conn.Close()
return nil
return err
}

var requiredServices = []string{
Expand Down

0 comments on commit 45bb469

Please sign in to comment.