fix(logging): attribute request logs to the external client IP #334
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/BUNYIP-328-log-external-client-ip"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The actix access
Logger::default()logs%a, the immediate socket peer. Behind Traefik that is the reverse proxy's internal IP, so every request line was attributed to the proxy rather than the client that made the request, making errors hard to trace back to a specific caller.Add
access_log::access_logger(), aLoggerwhose client field is resolved byextract_client_ip, which honours the proxy'sX-Forwarded-For(thenX-Real-IP) only when the socket peer is a configured trusted proxy (TRUSTED_PROXY_CIDR). This is the same trusted resolution the rate-limit records already use, so request-log lines and rate-limit entries now point at the same external client. Wire it into both the primary app and the OCI registry server in place ofLogger::default().Factor the trusted-proxy logic out of
extract_client_ipinto a pureresolve_client_ip(peer, xff, real_ip, trusted_proxies)so it is unit-testable without an actix request, and add tests proving a request forwarded by a trusted proxy resolves to the external client in XFF (not the proxy/internal IP) while a forged XFF from an untrusted peer is ignored.#BUNYIP-328