Add support for add_headers
This commit is contained in:
parent
c1e7c7a290
commit
02832dec6c
3 changed files with 26 additions and 2 deletions
|
@ -479,6 +479,18 @@ func (n *NGINXController) OnUpdate(ingressCfg ingress.Configuration) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addHeaders := map[string]string{}
|
||||||
|
if cfg.AddHeaders != "" {
|
||||||
|
cmap, exists, err := n.storeLister.ConfigMap.GetByKey(cfg.AddHeaders)
|
||||||
|
if err != nil {
|
||||||
|
glog.Warningf("unexpected error reading configmap %v: %v", cfg.AddHeaders, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if exists {
|
||||||
|
addHeaders = cmap.(*api_v1.ConfigMap).Data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sslDHParam := ""
|
sslDHParam := ""
|
||||||
if cfg.SSLDHParam != "" {
|
if cfg.SSLDHParam != "" {
|
||||||
secretName := cfg.SSLDHParam
|
secretName := cfg.SSLDHParam
|
||||||
|
@ -507,6 +519,7 @@ func (n *NGINXController) OnUpdate(ingressCfg ingress.Configuration) error {
|
||||||
|
|
||||||
content, err := n.t.Write(config.TemplateConfig{
|
content, err := n.t.Write(config.TemplateConfig{
|
||||||
ProxySetHeaders: setHeaders,
|
ProxySetHeaders: setHeaders,
|
||||||
|
AddHeaders: addHeaders,
|
||||||
MaxOpenFiles: maxOpenFiles,
|
MaxOpenFiles: maxOpenFiles,
|
||||||
BacklogSize: sysctlSomaxconn(),
|
BacklogSize: sysctlSomaxconn(),
|
||||||
Backends: ingressCfg.Backends,
|
Backends: ingressCfg.Backends,
|
||||||
|
|
|
@ -83,6 +83,9 @@ const (
|
||||||
type Configuration struct {
|
type Configuration struct {
|
||||||
defaults.Backend `json:",squash"`
|
defaults.Backend `json:",squash"`
|
||||||
|
|
||||||
|
// Sets the name of the configmap that contains the headers to pass to the client
|
||||||
|
AddHeaders string `json:"add-headers,omitempty"`
|
||||||
|
|
||||||
// AllowBackendServerHeader enables the return of the header Server from the backend
|
// AllowBackendServerHeader enables the return of the header Server from the backend
|
||||||
// instead of the generic nginx string.
|
// instead of the generic nginx string.
|
||||||
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_hide_header
|
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_hide_header
|
||||||
|
@ -392,6 +395,7 @@ func (cfg Configuration) BuildLogFormatUpstream() string {
|
||||||
// TemplateConfig contains the nginx configuration to render the file nginx.conf
|
// TemplateConfig contains the nginx configuration to render the file nginx.conf
|
||||||
type TemplateConfig struct {
|
type TemplateConfig struct {
|
||||||
ProxySetHeaders map[string]string
|
ProxySetHeaders map[string]string
|
||||||
|
AddHeaders map[string]string
|
||||||
MaxOpenFiles int
|
MaxOpenFiles int
|
||||||
BacklogSize int
|
BacklogSize int
|
||||||
Backends []*ingress.Backend
|
Backends []*ingress.Backend
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
{{ $healthzURI := .HealthzURI }}
|
{{ $healthzURI := .HealthzURI }}
|
||||||
{{ $backends := .Backends }}
|
{{ $backends := .Backends }}
|
||||||
{{ $proxyHeaders := .ProxySetHeaders }}
|
{{ $proxyHeaders := .ProxySetHeaders }}
|
||||||
|
{{ $addHeaders := .AddHeaders }}
|
||||||
daemon off;
|
daemon off;
|
||||||
|
|
||||||
worker_processes {{ $cfg.WorkerProcesses }};
|
worker_processes {{ $cfg.WorkerProcesses }};
|
||||||
|
@ -92,6 +93,11 @@ http {
|
||||||
gzip_proxied any;
|
gzip_proxied any;
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
# Custom headers for response
|
||||||
|
{{ range $k, $v := $addHeaders }}
|
||||||
|
add_header {{ $k }} "{{ $v }}";
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
server_tokens {{ if $cfg.ShowServerTokens }}on{{ else }}off{{ end }};
|
server_tokens {{ if $cfg.ShowServerTokens }}on{{ else }}off{{ end }};
|
||||||
|
|
||||||
# disable warnings
|
# disable warnings
|
||||||
|
@ -324,6 +330,7 @@ http {
|
||||||
return 302 {{ $location.Redirect.AppRoot }};
|
return 302 {{ $location.Redirect.AppRoot }};
|
||||||
}
|
}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ if not (empty $authPath) }}
|
{{ if not (empty $authPath) }}
|
||||||
location = {{ $authPath }} {
|
location = {{ $authPath }} {
|
||||||
internal;
|
internal;
|
||||||
|
@ -427,7 +434,7 @@ http {
|
||||||
# https://www.nginx.com/blog/mitigating-the-httpoxy-vulnerability-with-nginx/
|
# https://www.nginx.com/blog/mitigating-the-httpoxy-vulnerability-with-nginx/
|
||||||
proxy_set_header Proxy "";
|
proxy_set_header Proxy "";
|
||||||
|
|
||||||
# Custom headers
|
# Custom headers to proxied server
|
||||||
{{ range $k, $v := $proxyHeaders }}
|
{{ range $k, $v := $proxyHeaders }}
|
||||||
proxy_set_header {{ $k }} "{{ $v }}";
|
proxy_set_header {{ $k }} "{{ $v }}";
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
Loading…
Reference in a new issue