Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add path to auth proxy logs #34

Merged
merged 1 commit into from
Jul 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,30 @@ func proxyHandler(logger logr.Logger, proxies map[string]*httputil.ReverseProxy,
return
}

handlerLogger := logger.WithValues("path", r.URL.Path)

// Check basic auth with local auth configuration
err = authz.IsPermitted(r.URL.EscapedPath(), token)
if err != nil {
logger.Error(err, "Received unauthorized request")
handlerLogger.Error(err, "Received unauthorized request")
http.Error(w, "User not permitted", http.StatusForbidden)
return
}
pat, err := authz.GetPatForToken(token)
if err != nil {
logger.Error(err, "Could not find the PAT for the given token")
handlerLogger.Error(err, "Could not find the PAT for the given token")
http.Error(w, "Internal server error", http.StatusInternalServerError)
return
}
target, err := authz.GetTargetForToken(token)
if err != nil {
logger.Error(err, "Target could not be created from the token")
handlerLogger.Error(err, "Target could not be created from the token")
http.Error(w, "Internal server error", http.StatusInternalServerError)
return
}

// Overwrite the authorization header with the PAT token
logger.Info("Authenticated request", "path", r.URL.Path)
handlerLogger.Info("Authenticated request")
r.Host = target.Host
r.Header.Del("Authorization")
patB64 := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("pat:%s", pat)))
Expand All @@ -100,7 +102,7 @@ func proxyHandler(logger logr.Logger, proxies map[string]*httputil.ReverseProxy,
// Forward the request to the correct proxy
proxy, ok := proxies[target.String()]
if !ok {
logger.Info("missing proxy for target")
handlerLogger.Info("missing proxy for target")
http.Error(w, "Internal server error", http.StatusInternalServerError)
return
}
Expand Down