From 85cbfeef382fa1fefa40dc9ccd2a578a2430dc62 Mon Sep 17 00:00:00 2001 From: chaosinthecrd Date: Tue, 10 Nov 2026 19:56:42 +0000 Subject: [PATCH] k8s-operator/api-proxy: only use the remote address for WhoIs whoIs fell back to the X-Forwarded-For header when WhoIs on the request's remote address failed (only when serving over plain HTTP, as cmd/k8s-proxy does). That header comes from the client, so the identity could come from the request instead of the connection. This fixes this by removing the fallback, so whoIs only uses the connection's remote address. It also asks for TCP only, as the proxy only serves TCP, so a miss does not also try UDP. Updates tailscale/corp#51000 Thank you Emilio Mendoza @a3l6 for reporting Signed-off-by: chaosinthecrd --- k8s-operator/api-proxy/proxy.go | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/k8s-operator/api-proxy/proxy.go b/k8s-operator/api-proxy/proxy.go index 47a65d17b..7e72d09a4 100644 --- a/k8s-operator/api-proxy/proxy.go +++ b/k8s-operator/api-proxy/proxy.go @@ -472,23 +472,7 @@ func (ap *APIServerProxy) addImpersonationHeadersAsRequired(r *http.Request) { } func (ap *APIServerProxy) whoIs(r *http.Request) (*apitype.WhoIsResponse, error) { - who, remoteErr := ap.lc.WhoIs(r.Context(), r.RemoteAddr) - if remoteErr == nil { - ap.log.Debugf("WhoIs from remote addr: %s", r.RemoteAddr) - return who, nil - } - - var fwdErr error - fwdFor := r.Header.Get("X-Forwarded-For") - if fwdFor != "" && !ap.https { - who, fwdErr = ap.lc.WhoIs(r.Context(), fwdFor) - if fwdErr == nil { - ap.log.Debugf("WhoIs from X-Forwarded-For header: %s", fwdFor) - return who, nil - } - } - - return nil, errors.Join(remoteErr, fwdErr) + return ap.lc.WhoIsProto(r.Context(), "tcp", r.RemoteAddr) } func (ap *APIServerProxy) authError(w http.ResponseWriter, err error) {