Skip to content

Commit 183531f

Browse files
tkashembertinatto
authored andcommitted
UPSTREAM: <carry>: annotate audit events for requests during unready phase and graceful termination phase
This reverts commit 85f0f2c. UPSTREAM: <carry>: fix request Host storing in openshift.io/during-graceful audit log annotation request URL doesn't contain the host used in the request, instead it should be fetched from request headers Note for rebase: squash it into the following commit vrutkovs@a83d289 UPSTREAM: <carry>: annotate audit events for requests during unready phase and graceful termination phase (#2077) When audit message is being processed https://github.com/openshift/kubernetes/blob/309f240e18f1da87bbe86c18746774d6d302f8ef/staging/src/k8s.io/apimachinery/pkg/util/proxy/transport.go#L136-L174 may strip `Host` from `r.URL`, however `r.Host` is always filled in. This value may be different for proxy requests, but in most cases `r.Host` should be used instead of `r.URL.Host`
1 parent 1d63680 commit 183531f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

staging/src/k8s.io/apiserver/pkg/server/patch_genericapiserver.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
corev1 "k8s.io/api/core/v1"
3333
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3434
"k8s.io/apimachinery/pkg/types"
35+
"k8s.io/apiserver/pkg/audit"
3536
v1 "k8s.io/client-go/kubernetes/typed/core/v1"
3637
"k8s.io/klog/v2"
3738
netutils "k8s.io/utils/net"
@@ -196,8 +197,10 @@ func WithLateConnectionFilter(handler http.Handler) http.Handler {
196197
if late {
197198
if pth := "/" + strings.TrimLeft(r.URL.Path, "/"); pth != "/readyz" && pth != "/healthz" && pth != "/livez" {
198199
if isLocal(r) {
200+
audit.AddAuditAnnotation(r.Context(), "openshift.io/during-graceful", fmt.Sprintf("loopback=true,%v,readyz=false", r.Host))
199201
klog.V(4).Infof("Loopback request to %q (user agent %q) through connection created very late in the graceful termination process (more than 80%% has passed). This client probably does not watch /readyz and might get failures when termination is over.", r.URL.Path, r.UserAgent())
200202
} else {
203+
audit.AddAuditAnnotation(r.Context(), "openshift.io/during-graceful", fmt.Sprintf("loopback=false,%v,readyz=false", r.Host))
201204
klog.Warningf("Request to %q (source IP %s, user agent %q) through a connection created very late in the graceful termination process (more than 80%% has passed), possibly a sign for a broken load balancer setup.", r.URL.Path, r.RemoteAddr, r.UserAgent())
202205

203206
// create only one event to avoid event spam.
@@ -234,9 +237,11 @@ func WithNonReadyRequestLogging(handler http.Handler, hasBeenReadySignal lifecyc
234237
if pth := "/" + strings.TrimLeft(r.URL.Path, "/"); pth != "/readyz" && pth != "/healthz" && pth != "/livez" {
235238
if isLocal(r) {
236239
if !isKubeApiserverLoopBack(r) {
240+
audit.AddAuditAnnotation(r.Context(), "openshift.io/unready", fmt.Sprintf("loopback=true,%v,readyz=false", r.URL.Host))
237241
klog.V(2).Infof("Loopback request to %q (user agent %q) before server is ready. This client probably does not watch /readyz and might get inconsistent answers.", r.URL.Path, r.UserAgent())
238242
}
239243
} else {
244+
audit.AddAuditAnnotation(r.Context(), "openshift.io/unready", fmt.Sprintf("loopback=false,%v,readyz=false", r.URL.Host))
240245
klog.Warningf("Request to %q (source IP %s, user agent %q) before server is ready, possibly a sign for a broken load balancer setup.", r.URL.Path, r.RemoteAddr, r.UserAgent())
241246

242247
// create only one event to avoid event spam.

0 commit comments

Comments
 (0)