diff options
author | Francis Lavoie <[email protected]> | 2023-03-27 16:22:59 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2023-03-27 20:22:59 +0000 |
commit | 05e9974570a08df14b1162a1e98315d4ee9ec2ee (patch) | |
tree | e11e345766dc53c25f901a7402ceb489b4416fe9 /caddyconfig/httpcaddyfile/serveroptions.go | |
parent | 330be2d8c793147d3914f944eecb96c18f2eabff (diff) | |
download | caddy-05e9974570a08df14b1162a1e98315d4ee9ec2ee.tar.gz caddy-05e9974570a08df14b1162a1e98315d4ee9ec2ee.zip |
caddyhttp: Determine real client IP if trusted proxies configured (#5104)
* caddyhttp: Determine real client IP if trusted proxies configured
* Support customizing client IP header
* Implement client_ip matcher, deprecate remote_ip's forwarded option
Diffstat (limited to 'caddyconfig/httpcaddyfile/serveroptions.go')
-rw-r--r-- | caddyconfig/httpcaddyfile/serveroptions.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/caddyconfig/httpcaddyfile/serveroptions.go b/caddyconfig/httpcaddyfile/serveroptions.go index eb57c58cb..f4274eabd 100644 --- a/caddyconfig/httpcaddyfile/serveroptions.go +++ b/caddyconfig/httpcaddyfile/serveroptions.go @@ -44,6 +44,7 @@ type serverOptions struct { Protocols []string StrictSNIHost *bool TrustedProxiesRaw json.RawMessage + ClientIPHeaders []string ShouldLogCredentials bool Metrics *caddyhttp.Metrics } @@ -208,6 +209,18 @@ func unmarshalCaddyfileServerOptions(d *caddyfile.Dispenser) (any, error) { ) serverOpts.TrustedProxiesRaw = jsonSource + case "client_ip_headers": + headers := d.RemainingArgs() + for _, header := range headers { + if sliceContains(serverOpts.ClientIPHeaders, header) { + return nil, d.Errf("client IP header %s specified more than once", header) + } + serverOpts.ClientIPHeaders = append(serverOpts.ClientIPHeaders, header) + } + if nesting := d.Nesting(); d.NextBlock(nesting) { + return nil, d.ArgErr() + } + case "metrics": if d.NextArg() { return nil, d.ArgErr() @@ -317,6 +330,7 @@ func applyServerOptions( server.Protocols = opts.Protocols server.StrictSNIHost = opts.StrictSNIHost server.TrustedProxiesRaw = opts.TrustedProxiesRaw + server.ClientIPHeaders = opts.ClientIPHeaders server.Metrics = opts.Metrics if opts.ShouldLogCredentials { if server.Logs == nil { |