Skip to content

Commit 294a5a2

Browse files
authored
Add configuration options for supporting Kubernetes usage (#8)
1 parent 401f192 commit 294a5a2

3 files changed

Lines changed: 27 additions & 9 deletions

File tree

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ ENV DOMAINNAMES ${DOMAINNAMES}
1313
ENV TERM xterm
1414
ENV HAPROXY_USER_PARAMS ${HAPROXY_USER_PARAMS}
1515
ENV HAPROXY_CONFIG ${HAPROXY_CONFIG:-/etc/haproxy/haproxy.cfg}
16+
ENV HTTP_PORT ${HTTP_PORT:-80}
17+
ENV HTTPS_PORT ${HTTPS_PORT:-443}
18+
ENV HTTPS_FORWARDED_PORT ${HTTPS_FORWARDED_PORT:-%[dst_port]}
19+
ENV NAMESERVER ${NAMESERVER:-127.0.0.11:53}
1620
ENV PROXY_LOGLEVEL ${PROXY_LOGLEVEL:-notice}
1721
ENV MANAGER_HOST ${MANAGER_HOST:-manager}
1822
ENV MANAGER_WEB_PORT ${MANAGER_WEB_PORT:-8080}

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
# HAProxy docker image
2+
23
[![Docker Image](https://github.com/openremote/proxy/actions/workflows/proxy.yml/badge.svg)](https://github.com/openremote/proxy/actions/workflows/proxy.yml)
34

45
HAProxy docker image with Lets Encrypt SSL auto renewal using certbot with built in support for wildcard certificates using AWS Route53.
56

67
## Paths
8+
79
* `/deployment/letsencrypt` - Certbot config directory where generated certificates are stored
810
* `/etc/haproxy/haproxy.cfg` - Default location of haproxy configuration file
911
* `/etc/haproxy/certs` - Static (non certbot) certificates includes self-signed and any other static certificates should be volume mapped into this folder
1012
* `/var/log/*` - Location of log files (all are symlinked to stdout)
1113

1214
## Environment variables
15+
1316
* `DOMAINNAME` - IANA TLD subdomain for which a Lets Encrypt certificate should be requested
1417
* `DOMAINNAMES` - Comma separated list of IANA TLD subdomain names for which Lets Encrypt certificates should be
1518
requested (this is a multi-value alternative to DOMAINNAME)
1619
* `HAPROXY_USER_PARAMS` - Additional arguments that should be passed to the haproxy process during startup
1720
* `HAPROXY_CONFIG` - Location of HAProxy config file (default: `/etc/haproxy/haproxy.cfg`)
1821
* `PROXY_LOGLEVEL` - Log level for HAProxy (default: `notice`)
22+
* `HTTP_PORT` - The container binds to this port for handling HTTP requests (default: `80`)
23+
* `HTTPS_PORT` - The container binds to this port for handling HTTPS requests (default: `443`)
24+
* `HTTPS_FORWARDED_PORT` - The port set in the `X-Forwarded-Port` header of requests send to the Manager/Keycloak (default: `%[dst_port]` this is the HAProxy port)
25+
* `NAMESERVER` - The nameserver hostname and port used for resolving the Manager/Keycloak hosts (default: `127.0.0.11:53`)
1926
* `MANAGER_HOST` - Hostname of OpenRemote Manager (default: `manager`)
2027
* `MANAGER_WEB_PORT` - Web server port of OpenRemote Manager (default `8080`)
2128
* `MANAGER_MQTT_PORT` - MQTT broker port of OpenRemote Manager (default `1883`)
@@ -31,12 +38,22 @@ requested (this is a multi-value alternative to DOMAINNAME)
3138
* `MQTT_RATE_LIMIT` - Enable rate limiting for MQTT connections (connections/s)
3239

3340
## Custom certificate format
41+
3442
Any custom certificate volume mapped into `/etc/haproxy/certs` should be in PEM format and must include the full certificate chain and the private key, i.e.:
35-
```
36-
cat privkey.pem cert.pem chain.pem > ssl-certs.pem
43+
```shell
44+
cat privkey.pem cert.pem chain.pem > ssl-certs.pem
3745
```
3846

3947
See `haproxy` SSL cert [documentation](https://www.haproxy.com/blog/haproxy-ssl-termination/#enabling-ssl-with-haproxy).
4048

4149
## Edge gateway tunnelling using SISH
50+
4251
The built in `haproxy.cfg` has support for forwarding requsts beginning with `gw-` to `https://SISH_HOST:SISH_PORT` just define these environment variables to enable this.
52+
53+
## Kubernetes
54+
55+
When running the proxy in Kubernetes make sure to set the `HTTP_PORT` and `HTTPS_PORT` environment variables to a non-privileged port (> 1024).
56+
If you use an Ingress, reconfigure the `HTTPS_FORWARDED_PORT` to the HTTPS port of your Ingress (443).
57+
58+
You will also need to set the `NAMESERVER` environment variable to the cluster DNS (usually 10.96.0.10:53).
59+
The cluster DNS typically only resolves fully qualified hostnames, so make sure to set these using the `MANAGER_HOST` and `KEYCLOAK_HOST` environment variables (e.g. `manager.default.svc.cluster.local`).

haproxy.cfg

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ defaults
3030
default-server init-addr none
3131

3232
resolvers docker_resolver
33-
nameserver dns 127.0.0.11:53
33+
nameserver dns "${NAMESERVER}"
3434

3535
frontend stats
3636
bind *:8404
@@ -40,7 +40,7 @@ frontend stats
4040
stats refresh 10s
4141

4242
frontend http
43-
bind *:80
43+
bind *:"${HTTP_PORT}"
4444

4545
# Serve certificate validation challenges directly with Lua plugin
4646
acl url_acme_http01 path_beg /.well-known/acme-challenge/
@@ -55,7 +55,7 @@ frontend http
5555
redirect scheme https code 301 if !url_acme_http01 !url_docker_health
5656

5757
frontend https
58-
bind *:443 ssl crt /etc/haproxy/certs crt "${CERT_DIR}" no-tls-tickets
58+
bind *:"${HTTPS_PORT}" ssl crt /etc/haproxy/certs crt "${CERT_DIR}" no-tls-tickets
5959

6060
# Optional: redirects for root requests with certain host names to service paths
6161
acl is_root path -i /
@@ -105,7 +105,7 @@ frontend https
105105
option forwardfor
106106
http-request add-header X-Forwarded-Proto https
107107
http-request set-header X-Forwarded-Host %[req.hdr(Host)]
108-
http-request add-header X-Forwarded-Port %[dst_port]
108+
http-request add-header X-Forwarded-Port "${HTTPS_FORWARDED_PORT}"
109109
# Enforce HSTS
110110
http-response add-header Strict-Transport-Security max-age=15768000
111111
# Block bot indexing
@@ -150,9 +150,6 @@ backend manager_backend
150150

151151
backend keycloak_backend
152152
server keycloak "${KEYCLOAK_HOST}":"${KEYCLOAK_PORT}" resolvers docker_resolver
153-
.if defined(KEYCLOAK_PATH_PREFIX)
154-
http-request replace-path ^"${KEYCLOAK_PATH_PREFIX}"(/.*)?$ \1
155-
.endif
156153

157154
# Gateway tunnelling config
158155
.if defined(SISH_HOST) && defined(SISH_PORT)

0 commit comments

Comments
 (0)