Documentation
¶
Overview ¶
Package clientaddr is the ONE reading of "which address is this request from". Every per-address limit, every address forwarded to GoTrue (X-Muster-Client-IP), every audit row and log line that names a client takes it from here (Of), in muster-server and in muster-preview alike.
🔴 THE DEFAULT TRUSTS NOTHING. The answer is the TCP peer of the connection, whatever the request's headers say, on every listener. A forwarding header (CF-Connecting-IP, X-Forwarded-For, X-Real-IP) is something any client can type, and a plain reverse proxy passes most of them through unchanged, so a header is believed ONLY when the TCP peer is inside a configured trusted range (MUSTER_TRUSTED_PROXIES) — and then only the one header the operator named (MUSTER_CLIENT_IP_HEADER).
🔴 X-Forwarded-For IS READ FROM THE RIGHT. Each proxy APPENDS the address it received the request from, so the right-most entries are the ones written by proxies, and the left-most is whatever the client sent. The client is the first entry, walking from the right, that is NOT a trusted proxy. The left-most entry is used only when every entry is trusted.
⚠ THAT IS SAFE ONLY BEHIND A PROXY THAT APPENDS. A proxy that forwards the client's X-Forwarded-For untouched (nginx with a bare proxy_pass) leaves a client-typed value right-most, and no reading of the header can undo that: such a proxy must name the client in a header it OVERWRITES (X-Real-IP) or append it ($proxy_add_x_forwarded_for). docs/configuration.md has the recipes.
The package is a leaf: the standard library only.
Index ¶
Constants ¶
const ( HeaderCFConnectingIP = "CF-Connecting-IP" HeaderXForwardedFor = "X-Forwarded-For" HeaderXRealIP = "X-Real-IP" )
The headers MUSTER_CLIENT_IP_HEADER may name, in their canonical spelling.
const Unknown = "unknown"
Unknown is the address of a request whose TCP peer does not parse (never a real network connection; a test's hand-made RemoteAddr).
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// TrustedProxies is the comma-separated CIDR list (a bare address is a
// single host). Empty trusts nothing.
TrustedProxies string
// Header is the header a trusted peer names the client in: one of the
// Header* constants, case-insensitive. Empty with TrustedProxies empty.
Header string
TrustedVar, HeaderVar string
}
Config is what New reads. The two *Var names are only for messages, so the same code serves muster-server (MUSTER_*) and muster-preview (PREVIEW_*).
type Policy ¶
type Policy struct {
// contains filtered or unexported fields
}
Policy decides a request's client address. A nil *Policy is the strict default: the TCP peer, always.
func New ¶
New parses c. Both settings or neither: a header with no trusted range would never be read, and a trusted range with no header would believe nothing, and either is a configuration that silently does not do what it says.
func (*Policy) Middleware ¶
Middleware resolves each request's client address once, with p, and carries it on the request for Of.
func (*Policy) Resolve ¶
Resolve is the client address of r: the TCP peer, unless the peer is a trusted proxy, in which case the configured header's client (validated; the peer when the header is absent or does not parse). Always a canonical IP string, or Unknown.