diff --git a/authn/authn.go b/authn/authn.go index 28b1c6a4e8..7b53694bdd 100644 --- a/authn/authn.go +++ b/authn/authn.go @@ -30,6 +30,14 @@ import ( func GetAuthenticationHeaders(ctx context.Context, endpoint *url.URL, authenticators map[string]string) (http.Header, error) { logger := log.FromContext(ctx).Scope(endpoint.Hostname()) + // Next, try the authenticator. + logger.Debugf("Trying authenticator") + authenticator, ok := authenticators[endpoint.Hostname()] + if !ok { + logger.Tracef("No authenticator found for %s in %s", endpoint, authenticators) + return nil, nil + } + endpoint = &url.URL{ Scheme: endpoint.Scheme, Host: endpoint.Host, @@ -60,14 +68,6 @@ func GetAuthenticationHeaders(ctx context.Context, endpoint *url.URL, authentica } } - // Next, try the authenticator. - logger.Debugf("Trying authenticator") - authenticator, ok := authenticators[endpoint.Hostname()] - if !ok { - logger.Tracef("No authenticator found in %s", authenticators) - return nil, nil - } - cmd := exec.Command(ctx, log.Error, ".", authenticator, endpoint.String()) out := &strings.Builder{} cmd.Stdout = out @@ -152,6 +152,9 @@ func checkAuth(ctx context.Context, logger *log.Logger, endpoint *url.URL, creds // Transport returns a transport that will authenticate requests to the given endpoints. func Transport(next http.RoundTripper, authenticators map[string]string) http.RoundTripper { + if len(authenticators) == 0 { + return next + } return &authnTransport{ authenticators: authenticators, credentials: map[string]http.Header{}, diff --git a/go.mod b/go.mod index acd4c3612f..5cfae57c5f 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( connectrpc.com/connect v1.11.1 github.com/BurntSushi/toml v1.3.2 - github.com/alecthomas/kong v0.8.0 + github.com/alecthomas/kong v0.8.1 github.com/alecthomas/kong-toml v0.0.0-20230922031405-31cfb1264a3b github.com/go-logr/logr v1.2.4 github.com/golang/protobuf v1.5.3 diff --git a/go.sum b/go.sum index 15fa11954c..b4cb5d8dee 100644 --- a/go.sum +++ b/go.sum @@ -16,6 +16,8 @@ github.com/alecthomas/errors v0.4.0 h1:zDIapqdw7gVx2BrQpw3Ll5YRGFuaiB0ywcjesqT0R github.com/alecthomas/errors v0.4.0/go.mod h1:0DQf6/xQp3f9rv+k72g2NmeTW2lC74kXA6b/8dN9BwY= github.com/alecthomas/kong v0.8.0 h1:ryDCzutfIqJPnNn0omnrgHLbAggDQM2VWHikE1xqK7s= github.com/alecthomas/kong v0.8.0/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U= +github.com/alecthomas/kong v0.8.1 h1:acZdn3m4lLRobeh3Zi2S2EpnXTd1mOL6U7xVml+vfkY= +github.com/alecthomas/kong v0.8.1/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U= github.com/alecthomas/kong-toml v0.0.0-20230922031405-31cfb1264a3b h1:A+PJz+8ULrnKZJYNwaefLGcXwAy5mnv0eD9zsx0PdYc= github.com/alecthomas/kong-toml v0.0.0-20230922031405-31cfb1264a3b/go.mod h1:d0aHX/kbCSdgQSg7ZUQzSTbBCh02sjSu8RT3YF2TKzA= github.com/alecthomas/participle/v2 v2.0.0 h1:Fgrq+MbuSsJwIkw3fEj9h75vDP0Er5JzepJ0/HNHv0g=