From 751454595e56a3158ceaec304f491b496b56beec Mon Sep 17 00:00:00 2001 From: hc-github-team-consul-core Date: Wed, 28 Feb 2024 03:55:09 -0500 Subject: [PATCH] Backport of Fix audit-log encoding issue (CC-7337) into release/1.18.x (#20749) Fix audit-log encoding issue (CC-7337) (#20345) * add changes * added changelog * change update * CE chnages * Removed gzip size fix * fix changelog * Update .changelog/20345.txt * Adding comments --------- Co-authored-by: Ashesh Vidyut <134911583+absolutelightning@users.noreply.github.com> Co-authored-by: Abhishek Sahu Co-authored-by: Hans Hasselberg Co-authored-by: srahul3 --- .changelog/20345.txt | 3 +++ agent/http.go | 5 +++-- agent/http_ce.go | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 .changelog/20345.txt diff --git a/.changelog/20345.txt b/.changelog/20345.txt new file mode 100644 index 0000000000..b2fcc5271f --- /dev/null +++ b/.changelog/20345.txt @@ -0,0 +1,3 @@ +```release-note:bug + audit-logs: **(Enterprise Only)** Fixes non ASCII characters in audit logs because of gzip. +``` diff --git a/agent/http.go b/agent/http.go index 34a92cecd5..d828ed04c1 100644 --- a/agent/http.go +++ b/agent/http.go @@ -188,7 +188,9 @@ func (s *HTTPHandlers) handler() http.Handler { // Register the wrapper. wrapper := func(resp http.ResponseWriter, req *http.Request) { start := time.Now() - handler(resp, req) + + // this method is implemented by different flavours of consul e.g. oss, ce. ent. + s.enterpriseRequest(resp, req, handler) labels := []metrics.Label{{Name: "method", Value: req.Method}, {Name: "path", Value: path_label}} metrics.MeasureSinceWithLabels([]string{"api", "http"}, start, labels) @@ -313,7 +315,6 @@ func (s *HTTPHandlers) handler() http.Handler { h = mux } - h = s.enterpriseHandler(h) h = withRemoteAddrHandler(h) s.h = &wrappedMux{ mux: mux, diff --git a/agent/http_ce.go b/agent/http_ce.go index da6bef7237..0259dc738f 100644 --- a/agent/http_ce.go +++ b/agent/http_ce.go @@ -95,9 +95,9 @@ func parseACLAuthMethodEnterpriseMeta(req *http.Request, _ *structs.ACLAuthMetho return nil } -// enterpriseHandler is a noop for the enterprise implementation. we pass the original back -func (s *HTTPHandlers) enterpriseHandler(next http.Handler) http.Handler { - return next +func (s *HTTPHandlers) enterpriseRequest(w http.ResponseWriter, req *http.Request, handler func(http.ResponseWriter, *http.Request)) { + // no special handling for CE. Calling the default handler with default params. + handler(w, req) } // uiTemplateDataTransform returns an optional uiserver.UIDataTransform to allow