diff options
| author | Max Resnick <max@ofmax.li> | 2024-04-23 22:20:11 -0700 |
|---|---|---|
| committer | Max Resnick <max@ofmax.li> | 2024-04-23 22:20:11 -0700 |
| commit | 37666883a6b90f811f40fc6bf622a89165981df5 (patch) | |
| tree | bfec5850a18d28fddc5adcef1abb530f4c42125a /internal | |
| parent | 948a7398906cb8aba21b5538f7b6906a6aa1df96 (diff) | |
| download | go-git-server-37666883a6b90f811f40fc6bf622a89165981df5.tar.gz | |
feat: light access logging
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/authz/middleware.go | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/internal/authz/middleware.go b/internal/authz/middleware.go index 9031c99..f4838ec 100644 --- a/internal/authz/middleware.go +++ b/internal/authz/middleware.go @@ -21,6 +21,7 @@ var ( func Authentication(authMap TokenMap, next http.Handler) http.Handler { return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { + slog.Info("access request recv") u, p, ok := req.BasicAuth() if !ok { rw.Header().Set("WWW-Authenticate", `Basic realm="git"`) @@ -30,6 +31,7 @@ func Authentication(authMap TokenMap, next http.Handler) http.Handler { urn := fmt.Sprintf("uid:%s", u) hash, ok := authMap[urn] if !ok { + slog.Info("failed access", "urn", urn) http.Error(rw, "Bad Request", http.StatusForbidden) return } @@ -39,10 +41,12 @@ func Authentication(authMap TokenMap, next http.Handler) http.Handler { return } if err := bcrypt.CompareHashAndPassword([]byte(hash), token); err != nil { + slog.Info("bad token for user", "urn", urn) http.Error(rw, "Bad Request", http.StatusForbidden) return } ctx := context.WithValue(req.Context(), AuthzUrnKey, urn) + slog.Info("access request granted", "urn", urn) next.ServeHTTP(rw, req.WithContext(ctx)) }) } |