Skip to content

Commit

Permalink
Merge pull request #2353 from bashofmann/master
Browse files Browse the repository at this point in the history
Add proxy-add-original-uri-header config flag
  • Loading branch information
k8s-ci-robot authored Apr 16, 2018
2 parents 986e87e + 1c17962 commit 564ec88
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
5 changes: 5 additions & 0 deletions docs/user-guide/configmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ The following table shows a configuration option's name, type, and the default v
|[bind-address-ipv6](#bind-address-ipv6)|[]string|""|
|[forwarded-for-header](#forwarded-for-header)|string|"X-Forwarded-For"|
|[compute-full-forwarded-for](#compute-full-forwarded-for)|bool|"false"|
|[proxy-add-original-uri-header](#proxy-add-original-uri-header)|bool|"true"|
|[enable-opentracing](#enable-opentracing)|bool|"false"|
|[zipkin-collector-host](#zipkin-collector-host)|string|""|
|[zipkin-collector-port](#zipkin-collector-port)|int|9411|
Expand Down Expand Up @@ -585,6 +586,10 @@ Sets the header field for identifying the originating IP address of a client. De

Append the remote address to the X-Forwarded-For header instead of replacing it. When this option is enabled, the upstream application is responsible for extracting the client IP based on its own list of trusted proxies.

## proxy-add-original-uri-header

Adds an X-Original-Uri header with the original request URI to the backend request

## enable-opentracing

Enables the nginx Opentracing extension. By default this is disabled.
Expand Down
2 changes: 1 addition & 1 deletion internal/file/bindata.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions internal/ingress/controller/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,10 @@ type Configuration struct {
// Default: false
ComputeFullForwardedFor bool `json:"compute-full-forwarded-for,omitempty"`

// Adds an X-Original-Uri header with the original request URI to the backend request
// Default: true
ProxyAddOriginalUriHeader bool `json:"proxy-add-original-uri-header"`

// EnableOpentracing enables the nginx Opentracing extension
// https://github.com/rnburn/nginx-opentracing
// By default this is disabled
Expand Down Expand Up @@ -536,6 +540,7 @@ func NewDefault() Configuration {
ErrorLogLevel: errorLevel,
ForwardedForHeader: "X-Forwarded-For",
ComputeFullForwardedFor: false,
ProxyAddOriginalUriHeader: true,
HTTP2MaxFieldSize: "4k",
HTTP2MaxHeaderSize: "16k",
HTTPRedirectCode: 308,
Expand Down
34 changes: 18 additions & 16 deletions internal/ingress/controller/template/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,23 @@ func TestFilterErrors(t *testing.T) {

func TestMergeConfigMapToStruct(t *testing.T) {
conf := map[string]string{
"custom-http-errors": "300,400,demo",
"proxy-read-timeout": "1",
"proxy-send-timeout": "2",
"skip-access-log-urls": "/log,/demo,/test",
"use-proxy-protocol": "true",
"disable-access-log": "true",
"access-log-path": "/var/log/test/access.log",
"error-log-path": "/var/log/test/error.log",
"use-gzip": "true",
"enable-dynamic-tls-records": "false",
"gzip-types": "text/html",
"proxy-real-ip-cidr": "1.1.1.1/8,2.2.2.2/24",
"bind-address": "1.1.1.1,2.2.2.2,3.3.3,2001:db8:a0b:12f0::1,3731:54:65fe:2::a7,33:33:33::33::33",
"worker-shutdown-timeout": "99s",
"nginx-status-ipv4-whitelist": "127.0.0.1,10.0.0.0/24",
"nginx-status-ipv6-whitelist": "::1,2001::/16",
"custom-http-errors": "300,400,demo",
"proxy-read-timeout": "1",
"proxy-send-timeout": "2",
"skip-access-log-urls": "/log,/demo,/test",
"use-proxy-protocol": "true",
"disable-access-log": "true",
"access-log-path": "/var/log/test/access.log",
"error-log-path": "/var/log/test/error.log",
"use-gzip": "true",
"enable-dynamic-tls-records": "false",
"gzip-types": "text/html",
"proxy-real-ip-cidr": "1.1.1.1/8,2.2.2.2/24",
"bind-address": "1.1.1.1,2.2.2.2,3.3.3,2001:db8:a0b:12f0::1,3731:54:65fe:2::a7,33:33:33::33::33",
"worker-shutdown-timeout": "99s",
"nginx-status-ipv4-whitelist": "127.0.0.1,10.0.0.0/24",
"nginx-status-ipv6-whitelist": "::1,2001::/16",
"proxy-add-original-uri-header": "false",
}
def := config.NewDefault()
def.CustomHTTPErrors = []int{300, 400}
Expand All @@ -67,6 +68,7 @@ func TestMergeConfigMapToStruct(t *testing.T) {
def.WorkerShutdownTimeout = "99s"
def.NginxStatusIpv4Whitelist = []string{"127.0.0.1", "10.0.0.0/24"}
def.NginxStatusIpv6Whitelist = []string{"::1", "2001::/16"}
def.ProxyAddOriginalUriHeader = false

to := ReadConfig(conf)
if diff := pretty.Compare(to, def); diff != "" {
Expand Down
2 changes: 2 additions & 0 deletions rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,9 @@ stream {
proxy_set_header X-Forwarded-Host $best_http_host;
proxy_set_header X-Forwarded-Port $pass_port;
proxy_set_header X-Forwarded-Proto $pass_access_scheme;
{{ if $all.Cfg.ProxyAddOriginalUriHeader }}
proxy_set_header X-Original-URI $request_uri;
{{ end }}
proxy_set_header X-Scheme $pass_access_scheme;

# Pass the original X-Forwarded-For
Expand Down

0 comments on commit 564ec88

Please sign in to comment.