Skip to content

Commit 0b69877

Browse files
Merge pull request #92 from UKHomeOffice/teapot-debug-info
Conditionally present debug msg in SSI
2 parents b52f9c4 + f09b745 commit 0b69877

File tree

4 files changed

+77
-34
lines changed

4 files changed

+77
-34
lines changed

README.md

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Build Status](https://travis-ci.org/UKHomeOffice/docker-nginx-proxy.svg?branch=master)](https://travis-ci.org/UKHomeOffice/docker-nginx-proxy)
44

5-
This container aims to be a generic proxy layer for your web services. It includes OpenResty with
5+
This container aims to be a generic proxy layer for your web services. It includes OpenResty with
66
Lua and NAXSI filtering compiled in.
77

88
## Getting Started
@@ -23,15 +23,15 @@ In order to run this container you'll need docker installed.
2323

2424
#### Multi-location Variables
2525

26-
Variables to control how to configure the proxy (can be set per location, see
26+
Variables to control how to configure the proxy (can be set per location, see
2727
[Using Multiple Locations](#using-multiple-locations)).
2828

2929
* `PROXY_SERVICE_HOST` - The upstream host you want this service to proxy.
3030
* `PROXY_SERVICE_PORT` - The port of the upstream host you want this service to proxy.
31-
* `NAXSI_RULES_URL_CSV` - A CSV of [Naxsi](https://github.com/nbs-system/naxsi) URL's of files to download and use.
31+
* `NAXSI_RULES_URL_CSV` - A CSV of [Naxsi](https://github.com/nbs-system/naxsi) URL's of files to download and use.
3232
(Files must end in .rules to be loaded)
3333
* `NAXSI_RULES_MD5_CSV` - A CSV of md5 hashes for the files specified above
34-
* `EXTRA_NAXSI_RULES` - Allows NAXSI rules to be specified as an environment variable. This allows one or two extra
34+
* `EXTRA_NAXSI_RULES` - Allows NAXSI rules to be specified as an environment variable. This allows one or two extra
3535
rules to be specified without downloading or mounting in a rule file.
3636
* `NAXSI_USE_DEFAULT_RULES` - If set to "FALSE" will delete the default rules file.
3737
* `ENABLE_UUID_PARAM` - If set to "FALSE", will NOT add a UUID url parameter to all requests. The Default will add this
@@ -43,33 +43,34 @@ rules to be specified without downloading or mounting in a rule file.
4343
* `ERROR_REDIRECT_CODES` - Can override when Nginx will redirect requests to its own error page. Defaults to
4444
"`500 501 502 503 504`". To support a new code, say `505`, an error page must be provided at
4545
`/usr/local/openresty/nginx/html/505.shtml`, see [Useful File Locations](#useful-file-locations).
46-
* `ADD_NGINX_LOCATION_CFG` - Arbitrary extra NGINX configuration to be added to the location context, see
46+
* `ADD_NGINX_LOCATION_CFG` - Arbitrary extra NGINX configuration to be added to the location context, see
4747
[Arbitrary Config](#arbitrary-config).
4848
* `PORT_IN_HOST_HEADER` - If FALSE will remove the port from the http `Host` header.
4949
* `BASIC_AUTH` - Define a path for username and password file (in `username:password` format), this will turn the file into a .htpasswd file.
5050
* `REQS_PER_MIN_PER_IP` - Will limit requests based on IP e.g. set to 60 to allow one request per second.
5151
* `CONCURRENT_CONNS_PER_IP` - Will limit concurrent connections based on IP e.g. set to 10 to allow max of 10 connections per browser or proxy!
5252
* `REQS_PER_PAGE` - Will limit requests to 'bursts' of x requests at a time before terminating (will default to 20)
5353
* `DENY_COUNTRY_ON` - Set to `TRUE` to deny access to countries not listed in ALLOW_COUNTRY_CSV with 403 status for a location (set location for 403 with ADD_NGINX_LOCATION_CFG).
54+
* `VERBOSE_ERROR_PAGES` - Set to TRUE to display debug info in 418 error pages.
5455

5556
#### Single set Variables
5657

5758
Note the following variables can only be set once:
5859

59-
* `ADD_NGINX_SERVER_CFG` - Arbitrary extra NGINX configuration to be added to the server context, see
60+
* `ADD_NGINX_SERVER_CFG` - Arbitrary extra NGINX configuration to be added to the server context, see
6061
[Arbitrary Config](#arbitrary-config)
6162
* `ADD_NGINX_HTTP_CFG` - Arbitrary extra NGINX configuration to be added to the http context, see
6263
[Arbitrary Config](#arbitrary-config)
63-
* `LOCATIONS_CSV` - Set to a list of locations that are to be independently proxied, see the example
64-
[Using Multiple Locations](#using-multiple-locations). Note, if this isn't set, `/` will be used as the default
64+
* `LOCATIONS_CSV` - Set to a list of locations that are to be independently proxied, see the example
65+
[Using Multiple Locations](#using-multiple-locations). Note, if this isn't set, `/` will be used as the default
6566
location.
66-
* `LOAD_BALANCER_CIDR` - Set to preserve client IP addresses. *Important*, to enable, see
67+
* `LOAD_BALANCER_CIDR` - Set to preserve client IP addresses. *Important*, to enable, see
6768
[Preserve Client IP](#preserve-client-ip).
68-
* `NAME_RESOLVER` - Can override the *default* DNS server used to re-resolve the backend proxy (based on TTL).
69-
The *Default DNS Server* is the first entry in the resolve.conf file in the container and is normally correct and
70-
managed by Docker or Kubernetes.
69+
* `NAME_RESOLVER` - Can override the *default* DNS server used to re-resolve the backend proxy (based on TTL).
70+
The *Default DNS Server* is the first entry in the resolve.conf file in the container and is normally correct and
71+
managed by Docker or Kubernetes.
7172
* `CLIENT_MAX_BODY_SIZE` - Can set a larger upload than Nginx defaults in MB.
72-
* `HTTPS_REDIRECT_PORT` - Only required for http to https redirect and only when a non-standard https port is in use.
73+
* `HTTPS_REDIRECT_PORT` - Only required for http to https redirect and only when a non-standard https port is in use.
7374
This is useful when testing or for development instances or when a load-balancer mandates a non-standard port.
7475
* `LOG_FORMAT_NAME` - Can be set to `text` or `json` (default).
7576
* `NO_LOGGING_URL_PARAMS` - Can be set to `TRUE` if you don't want to log url params. Default is empty which means URL params are logged
@@ -100,17 +101,17 @@ N.B. see HTTP(S)_LISTEN_PORT above
100101
### Useful File Locations
101102

102103
* `nginx.conf` is stored at `/usr/local/openresty/nginx/conf/nginx.conf`
103-
* `/etc/keys/crt` & `/etc/keys/key` - A certificate can be mounted here to make OpenResty use it. However a self
104+
* `/etc/keys/crt` & `/etc/keys/key` - A certificate can be mounted here to make OpenResty use it. However a self
104105
signed one is provided if they have not been mounted.
105-
* `/etc/keys/client-ca` If a client CA is mounted here, it will be loaded and configured.
106+
* `/etc/keys/client-ca` If a client CA is mounted here, it will be loaded and configured.
106107
See `CLIENT_CERT_REQUIRED` above in [Environment Variables](#environment-variables).
107108
* `/etc/keys/upstream-server-ca` A CA public cert must be mounted here when verifying the upstream server's certificate is required.
108109
See `VERIFY_SERVER_CERT` above in [Environment Variables](#environment-variables).
109110
* `/etc/keys/upstream-client-crt` A public client cert must be mounted here when when the upstream server requires client cert authentication.
110111
See `USE_UPSTREAM_CLIENT_CERT` above in [Environment Variables](#environment-variables).
111112
* `/etc/keys/upstream-client-key` A private client key must be mounted here when when the upstream server requires client cert authentication.
112113
See `USE_UPSTREAM_CLIENT_CERT` above in [Environment Variables](#environment-variables).
113-
* `/usr/local/openresty/naxsi/*.conf` - [Naxsi](https://github.com/nbs-system/naxsi) rules location in default
114+
* `/usr/local/openresty/naxsi/*.conf` - [Naxsi](https://github.com/nbs-system/naxsi) rules location in default
114115
nginx.conf.
115116
* `/usr/local/openresty/nginx/html/$CODE.shtml` - HTML (with SSI support) displayed when a the status code $CODE
116117
is encountered upstream and the proxy is configured to intercept. See ERROR_REDIRECT_CODES to change this.
@@ -145,13 +146,13 @@ This proxy supports [Proxy Protocol](http://www.haproxy.org/download/1.5/doc/pro
145146

146147
To use this feature you will need:
147148

148-
* To enable [proxy protocol](http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt) on your load balancer.
149+
* To enable [proxy protocol](http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt) on your load balancer.
149150
For AWS, see [Enabling Proxy Protocol for AWS](http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/enable-proxy-protocol.html).
150-
* Find the private address range of your load balancer.
151+
* Find the private address range of your load balancer.
151152
For AWS, this could be any address in the destination network. E.g.
152153
if you have three compute subnets defined as 10.50.0.0/24, 10.50.1.0/24 and 10.50.2.0/24,
153154
then a suitable range would be 10.50.0.0/22 see [CIDR Calculator](http://www.subnet-calculator.com/cidr.php).
154-
155+
155156
```shell
156157
docker run -e 'PROXY_SERVICE_HOST=http://stackexchange.com' \
157158
-e 'PROXY_SERVICE_PORT=80' \
@@ -176,11 +177,11 @@ docker run -e 'PROXY_SERVICE_HOST=http://myapp.svc.cluster.local' \
176177

177178
#### Using Multiple Locations
178179

179-
When the LOCATIONS_CSV option is set, multiple locations can be proxied. The settings for each proxy location can be
180+
When the LOCATIONS_CSV option is set, multiple locations can be proxied. The settings for each proxy location can be
180181
controlled with the use of any [Multi-location Variables](#multi-location-variables) by suffixing the variable name with
181-
both a number, and the '_' character, as listed in the LOCATIONS_CSV variable.
182-
183-
##### Two servers
182+
both a number, and the '_' character, as listed in the LOCATIONS_CSV variable.
183+
184+
##### Two servers
184185

185186
The example below configures a simple proxy with two locations '/' (location 1) and '/api' (location 2):
186187

@@ -192,7 +193,7 @@ docker run -e 'PROXY_SERVICE_HOST_1=http://stackexchange.com' \
192193
-e 'LOCATIONS_CSV=/,/api' \
193194
-p 8443:443 \
194195
quay.io/ukhomeofficedigital/nginx-proxy:v1.0.0
195-
```
196+
```
196197

197198
For more detail, see the [generated config](./docs/GeneratedConfigs.md#two-separate-proxied-servers).
198199

@@ -235,7 +236,7 @@ docker run -e 'PROXY_SERVICE_HOST=http://serverfault.com' \
235236
-p 8443:443 \
236237
quay.io/ukhomeofficedigital/nginx-proxy:v1.0.0
237238
```
238-
See [./client_certs](./client_certs) for scripts that can be used to generate a CA and client certs.
239+
See [./client_certs](./client_certs) for scripts that can be used to generate a CA and client certs.
239240

240241
#### Upstream Client Certs
241242

@@ -332,19 +333,19 @@ docker run -e 'PROXY_SERVICE_HOST=http://serverfault.com' \
332333
quay.io/ukhomeofficedigital/nginx-proxy:v1.0.0
333334
```
334335

335-
this will setup basic-auth for the the `/about` location or simply swap the 2 for a 1 to setup basic auth for the root location.
336+
this will setup basic-auth for the the `/about` location or simply swap the 2 for a 1 to setup basic auth for the root location.
336337

337338

338339

339340
## Built With
340341

341342
* [OpenResty](https://openresty.org/) - OpenResty (aka. ngx_openresty) is a full-fledged web
342-
application server by bundling the standard Nginx core, lots of 3rd-party Nginx modules, as well
343+
application server by bundling the standard Nginx core, lots of 3rd-party Nginx modules, as well
343344
as most of their external dependencies.
344345
* [Nginx](https://www.nginx.com/resources/wiki/) - The proxy server core software.
345346
* [ngx_lua](http://wiki.nginx.org/HttpLuaModule) - Embed the power of Lua into Nginx
346-
* [Naxsi](https://github.com/nbs-system/naxsi) - NAXSI is an open-source, high performance, low
347-
rules maintenance WAF for NGINX
347+
* [Naxsi](https://github.com/nbs-system/naxsi) - NAXSI is an open-source, high performance, low
348+
rules maintenance WAF for NGINX
348349
* [GeoLite data](http://www.maxmind.com">http://www.maxmind.com) This product includes GeoLite data created by MaxMind.
349350
350351
## Find Us
@@ -354,22 +355,22 @@ this will setup basic-auth for the the `/about` location or simply swap the 2 fo
354355
355356
## Contributing
356357
357-
Feel free to submit pull requests and issues. If it's a particularly large PR, you may wish to
358+
Feel free to submit pull requests and issues. If it's a particularly large PR, you may wish to
358359
discuss it in an issue first.
359360
360-
Please note that this project is released with a [Contributor Code of Conduct](code_of_conduct.md).
361+
Please note that this project is released with a [Contributor Code of Conduct](code_of_conduct.md).
361362
By participating in this project you agree to abide by its terms.
362363
363364
## Versioning
364365
365-
We use [SemVer](http://semver.org/) for the version tags available See the tags on this repository.
366+
We use [SemVer](http://semver.org/) for the version tags available See the tags on this repository.
366367
367368
## Authors
368369
369370
* **Lewis Marshal** - *Initial work* - [lewismarshall](https://github.com/lewismarshall)
370371
371-
See also the list of
372-
[contributors](https://github.com/UKHomeOffice/docker-nginx-proxy/graphs/contributors) who
372+
See also the list of
373+
[contributors](https://github.com/UKHomeOffice/docker-nginx-proxy/graphs/contributors) who
373374
participated in this project.
374375
375376
## License

ci-build.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,33 @@ echo "Testing no logging of url params option works..."
477477
docker logs mockserver | grep 'Nginxid:'
478478
docker logs ${INSTANCE} | grep '"nginx_uuid": "'
479479

480+
start_test "Test VERBOSE_ERROR_PAGES=TRUE displays debug info" "${STD_CMD} \
481+
-e \"PROXY_SERVICE_HOST=http://mockserver\" \
482+
-e \"PROXY_SERVICE_PORT=8080\" \
483+
-e \"DNSMASK=TRUE\" \
484+
-e \"ENABLE_UUID_PARAM=FALSE\" \
485+
-e \"VERBOSE_ERROR_PAGES=TRUE\" \
486+
--link mockserver:mockserver "
487+
if curl -k https://${DOCKER_HOST_NAME}:${PORT}/\?\"==\` | grep "Sorry, we are refusing to process your request." ; then
488+
echo "Testing VERBOSE_ERROR_PAGES works..."
489+
else
490+
echo "Testing VERBOSE_ERROR_PAGES failed..."
491+
exit 1
492+
fi
493+
494+
start_test "Test VERBOSE_ERROR_PAGES is not set does not display debug info" "${STD_CMD} \
495+
-e \"PROXY_SERVICE_HOST=http://mockserver\" \
496+
-e \"PROXY_SERVICE_PORT=8080\" \
497+
-e \"DNSMASK=TRUE\" \
498+
-e \"ENABLE_UUID_PARAM=FALSE\" \
499+
--link mockserver:mockserver "
500+
if curl -k https://${DOCKER_HOST_NAME}:${PORT}/\?\"==\` | grep "Sorry, we are refusing to process your request." ; then
501+
echo "Testing VERBOSE_ERROR_PAGES failed..."
502+
exit 1
503+
else
504+
echo "Testing VERBOSE_ERROR_PAGES works..."
505+
fi
506+
480507
echo "_________________________________"
481508
echo "We got here, ALL tests successful"
482509
clean_up

html/418-request-denied.shtml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!--#if expr="${VERBOSE_ERROR_PAGES}=TRUE" -->
2+
<p>
3+
Sorry, we are refusing to process your request. If you believe we have
4+
made a mistake please raise a support ticket with the following
5+
information:
6+
</p>
7+
<code style="display: block;">
8+
ORIG URL: <!--#echo var="http_x_orig_url" --><br />
9+
ORIG ARGS: <!--#echo var="http_x_orig_args" --><br />
10+
CODE: <!--#echo var="http_x_naxsi_sig" --><br />
11+
TIME: <!--#config timefmt="%Y-%m-%dT%H:%M:%S %Z" --><!--#echo var="date_local" -->
12+
</code>
13+
<!--#endif -->

nginx.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ error_log /dev/stderr error;
33
env LOG_UUID;
44
env HTTPS_REDIRECT_PORT_STRING;
55
env ALLOW_COUNTRY_CSV;
6+
env VERBOSE_ERROR_PAGES;
67

78
http {
89

@@ -153,6 +154,7 @@ http {
153154
location /nginx-proxy/RequestDenied {
154155
# Debug information now available in headers ($http_x_naxsi_sig etc.)
155156
# Return a 418 (Teapot) status
157+
set_by_lua_file $verbose_error_pages lua/get_env.lua 'VERBOSE_ERROR_PAGES';
156158
error_page 418 /nginx-proxy/418-request-denied.shtml;
157159
return 418;
158160
}

0 commit comments

Comments
 (0)