Skip to content

Commit

Permalink
pkg/server/middleware: fix invalid project ID errors in logs
Browse files Browse the repository at this point in the history
don't attempt to parse an invalid public project ID like "-"
if no credentials are present, or if there's an empty string
returned from authservice. If authservice produces an empty
UUID (string as all zeros) then it's still valid and won't
cause any problems.

Change-Id: I6ae5a14d0500397f312694b3afc7a8ce41e95c29
  • Loading branch information
halkyon committed Aug 20, 2024
1 parent 7ae6c2c commit c30af4a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions pkg/server/middleware/access_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,17 @@ func AccessLog(log *zap.Logger, p *accesslogs.Processor, config AccessLogConfig)

h.ServeHTTP(w, r)

logEntry := extractLogEntry(r, rw, startTime, gl)
credentials := GetAccess(r.Context())
var publicProjectID string
if credentials == nil {
publicProjectID = "-"
} else {
credentials := GetAccess(r.Context())
if credentials != nil {
publicProjectID = credentials.PublicProjectID
}

if publicProjectID == "" {
return
}

logEntry := extractLogEntry(r, rw, startTime, gl)
processLogEntry(log, p, config, publicProjectID, gl.BucketName, &logEntry)
}))
}
Expand Down Expand Up @@ -215,7 +218,9 @@ func extractLogEntry(r *http.Request, rw whmon.ResponseWriter, startTime time.Ti
func processLogEntry(log *zap.Logger, p *accesslogs.Processor, config AccessLogConfig, publicProjectID, bucketName string, logEntry *accesslogs.S3AccessLogEntry) {
parsedPublicProjectID, err := uuid.FromString(publicProjectID)
if err != nil {
log.Error("Error parsing public project ID from authservice", zap.Error(err))
log.Error("Error parsing public project ID from authservice",
zap.Error(err),
zap.String("publicProjectID", publicProjectID))
return
}

Expand Down

0 comments on commit c30af4a

Please sign in to comment.