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 several request/response headers in audit log entries #2121

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Store "openshift.io/request-header-accept", "openshift.io/request-hea…
…der-accept-encoding" and "openshift.io/request-header-content-length"
  • Loading branch information
vrutkovs committed Oct 22, 2024
commit 14b05bd6759918a8432483ccab74d0dfeee89280
2 changes: 1 addition & 1 deletion staging/src/k8s.io/apiserver/pkg/server/config.go
Original file line number Diff line number Diff line change
@@ -1104,7 +1104,7 @@ func DefaultBuildHandlerChain(apiHandler http.Handler, c *Config) http.Handler {
handler = genericfilters.WithWaitGroup(handler, c.LongRunningFunc, c.NonLongRunningRequestWaitGroup)
handler = WithNonReadyRequestLogging(handler, c.lifecycleSignals.HasBeenReady)
handler = WithLateConnectionFilter(handler)
handler = WithRequestHeaderHost(handler)
handler = WithRequestHeaders(handler)
if c.ShutdownWatchTerminationGracePeriod > 0 {
handler = genericfilters.WithWatchTerminationDuringShutdown(handler, c.lifecycleSignals, c.WatchRequestWaitGroup)
}
14 changes: 11 additions & 3 deletions staging/src/k8s.io/apiserver/pkg/server/patch_genericapiserver.go
Original file line number Diff line number Diff line change
@@ -217,11 +217,19 @@ func WithLateConnectionFilter(handler http.Handler) http.Handler {
})
}

// WithRequestHeaderHost logs every non-probe request and logs which host was used in request header.
func WithRequestHeaderHost(handler http.Handler) http.Handler {
// WithRequestHeaders logs every non-probe request and logs interesting request headers.
func WithRequestHeaders(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if pth := "/" + strings.TrimLeft(r.URL.Path, "/"); pth != "/readyz" && pth != "/healthz" && pth != "/livez" {
audit.AddAuditAnnotation(r.Context(), "openshift.io/request-header-host", r.Host)
if accept, ok := r.Header["Accept"]; ok {
audit.AddAuditAnnotation(r.Context(), "openshift.io/request-header-accept", strings.Join(accept, ","))
}
if accept_encoding, ok := r.Header["Accept-Encoding"]; ok {
audit.AddAuditAnnotation(r.Context(), "openshift.io/request-header-accept-encoding", strings.Join(accept_encoding, ","))
}
if content_length, ok := r.Header["Content-Length"]; ok {
audit.AddAuditAnnotation(r.Context(), "openshift.io/request-header-content-length", strings.Join(content_length, ","))
}
}
handler.ServeHTTP(w, r)
})