Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Commit

Permalink
Disable OIDC Keep-Alive and instantiate client once
Browse files Browse the repository at this point in the history
This should reduce file-descriptor leaks.
  • Loading branch information
IljaN committed May 29, 2020
1 parent f33b678 commit eaa27ca
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions pkg/middleware/openidconnect.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ func OpenIDConnect(opts ...ocisoidc.Option) func(next http.Handler) http.Handler
opt.SigningAlgs = []string{"RS256", "PS256"}
}

var oidcHTTPClient = &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: opt.Insecure,
},
DisableKeepAlives: true,
},
Timeout: time.Second * 10,
}
var oidcProvider *oidc.Provider

return func(next http.Handler) http.Handler {
Expand All @@ -62,17 +71,7 @@ func OpenIDConnect(opts ...ocisoidc.Option) func(next http.Handler) http.Handler
return
}

token := header[7:]
customHTTPClient := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: opt.Insecure,
},
},
Timeout: time.Second * 10,
}

customCtx := context.WithValue(r.Context(), oauth2.HTTPClient, customHTTPClient)
customCtx := context.WithValue(r.Context(), oauth2.HTTPClient, oidcHTTPClient)

// use cached provider
if oidcProvider == nil {
Expand All @@ -92,6 +91,8 @@ func OpenIDConnect(opts ...ocisoidc.Option) func(next http.Handler) http.Handler
// The claims we want to have
var claims ocisoidc.StandardClaims

token := header[7:]

// TODO cache userinfo for access token if we can determine the expiry (which works in case it is a jwt based access token)
oauth2Token := &oauth2.Token{
AccessToken: token,
Expand Down

0 comments on commit eaa27ca

Please sign in to comment.