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 <[email protected]>
This commit is contained in:
chaosinthecrd authored and Tom Meadows committed 2026-11-12 17:21:23 +00:00
1 parent 2e6fcb4f60
commit 85cbfeef38
1 file changed
+1 -17
+1 -17
View File
@@ -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) {