Skip to content

Commit 8b2ffde

Browse files
author
Nico Schieder
committed
Merged!
2 parents 94923b8 + 3840597 commit 8b2ffde

25 files changed

+758
-74
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
### 0.6.0
4+
5+
* [75](https://github.com/nginxinc/kubernetes-ingress/pull/75): Add the HSTS settings in the configmap and annotations. Thanks to [Nico Schieder](https://github.com/thetechnick).
6+
* [74](https://github.com/nginxinc/kubernetes-ingress/pull/74): Fix the issue of the `kubernetes.io/ingress.class` annotation handling. Thanks to [Tang Le](https://github.com/tangle329).
7+
* [70](https://github.com/nginxinc/kubernetes-ingress/pull/70): Add support for the alpine-based image for the NGINX controller.
8+
* [68](https://github.com/nginxinc/kubernetes-ingress/pull/68): Support for proxy-buffering settings in the configmap and annotations. Thanks to [Mark Daniel Reidel](https://github.com/df-mreidel).
9+
* [66](https://github.com/nginxinc/kubernetes-ingress/pull/66): Support for custom log-format in the configmap. Thanks to [Mark Daniel Reidel](https://github.com/df-mreidel).
10+
* [65](https://github.com/nginxinc/kubernetes-ingress/pull/65): Add HTTP/2 as an option in the configmap and annotations. Thanks to [Nico Schieder](https://github.com/thetechnick).
11+
* The NGINX Plus controller image is now based on Ubuntu Xenial.
12+
313
### 0.5.0
414

515
* Update NGINX version to 1.11.5.

examples/complete-example/nginx-ingress-rc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spec:
1414
app: nginx-ingress
1515
spec:
1616
containers:
17-
- image: nginxdemos/nginx-ingress:0.5.0
17+
- image: nginxdemos/nginx-ingress:0.6.0
1818
imagePullPolicy: Always
1919
name: nginx-ingress
2020
ports:

examples/complete-example/nginx-plus-ingress-rc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spec:
1414
app: nginx-plus-ingress
1515
spec:
1616
containers:
17-
- image: nginx-plus-ingress:0.5.0
17+
- image: nginx-plus-ingress:0.6.0
1818
imagePullPolicy: Always
1919
name: nginx-plus-ingress
2020
ports:

examples/customization/README.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
# Customization of NGINX Configuration
22

3-
You can customize the NGINX configuration using ConfigMaps or Annotations. For now, you can set the values of the following
4-
NGINX directives:
5-
* [proxy_connect_timeout](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_connect_timeout)
6-
* [proxy_read_timeout](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_read_timeout)
7-
* [client_max_body_size](http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size)
8-
* [server_names_hash_max_size](http://nginx.org/en/docs/http/ngx_http_core_module.html#server_names_hash_max_size) via ConfigMaps only
9-
* [server_names_hash_bucket_size](http://nginx.org/en/docs/http/ngx_http_core_module.html#server_names_hash_bucket_size) via ConfigMaps only
3+
You can customize the NGINX configuration using ConfigMaps or Annotations.
4+
5+
The table below summarizes some of the options. More options (extensions) are available, refer to the [examples](..) folder.
6+
7+
| Annotation | ConfigMaps Key | Description | Default |
8+
| ---------- | -------------- | ----------- | ------- |
9+
| `nginx.org/proxy-read-timeout` | `proxy-read-timeout` | Sets the value of the [proxy_connect_timeout](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_connect_timeout) directive. | `60s` |
10+
| `nginx.org/proxy-read-timeout` | `proxy-read-timeout` | Sets the value of the [proxy_read_timeout](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_read_timeout) directive. | `60s` |
11+
| `nginx.org/client-max-body-size` | `client-max-body-size` | Sets the value of the [client_max_body_size](http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size) directive. | `1m` |
12+
| `nginx.org/proxy-buffering` | `proxy-buffering` | Enables or disables [buffering of responses](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffering) from the proxied server. | `True` |
13+
| `nginx.org/proxy-buffers` | `proxy-buffers` | Sets the value of the [proxy_buffers](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffers) directive. | Depends on the platform. |
14+
| `nginx.org/proxy-buffer-size` | `proxy-buffer-size` | Sets the value of the [proxy_buffer_size](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffer_size) directive | Depends on the platform. |
15+
| `nginx.org/proxy-max-temp-file-size` | `proxy-max-temp-file-size` | Sets the value of the [proxy_max_temp_file_size](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_max_temp_file_size) directive. | `1024m` |
16+
| 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. |
17+
| 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` |
18+
| `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` |
19+
| 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). |
20+
| `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` |
21+
| `nginx.org/hsts-max-age` | `hsts-max-age` | Sets the value of the `max-age` directive of the HSTS header. | `2592000` (1 month) |
22+
| `nginx.org/hsts-include-subdomains` | `hsts-include-subdomains` | Adds the `includeSubDomains` directive to the HSTS header. | `False`|
1023

1124
## Using ConfigMaps
1225

examples/customization/nginx-config.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,13 @@ data:
88
client-max-body-size: "2m" # default is "1m". See http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size
99
server-names-hash-bucket-size: "64" # default value depends on the size of the processor’s cache line. See http://nginx.org/en/docs/http/ngx_http_core_module.html#server_names_hash_bucket_size
1010
server-names-hash-max-size: "1024" # default is "512". See http://nginx.org/en/docs/http/ngx_http_core_module.html#server_names_hash_max_size
11-
http2: 'True' # default is "False". Enables http2 in servers with SSL enabled. See https://nginx.org/en/docs/http/ngx_http_v2_module.html
11+
http2: "True" # default is "False". Enables HTTP/2 in servers with SSL enabled. See https://nginx.org/en/docs/http/ngx_http_v2_module.html
12+
proxy-buffering: "False" # default is "True". Enables or disables buffering of responses from the proxied server. See http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffering
13+
proxy-buffers: "16 8k" # default value depends on the platform. See http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffers
14+
proxy-buffer-size: "2k" # default value depends on the platform. See http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffer_size
15+
proxy-max-temp-file-size: "0" # default is "1024m". See http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_max_temp_file_size
16+
log-format: '{ "@timestamp": "$time_iso8601", "@version": "1", "clientip": "$remote_addr", "tag": "ingress", "remote_user": "$remote_user", "bytes": $bytes_sent, "duration": $request_time, "status": $status, "request": "$request_uri", "urlpath": "$uri", "urlquery": "$args", "method": "$request_method", "referer": "$http_referer", "useragent": "$http_user_agent", "software": "nginx", "version": "$nginx_version", "host": "$host", "upstream": "$upstream_addr", "upstream-status": "$upstream_status" }'
17+
# log-format default is set in the nginx.conf.tmpl file. Also see http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format
18+
hsts: "True" # default is "False". Enables HTTP Strict Transport Security (HSTS): the HSTS header is added to the responses from backends. See https://www.nginx.com/blog/http-strict-transport-security-hsts-and-nginx/
19+
hsts-max-age: "31536000" # default is 2592000 (1 month).
20+
hsts-include-subdomains: "True" # default is "False".

examples/daemon-set/nginx-ingress.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ spec:
1111
# nodeSelector:
1212
# role: nginx-ingress
1313
containers:
14-
- image: nginxdemos/nginx-ingress:0.5.0
14+
- image: nginxdemos/nginx-ingress:0.6.0
1515
imagePullPolicy: Always
1616
name: nginx-ingress
1717
ports:

examples/daemon-set/nginx-plus-ingress.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ spec:
1111
# nodeSelector:
1212
# role: nginx-ingress
1313
containers:
14-
- image: nginx-plus-ingress:0.5.0
14+
- image: nginx-plus-ingress:0.6.0
1515
imagePullPolicy: Always
1616
name: nginx-plus-ingress
1717
ports:

nginx-controller/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
all: push
22

3-
VERSION = 0.5.0
3+
VERSION = 0.6.0
44
TAG = $(VERSION)
55
PREFIX = nginxdemos/nginx-ingress
66

nginx-controller/controller/controller.go

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package controller
1919
import (
2020
"fmt"
2121
"reflect"
22-
"strconv"
2322
"strings"
2423
"time"
2524

@@ -285,6 +284,9 @@ func (lbc *LoadBalancerController) syncEndp(key string) {
285284
ings := lbc.getIngressForEndpoints(obj)
286285

287286
for _, ing := range ings {
287+
if !isNginxIngress(&ing) {
288+
continue
289+
}
288290
ingEx, err := lbc.createIngress(&ing)
289291
if err != nil {
290292
lbc.ingQueue.requeueAfter(key, err, 5*time.Second)
@@ -326,21 +328,54 @@ func (lbc *LoadBalancerController) syncCfgm(key string) {
326328
if serverNamesHashMaxSize, exists := cfgm.Data["server-names-hash-max-size"]; exists {
327329
cfg.MainServerNamesHashMaxSize = serverNamesHashMaxSize
328330
}
329-
if HTTP2Str, exists := cfgm.Data["http2"]; exists {
330-
if HTTP2, err := strconv.ParseBool(HTTP2Str); err == nil {
331+
if HTTP2, exists, err := nginx.GetMapKeyAsBool(cfgm.Data, "http2", cfgm); exists {
332+
if err != nil {
333+
glog.Error(err)
334+
} else {
331335
cfg.HTTP2 = HTTP2
336+
}
337+
}
338+
339+
// HSTS block
340+
if hsts, exists, err := nginx.GetMapKeyAsBool(cfgm.Data, "hsts", cfgm); exists {
341+
if err != nil {
342+
glog.Error(err)
332343
} else {
333-
glog.Errorf("In configmap %v/%v 'http2' contains invalid declaration: %v, ignoring", cfgm.Namespace, cfgm.Name, err)
344+
parsingErrors := false
345+
346+
hstsMaxAge, existsMA, err := nginx.GetMapKeyAsInt(cfgm.Data, "hsts-max-age", cfgm)
347+
if existsMA && err != nil {
348+
glog.Error(err)
349+
parsingErrors = true
350+
}
351+
hstsIncludeSubdomains, existsIS, err := nginx.GetMapKeyAsBool(cfgm.Data, "hsts-include-subdomains", cfgm)
352+
if existsIS && err != nil {
353+
glog.Error(err)
354+
parsingErrors = true
355+
}
356+
357+
if parsingErrors {
358+
glog.Errorf("Configmap %s/%s: There are configuration issues with hsts annotations, skipping options for all hsts settings", cfgm.GetNamespace(), cfgm.GetName())
359+
} else {
360+
cfg.HSTS = hsts
361+
if existsMA {
362+
cfg.HSTSMaxAge = hstsMaxAge
363+
}
364+
if existsIS {
365+
cfg.HSTSIncludeSubdomains = hstsIncludeSubdomains
366+
}
367+
}
334368
}
335369
}
370+
336371
if logFormat, exists := cfgm.Data["log-format"]; exists {
337372
cfg.MainLogFormat = logFormat
338373
}
339-
if proxyBufferingStr, exists := cfgm.Data["proxy-buffering"]; exists {
340-
if ProxyBuffering, err := strconv.ParseBool(proxyBufferingStr); err == nil {
341-
cfg.ProxyBuffering = ProxyBuffering
374+
if proxyBuffering, exists, err := nginx.GetMapKeyAsBool(cfgm.Data, "proxy-buffering", cfgm); exists {
375+
if err != nil {
376+
glog.Error(err)
342377
} else {
343-
glog.Errorf("In configmap %v/%v 'proxy-buffering' contains invalid declaration: %v, ignoring", cfgm.Namespace, cfgm.Name, err)
378+
cfg.ProxyBuffering = proxyBuffering
344379
}
345380
}
346381
if proxyBuffers, exists := cfgm.Data["proxy-buffers"]; exists {
@@ -357,6 +392,9 @@ func (lbc *LoadBalancerController) syncCfgm(key string) {
357392

358393
ings, _ := lbc.ingLister.List()
359394
for _, ing := range ings.Items {
395+
if !isNginxIngress(&ing) {
396+
continue
397+
}
360398
lbc.ingQueue.enqueue(&ing)
361399
}
362400
}
@@ -393,6 +431,9 @@ func (lbc *LoadBalancerController) enqueueIngressForService(obj interface{}) {
393431
svc := obj.(*api.Service)
394432
ings := lbc.getIngressesForService(svc)
395433
for _, ing := range ings {
434+
if !isNginxIngress(&ing) {
435+
continue
436+
}
396437
lbc.ingQueue.enqueue(&ing)
397438
}
398439
}

nginx-controller/nginx/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ type Config struct {
1313
ProxyBuffers string
1414
ProxyBufferSize string
1515
ProxyMaxTempFileSize string
16+
HSTS bool
17+
HSTSMaxAge int64
18+
HSTSIncludeSubdomains bool
1619
}
1720

1821
// NewDefaultConfig creates a Config with default values
@@ -23,5 +26,6 @@ func NewDefaultConfig() *Config {
2326
ClientMaxBodySize: "1m",
2427
MainServerNamesHashMaxSize: "512",
2528
ProxyBuffering: true,
29+
HSTSMaxAge: 2592000,
2630
}
2731
}

0 commit comments

Comments
 (0)