Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/customization/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The table below summarizes some of the options. More options (extensions) are av
| N/A | `server-names-hash-bucket-size` | Sets the value of the [server_names_hash_max_size](http://nginx.org/en/docs/http/ngx_http_core_module.html#server_names_hash_max_size) directive. | Depends on the size of the processor’s cache line. |
| N/A | `server-names-hash-max-size` | Sets the value of the [server_names_hash_bucket_size](http://nginx.org/en/docs/http/ngx_http_core_module.html#server_names_hash_bucket_size) directive. | `512` |
| `nginx.org/http2` | `http2` | Enables HTTP/2 in servers with SSL enabled. To support HTTP/2 for Chrome users, use the provided controller image based on the alpine Linux. It includes OpenSSL with ALPN support, [necessary for Chrome users](https://www.nginx.com/blog/supporting-http2-google-chrome-users/). | `False` |
| `nginx.org/redirect-to-https` | `redirect-to-https` | Sets the 301 redirect rule based on the value of the `http_x_forwarded_proto` header on the server block to force incoming traffic to be over HTTPS. Useful when terminating SSL in a load balancer in front of the Ingress controller — see [115](https://github.com/nginxinc/kubernetes-ingress/issues/115) | `False` |
| N/A | `log-format` | Sets the custom [log format](http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format). | See the [template file](../../nginx-controller/nginx/nginx.conf.tmpl). |
| `nginx.org/hsts` | `hsts` | Enables [HTTP Strict Transport Security (HSTS)](https://www.nginx.com/blog/http-strict-transport-security-hsts-and-nginx/): the HSTS header is added to the responses from backends. The `preload` directive is included in the header. | `False` |
| `nginx.org/hsts-max-age` | `hsts-max-age` | Sets the value of the `max-age` directive of the HSTS header. | `2592000` (1 month) |
Expand Down
7 changes: 7 additions & 0 deletions nginx-controller/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,13 @@ func (lbc *LoadBalancerController) syncCfgm(key string) {
cfg.HTTP2 = HTTP2
}
}
if redirectToHTTPS, exists,err := nginx.GetMapKeyAsBool(cfgm.Data, "redirect-to-https", cfgm); exists {
if err != nil {
glog.Error(err)
} else {
cfg.RedirectToHTTPS = redirectToHTTPS
}
}

// HSTS block
if hsts, exists, err := nginx.GetMapKeyAsBool(cfgm.Data, "hsts", cfgm); exists {
Expand Down
1 change: 1 addition & 0 deletions nginx-controller/nginx/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Config struct {
ProxyReadTimeout string
ClientMaxBodySize string
HTTP2 bool
RedirectToHTTPS bool
MainServerNamesHashBucketSize string
MainServerNamesHashMaxSize string
MainLogFormat string
Expand Down
9 changes: 9 additions & 0 deletions nginx-controller/nginx/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func (cnf *Configurator) generateNginxCfg(ingEx *IngressEx, pems map[string]stri
Name: serverName,
ServerTokens: ingCfg.ServerTokens,
HTTP2: ingCfg.HTTP2,
RedirectToHTTPS: ingCfg.RedirectToHTTPS,
ProxyProtocol: ingCfg.ProxyProtocol,
HSTS: ingCfg.HSTS,
HSTSMaxAge: ingCfg.HSTSMaxAge,
Expand Down Expand Up @@ -162,6 +163,7 @@ func (cnf *Configurator) generateNginxCfg(ingEx *IngressEx, pems map[string]stri
Name: emptyHost,
ServerTokens: ingCfg.ServerTokens,
HTTP2: ingCfg.HTTP2,
RedirectToHTTPS: ingCfg.RedirectToHTTPS,
ProxyProtocol: ingCfg.ProxyProtocol,
HSTS: ingCfg.HSTS,
HSTSMaxAge: ingCfg.HSTSMaxAge,
Expand Down Expand Up @@ -232,6 +234,13 @@ func (cnf *Configurator) createConfig(ingEx *IngressEx) Config {
ingCfg.HTTP2 = HTTP2
}
}
if redirectToHTTPS, exists, err := GetMapKeyAsBool(ingEx.Ingress.Annotations, "nginx.org/redirect-to-https", ingEx.Ingress); exists {
if err != nil {
glog.Error(err)
} else {
ingCfg.RedirectToHTTPS = redirectToHTTPS
}
}
if proxyBuffering, exists, err := GetMapKeyAsBool(ingEx.Ingress.Annotations, "nginx.org/proxy-buffering", ingEx.Ingress); exists {
if err != nil {
glog.Error(err)
Expand Down
7 changes: 6 additions & 1 deletion nginx-controller/nginx/ingress.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ server {
proxy_hide_header Strict-Transport-Security;
add_header Strict-Transport-Security "max-age={{$server.HSTSMaxAge}}; {{if $server.HSTSIncludeSubdomains}}includeSubDomains; {{end}}preload" always;{{end}}
{{- end}}
{{- if $server.RedirectToHTTPS}}
if ($http_x_forwarded_proto = 'http') {
return 301 https://$host$request_uri;
}
{{- end}}

{{range $location := $server.Locations}}
location {{$location.Path}} {
Expand All @@ -50,7 +55,7 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Proto {{if $server.RedirectToHTTPS}}https{{else}}$scheme{{end}};

proxy_buffering {{if $location.ProxyBuffering}}on{{else}}off{{end}};
{{- if $location.ProxyBuffers}}
Expand Down
1 change: 1 addition & 0 deletions nginx-controller/nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Server struct {
SSLCertificate string
SSLCertificateKey string
HTTP2 bool
RedirectToHTTPS bool
ProxyProtocol bool
HSTS bool
HSTSMaxAge int64
Expand Down
7 changes: 7 additions & 0 deletions nginx-plus-controller/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,13 @@ func (lbc *LoadBalancerController) syncCfgm(key string) {
cfg.HTTP2 = HTTP2
}
}
if redirectToHTTPS, exists,err := nginx.GetMapKeyAsBool(cfgm.Data, "redirect-to-https", cfgm); exists {
if err != nil {
glog.Error(err)
} else {
cfg.RedirectToHTTPS = redirectToHTTPS
}
}

// HSTS block
if hsts, exists, err := nginx.GetMapKeyAsBool(cfgm.Data, "hsts", cfgm); exists {
Expand Down
1 change: 1 addition & 0 deletions nginx-plus-controller/nginx/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Config struct {
ProxyReadTimeout string
ClientMaxBodySize string
HTTP2 bool
RedirectToHTTPS bool
MainServerNamesHashBucketSize string
MainServerNamesHashMaxSize string
MainLogFormat string
Expand Down
9 changes: 9 additions & 0 deletions nginx-plus-controller/nginx/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func (cnf *Configurator) generateNginxCfg(ingEx *IngressEx, pems map[string]stri
Name: serverName,
ServerTokens: ingCfg.ServerTokens,
HTTP2: ingCfg.HTTP2,
RedirectToHTTPS: ingCfg.RedirectToHTTPS,
ProxyProtocol: ingCfg.ProxyProtocol,
HSTS: ingCfg.HSTS,
HSTSMaxAge: ingCfg.HSTSMaxAge,
Expand Down Expand Up @@ -176,6 +177,7 @@ func (cnf *Configurator) generateNginxCfg(ingEx *IngressEx, pems map[string]stri
Name: serverName,
ServerTokens: ingCfg.ServerTokens,
HTTP2: ingCfg.HTTP2,
RedirectToHTTPS: ingCfg.RedirectToHTTPS,
ProxyProtocol: ingCfg.ProxyProtocol,
HSTS: ingCfg.HSTS,
HSTSMaxAge: ingCfg.HSTSMaxAge,
Expand Down Expand Up @@ -251,6 +253,13 @@ func (cnf *Configurator) createConfig(ingEx *IngressEx) Config {
ingCfg.HTTP2 = HTTP2
}
}
if redirectToHTTPS, exists,err := GetMapKeyAsBool(ingEx.Ingress.Annotations, "nginx.org/redirect-to-https", ingEx.Ingress); exists {
if err != nil {
glog.Error(err)
} else {
ingCfg.RedirectToHTTPS = redirectToHTTPS
}
}
if proxyBuffering, exists, err := GetMapKeyAsBool(ingEx.Ingress.Annotations, "nginx.org/proxy-buffering", ingEx.Ingress); exists {
if err != nil {
glog.Error(err)
Expand Down
7 changes: 6 additions & 1 deletion nginx-plus-controller/nginx/ingress.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ server {
{{- if $server.HSTS}}
add_header Strict-Transport-Security "max-age={{$server.HSTSMaxAge}}; {{if $server.HSTSIncludeSubdomains}}includeSubDomains; {{end}}preload" always;{{end}}
{{- end}}
{{- if $server.RedirectToHTTPS}}
if ($http_x_forwarded_proto = 'http') {
return 301 https://$host$request_uri;
}
{{- end}}

{{range $location := $server.Locations}}
location {{$location.Path}} {
Expand All @@ -56,7 +61,7 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Proto {{if $server.RedirectToHTTPS}}https{{else}}$scheme{{end}};
proxy_buffering {{if $location.ProxyBuffering}}on{{else}}off{{end}};
{{- if $location.ProxyBuffers}}
proxy_buffers {{$location.ProxyBuffers}};
Expand Down
1 change: 1 addition & 0 deletions nginx-plus-controller/nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Server struct {
SSLCertificateKey string
StatusZone string
HTTP2 bool
RedirectToHTTPS bool
ProxyProtocol bool
HSTS bool
HSTSMaxAge int64
Expand Down