-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor X-Forwarded-* headers #1381
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f38f49e
Refactor X-Forwarded-* headers
aledbf 669428e
Merge remote-tracking branch 'master/master' into refactor-template-h…
aledbf df57b8b
1
aledbf d73edb8
Merge remote-tracking branch 'master/master' into refactor-template-h…
aledbf 6ee2b72
Fix template mappings
aledbf 78e166f
Fix cast error
aledbf 3ed6019
Merge remote-tracking branch 'master/master' into refactor-template-h…
aledbf db12b51
Fix identation
aledbf fe2386b
Cleanup
aledbf b1b75f9
Rollback change in docker image
aledbf f549e03
Fix remote address
aledbf f253d24
Cleanup
aledbf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,27 +151,54 @@ http { | |
'' close; | ||
} | ||
|
||
{{ if (trustHTTPHeaders $all) }} | ||
# Trust HTTP X-Forwarded-* Headers, but use direct values if they're missing. | ||
map {{ buildForwardedFor $cfg.ForwardedForHeader }} $the_real_ip { | ||
# Get IP address from X-Forwarded-For HTTP header | ||
default $realip_remote_addr; | ||
'' $remote_addr; | ||
} | ||
|
||
# trust http_x_forwarded_proto headers correctly indicate ssl offloading | ||
map $http_x_forwarded_proto $pass_access_scheme { | ||
default $http_x_forwarded_proto; | ||
'' $scheme; | ||
} | ||
|
||
map $http_x_forwarded_port $pass_server_port { | ||
default $http_x_forwarded_port; | ||
'' $server_port; | ||
default $http_x_forwarded_port; | ||
'' $server_port; | ||
} | ||
|
||
map $http_x_forwarded_host $best_http_host { | ||
default $http_x_forwarded_host; | ||
'' $this_host; | ||
} | ||
|
||
{{ else }} | ||
# Do not trust HTTP X-Forwarded-* Headers | ||
map {{ buildForwardedFor $cfg.ForwardedForHeader }} $the_real_ip { | ||
default {{ buildForwardedFor $cfg.ForwardedForHeader }}; | ||
"~*(?<ip>[0-9\.]+).*" $ip; | ||
{{ if $cfg.UseProxyProtocol }} | ||
'' $proxy_protocol_addr; | ||
{{ if (trustProxyProtocol $cfg) }} | ||
# Get IP address from Proxy Protocol | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This wasn't created for me after setting real-client-from: "tcp-proxy" |
||
default $proxy_protocol_addr; | ||
{{ else }} | ||
'' $realip_remote_addr; | ||
# Get IP from direct remote address | ||
default $realip_remote_addr; | ||
{{ end }} | ||
} | ||
|
||
map $http_x_forwarded_host $best_http_host { | ||
default $this_host; | ||
} | ||
map $http_x_forwarded_proto $pass_access_scheme { | ||
default $scheme; | ||
} | ||
map $http_x_forwarded_port $pass_server_port { | ||
default $server_port; | ||
} | ||
|
||
{{ end }} | ||
|
||
{{ if $all.IsSSLPassthroughEnabled }} | ||
# map port {{ $all.ListenPorts.SSLProxy }} to 443 for header X-Forwarded-Port | ||
map $pass_server_port $pass_port { | ||
|
@@ -206,11 +233,6 @@ http { | |
'' $host; | ||
} | ||
|
||
map $http_x_forwarded_host $best_http_host { | ||
default $http_x_forwarded_host; | ||
'' $this_host; | ||
} | ||
|
||
server_name_in_redirect off; | ||
port_in_redirect off; | ||
|
||
|
@@ -270,10 +292,12 @@ http { | |
|
||
{{ range $server := $upstream.Endpoints }}server {{ $server.Address | formatIP }}:{{ $server.Port }} max_fails={{ $server.MaxFails }} fail_timeout={{ $server.FailTimeout }}; | ||
{{ end }} | ||
|
||
} | ||
|
||
{{ end }} | ||
|
||
|
||
upstream {{ $upstream.Name }} { | ||
# Load balance algorithm; empty for round robin, which is the default | ||
{{ if ne $cfg.LoadBalanceAlgorithm "round_robin" }} | ||
|
@@ -364,7 +388,7 @@ http { | |
|
||
{{ template "CUSTOM_ERRORS" $all }} | ||
} | ||
|
||
{{ if $server.Alias }} | ||
server { | ||
server_name {{ $server.Alias }}; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be $all instead of $cfg, as defined also in trustHTTPHeaders?
I'm facing an issue here, that even when UseProxyProtocol is false, it's returning a 'true' value here, using $proxy_protocol_addr instead of $realip_remote_addr.
Edit: After changing this to $all in my template, it works fine. I'm now going to test this with other options to see what's the behaviour.