Skip to content

Commit

Permalink
Add proxy_hide_header and proxy_pass_header directives (#88)
Browse files Browse the repository at this point in the history
* Add proxy_hide_header and proxy_pass_header directives
  • Loading branch information
thetechnick authored and pleshakov committed Dec 1, 2016
1 parent 9c72c30 commit 9d0f75d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
14 changes: 14 additions & 0 deletions nginx-controller/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,20 @@ func (lbc *LoadBalancerController) syncCfgm(key string) {
if proxyReadTimeout, exists := cfgm.Data["proxy-read-timeout"]; exists {
cfg.ProxyReadTimeout = proxyReadTimeout
}
if proxyHideHeaders, exists, err := nginx.GetMapKeyAsStringSlice(cfgm.Data, "proxy-hide-headers", cfgm); exists {
if err != nil {
glog.Error(err)
} else {
cfg.ProxyHideHeaders = proxyHideHeaders
}
}
if proxyPassHeaders, exists, err := nginx.GetMapKeyAsStringSlice(cfgm.Data, "proxy-pass-headers", cfgm); exists {
if err != nil {
glog.Error(err)
} else {
cfg.ProxyPassHeaders = proxyPassHeaders
}
}
if clientMaxBodySize, exists := cfgm.Data["client-max-body-size"]; exists {
cfg.ClientMaxBodySize = clientMaxBodySize
}
Expand Down
2 changes: 2 additions & 0 deletions nginx-controller/nginx/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type Config struct {
ProxyBufferSize string
ProxyMaxTempFileSize string
ProxyProtocol bool
ProxyHideHeaders []string
ProxyPassHeaders []string
HSTS bool
HSTSMaxAge int64
HSTSIncludeSubdomains bool
Expand Down
18 changes: 18 additions & 0 deletions nginx-controller/nginx/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ func (cnf *Configurator) generateNginxCfg(ingEx *IngressEx, pems map[string]stri
RealIPHeader: ingCfg.RealIPHeader,
SetRealIPFrom: ingCfg.SetRealIPFrom,
RealIPRecursive: ingCfg.RealIPRecursive,
ProxyHideHeaders: ingCfg.ProxyHideHeaders,
ProxyPassHeaders: ingCfg.ProxyPassHeaders,
}

if pemFile, ok := pems[serverName]; ok {
Expand Down Expand Up @@ -160,6 +162,8 @@ func (cnf *Configurator) generateNginxCfg(ingEx *IngressEx, pems map[string]stri
RealIPHeader: ingCfg.RealIPHeader,
SetRealIPFrom: ingCfg.SetRealIPFrom,
RealIPRecursive: ingCfg.RealIPRecursive,
ProxyHideHeaders: ingCfg.ProxyHideHeaders,
ProxyPassHeaders: ingCfg.ProxyPassHeaders,
}

if pemFile, ok := pems[emptyHost]; ok {
Expand Down Expand Up @@ -190,6 +194,20 @@ func (cnf *Configurator) createConfig(ingEx *IngressEx) Config {
if proxyReadTimeout, exists := ingEx.Ingress.Annotations["nginx.org/proxy-read-timeout"]; exists {
ingCfg.ProxyReadTimeout = proxyReadTimeout
}
if proxyHideHeaders, exists, err := GetMapKeyAsStringSlice(ingEx.Ingress.Annotations, "nginx.org/proxy-hide-headers", ingEx.Ingress); exists {
if err != nil {
glog.Error(err)
} else {
ingCfg.ProxyHideHeaders = proxyHideHeaders
}
}
if proxyPassHeaders, exists, err := GetMapKeyAsStringSlice(ingEx.Ingress.Annotations, "nginx.org/proxy-pass-headers", ingEx.Ingress); exists {
if err != nil {
glog.Error(err)
} else {
ingCfg.ProxyPassHeaders = proxyPassHeaders
}
}
if clientMaxBodySize, exists := ingEx.Ingress.Annotations["nginx.org/client-max-body-size"]; exists {
ingCfg.ClientMaxBodySize = clientMaxBodySize
}
Expand Down
5 changes: 4 additions & 1 deletion nginx-controller/nginx/ingress.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ server {
{{if $server.Name}}
server_name {{$server.Name}};
{{end}}

{{range $proxyHideHeader := $server.ProxyHideHeaders}}
proxy_hide_header {{$proxyHideHeader}};{{end}}
{{range $proxyPassHeader := $server.ProxyPassHeaders}}
proxy_pass_header {{$proxyPassHeader}};{{end}}
{{if $server.SSL}}
if ($scheme = http) {
return 301 https://$host$request_uri;
Expand Down
2 changes: 2 additions & 0 deletions nginx-controller/nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type Server struct {
HSTS bool
HSTSMaxAge int64
HSTSIncludeSubdomains bool
ProxyHideHeaders []string
ProxyPassHeaders []string

// http://nginx.org/en/docs/http/ngx_http_realip_module.html
RealIPHeader string
Expand Down

0 comments on commit 9d0f75d

Please sign in to comment.