Skip to content

Commit 4ca3a74

Browse files
author
Lachlan Evenson
committed
feat(router): make default app configurable
Makes default application configurable when hitting / on Deis router.
1 parent ee87845 commit 4ca3a74

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ _Note that Kubernetes annotation maps are all of Go type `map[string]string`. A
250250
| <a name="enforce-whitelists"></a>deis-router | deployment | [router.deis.io/nginx.enforceWhitelists](#enforce-whitelists) | `"false"` | Whether to _require_ application-level whitelists that explicitly enumerate allowed clients by IP / CIDR range. With this enabled, each app will drop _all_ requests unless a whitelist has been defined. |
251251
| <a name="default-whitelist"></a>deis-router | deployment | [router.deis.io/nginx.defaultWhitelist](#default-whitelist) | N/A | A default (router-wide) whitelist expressed as a comma-delimited list of addresses (using IP or CIDR notation). Application-specific whitelists can either extend or override this default. |
252252
| <a name="whitelist-mode"></a>deis-router | deployment | [router.deis.io/nginx.whitelistMode](#whitelist-mode) | `"extend"` | Whether application-specific whitelists should extend or override the router-wide default whitelist (if defined). Valid values are `"extend"` and `"override"`. |
253+
| <a name="default-service-enabled"></a>deis-router | deployment | [router.deis.io/nginx.defaultServiceEnabled](#default-service-enabled) | `"false"` | Enables default back-end service for traffic hitting /. In order to work correctly both `defaultServiceIP` and `DefaultAppName` MUST also be set. |
254+
| <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. |
255+
| <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. |
253256
| <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. |
254257
| <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. |
255258
| <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. |

model/model.go

+6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ type RouterConfig struct {
5151
EnforceWhitelists bool `key:"enforceWhitelists" constraint:"(?i)^(true|false)$"`
5252
DefaultWhitelist []string `key:"defaultWhitelist" constraint:"^((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\\/([0-9]|[1-2][0-9]|3[0-2]))?(\\s*,\\s*)?)+$"`
5353
WhitelistMode string `key:"whitelistMode" constraint:"^(extend|override)$"`
54+
DefaultServiceIP string `key:"defaultServiceIP"`
55+
DefaultAppName string `key:"defaultAppName"`
56+
DefaultServiceEnabled bool `key:"defaultServiceEnabled" constraint:"(?i)^(true|false)$"`
5457
RequestIDs bool `key:"requestIDs" constraint:"(?i)^(true|false)$"`
5558
SSLConfig *SSLConfig `key:"ssl"`
5659
AppConfigs []*AppConfig
@@ -77,6 +80,9 @@ func newRouterConfig() *RouterConfig {
7780
WhitelistMode: "extend",
7881
RequestIDs: false,
7982
SSLConfig: newSSLConfig(),
83+
DefaultServiceEnabled: false,
84+
DefaultAppName: "",
85+
DefaultServiceIP: "",
8086
HTTP2Enabled: true,
8187
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`,
8288
}

nginx/config.go

+30
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,35 @@ http {
128128
{{/* This means we force HTTPS if HSTS is enabled. */}}
129129
{{ $enforceSecure := or $sslConfig.Enforce $hstsConfig.Enabled }}
130130
131+
{{ if $routerConfig.DefaultServiceEnabled }}
132+
server {
133+
listen 8080 default_server{{ if $routerConfig.UseProxyProtocol }} proxy_protocol{{ end }};
134+
server_name _;
135+
server_name_in_redirect off;
136+
port_in_redirect off;
137+
set $app_name "{{ $routerConfig.DefaultAppName }}";
138+
vhost_traffic_status_filter_by_set_key {{ $routerConfig.DefaultAppName }} application::*;
139+
location ~ ^/healthz/?$ {
140+
access_log off;
141+
default_type 'text/plain';
142+
return 200;
143+
}
144+
145+
location / {
146+
proxy_buffering off;
147+
proxy_set_header Host $host;
148+
proxy_set_header X-Forwarded-For $remote_addr;
149+
proxy_set_header X-Forwarded-Proto $access_scheme;
150+
proxy_set_header X-Forwarded-Port $forwarded_port;
151+
proxy_redirect off;
152+
proxy_http_version 1.1;
153+
proxy_set_header Upgrade $http_upgrade;
154+
proxy_set_header Connection $connection_upgrade;
155+
proxy_pass http://{{$routerConfig.DefaultServiceIP}}:80;
156+
}
157+
}
158+
{{ else }}
159+
131160
# Default server handles requests for unmapped hostnames, including healthchecks
132161
server {
133162
listen 8080 default_server reuseport{{ if $routerConfig.UseProxyProtocol }} proxy_protocol{{ end }};
@@ -152,6 +181,7 @@ http {
152181
return 404;
153182
}
154183
}
184+
{{ end }}
155185
156186
# Healthcheck on 9090 -- never uses proxy_protocol
157187
server {

0 commit comments

Comments
 (0)