Skip to content

Commit e3c61f2

Browse files
authored
Merge pull request #37 from tolstenko/master
feat(router): Add ability to set MaxHeaderSize and MaxFieldSize globally
2 parents 268ef6d + 7095874 commit e3c61f2

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ _Note that Kubernetes annotation maps are all of Go type `map[string]string`. A
257257
| <a name="default-app-name"></a>deis-router | deployment | [router.deis.io/nginx.DefaultAppName](#default-app-name) | `""` | Default back-end application name for traffic hitting router on /. In order to work correctly both `defaultServiceIP` and `DefaultServiceEnabled` MUST also be set. |
258258
| <a name="default-service-ip"></a>deis-router | deployment | [router.deis.io/nginx.defaultServiceIP](#default-service-ip) | `""` | Default back-end service ip for traffic hitting router on /. In order to work correctly both `DefaultAppName` and `DefaultServiceEnabled` MUST also be set. |
259259
| <a name="http2-enabled"></a>deis-router | deployment | [router.deis.io/nginx.http2Enabled](#http2-enabled) | `"true"` | Whether to enable HTTP2 for apps on the SSL ports. |
260+
| <a name="http2MaxHeaderSize"></a>deis-router | deployment | [router.deis.io/nginx.http2MaxHeaderSize](#http2MaxHeaderSize) | `"32k"` | The max header size. |
261+
| <a name="http2MaxFieldSize"></a>deis-router | deployment | [router.deis.io/nginx.http2MaxFieldSize](#http2MaxFieldSize) | `"16k"` | The max header field size. |
260262
| <a name="log-format"></a>deis-router | deployment | [router.deis.io/nginx.logFormat](#log-format) | `"[$time_iso8601] - $app_name - $remote_addr - $remote_user - $status - "$request" - $bytes_sent - "$http_referer" - "$http_user_agent" - "$server_name" - $upstream_addr - $http_host - $upstream_response_time - $request_time"` | Nginx access log format. **Warning:** if you change this to a non-default value, log parsing in monitoring subsystem will be broken. Use this parameter if you completely understand what you're doing. |
261263
| <a name="ssl-enforce"></a>deis-router | deployment | [router.deis.io/nginx.ssl.enforce](#ssl-enforce) | `"false"` | Whether to respond with a 301 for all HTTP requests with a permanent redirect to the HTTPS equivalent address. |
262264
| <a name="ssl-protocols"></a>deis-router | deployment | [router.deis.io/nginx.ssl.protocols](#ssl-protocols) | `"TLSv1 TLSv1.1 TLSv1.2"` | nginx `ssl_protocols` setting. |

model/model.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ type RouterConfig struct {
7272
LogFormat string `key:"logFormat"`
7373
ProxyBuffersConfig *ProxyBuffersConfig `key:"proxyBuffers"`
7474
ReferrerPolicy string `key:"referrerPolicy" constraint:"^(no-referrer|no-referrer-when-downgrade|origin|origin-when-cross-origin|same-origin|strict-origin|strict-origin-when-cross-origin|unsafe-url|none)$"`
75+
HTTP2MaxHeaderSize string `key:"http2MaxHeaderSize" constraint:"^[0-9]\\d*[kKmM]?$"`
76+
HTTP2MaxFieldSize string `key:"http2MaxFieldSize" constraint:"^[0-9]\\d*[kKmM]?$"`
7577
}
7678

7779
func newRouterConfig() (*RouterConfig, error) {
@@ -108,6 +110,8 @@ func newRouterConfig() (*RouterConfig, error) {
108110
LogFormat: `[$time_iso8601] - $app_name - $remote_addr - $remote_user - $status - "$request" - $bytes_sent - "$http_referer" - "$http_user_agent" - "$server_name" - $upstream_addr - $http_host - $upstream_response_time - $request_time`,
109111
ProxyBuffersConfig: proxyBuffersConfig,
110112
ReferrerPolicy: "",
113+
HTTP2MaxHeaderSize: "32k",
114+
HTTP2MaxFieldSize: "16k",
111115
}, nil
112116
}
113117

nginx/config.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ http {
161161
return 200;
162162
}
163163
164+
# set header size limits
165+
{{ if $routerConfig.HTTP2Enabled }} http2_max_header_size {{ $routerConfig.HTTP2MaxHeaderSize }}; {{ end }}
166+
{{ if $routerConfig.HTTP2Enabled }} http2_max_field_size {{ $routerConfig.HTTP2MaxFieldSize }}; {{ end }}
167+
164168
location / {
165169
proxy_buffering {{ if $routerConfig.ProxyBuffersConfig.Enabled }}on{{ else }}off{{ end }};
166170
proxy_buffer_size {{ $routerConfig.ProxyBuffersConfig.Size }};
@@ -183,6 +187,11 @@ http {
183187
server {
184188
listen 8080 default_server reuseport{{ if $routerConfig.UseProxyProtocol }} proxy_protocol{{ end }};
185189
listen 6443 default_server ssl {{ if $routerConfig.HTTP2Enabled }}http2{{ end }} {{ if $routerConfig.UseProxyProtocol }}proxy_protocol{{ end }};
190+
191+
# set header size limits
192+
{{ if $routerConfig.HTTP2Enabled }} http2_max_header_size {{ $routerConfig.HTTP2MaxHeaderSize }}; {{ end }}
193+
{{ if $routerConfig.HTTP2Enabled }} http2_max_field_size {{ $routerConfig.HTTP2MaxFieldSize }}; {{ end }}
194+
186195
set $app_name "router-default-vhost";
187196
{{ if $routerConfig.PlatformCertificate }}
188197
ssl_protocols {{ $sslConfig.Protocols }};
@@ -251,6 +260,10 @@ http {
251260
modsecurity_rules_file /opt/router/conf/modsecurity.conf;
252261
{{- end }}
253262
263+
# set header size limits
264+
{{ if $routerConfig.HTTP2Enabled }} http2_max_header_size {{ $routerConfig.HTTP2MaxHeaderSize }}; {{ end }}
265+
{{ if $routerConfig.HTTP2Enabled }} http2_max_field_size {{ $routerConfig.HTTP2MaxFieldSize }}; {{ end }}
266+
254267
{{ if index $appConfig.Certificates $domain }}
255268
listen 6443 ssl {{ if $routerConfig.HTTP2Enabled }}http2{{ end }} {{ if $routerConfig.UseProxyProtocol }}proxy_protocol{{ end }};
256269
ssl_protocols {{ $sslConfig.Protocols }};

0 commit comments

Comments
 (0)