SaltDnsWeb.Plugs.RemoteIp (Salt v1.0.0)

Replaces conn.remote_ip with the client address a trusted reverse proxy reports (SaltDns.ProxyIP), so the rate limits and the audit trail see clients, not the proxy.

config :salt_dns, SaltDnsWeb.Plugs.RemoteIp,
  trusted_proxies: ["10.0.0.0/8", "fd00::/8"],
  header: "x-forwarded-for"

(SALT_DNS_TRUSTED_PROXIES and SALT_DNS_CLIENT_IP_HEADER in production.) With no trusted proxies configured, which is the default, this does nothing. It runs first in the endpoint, before anything counts or logs the address.

Summary

Functions

The client address of a request, worked out again from the peer address the server saw and the request's headers, whatever conn.remote_ip holds now. For the Shaker endpoints, which store it: same trusted-proxy rules as the plug, and an IPv4-mapped address comes out as plain IPv4.

The client address for a connection from remote_ip; headers.(name) reads a request header (lower-case name) as a list of values. Also used for WebSocket connections (connect_info), which do not pass through the plug.

Functions

client_ip(conn)

@spec client_ip(Plug.Conn.t()) :: :inet.ip_address()

The client address of a request, worked out again from the peer address the server saw and the request's headers, whatever conn.remote_ip holds now. For the Shaker endpoints, which store it: same trusted-proxy rules as the plug, and an IPv4-mapped address comes out as plain IPv4.

resolve(remote_ip, headers)

@spec resolve(:inet.ip_address(), (String.t() -> [String.t()])) :: :inet.ip_address()

The client address for a connection from remote_ip; headers.(name) reads a request header (lower-case name) as a list of values. Also used for WebSocket connections (connect_info), which do not pass through the plug.