100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Support for vanity domain redirects in proxy configuration
Christian Bauer1c6e5621c13d
diff --git a/profile/demo.yml b/profile/demo.ymlindex 7eb3157df..9f2832498 100644--- a/profile/demo.yml+++ b/profile/demo.yml@@ -62,6 +62,9 @@ services:# Store data either in host-mapped directory or a named Docker volume# - ${DEPLOYMENT_DIRECTORY:-../deployment}/proxy:/deployment# - proxy-data:/deployment+ #+ # Override the haproxy.cfg with custom file+ # -${MY_PROXY_CONFIG_FILE}:/etc/haproxy/haproxy.cfg# This configuration uses the manager's deployment-specific data such as map tiles,# console application static resources (HTML, JS, CSS), extensions, and otherdiff --git a/profile/deploy.yml b/profile/deploy.ymlindex 1803783db..455eddf05 100644--- a/profile/deploy.yml+++ b/profile/deploy.yml@@ -13,7 +13,7 @@ version: '2.2'services:- # The frontend proxy, terminates SSL/TLS connections and forwards them to the Manager backend.+ # The frontend proxy manages SSL certificates, terminates SSL/TLS connections and forwards them to the backend.proxy:# Image will be built when not already in the cache or when `--build` option is supplied to `docker-compose up`@@ -29,25 +29,37 @@ services:# Bearer tokens are only valid for minutes, and authentication fails if Keycloak drifts.TZ: Europe/Zurich- # The public host name of this OpenRemote installation. This is used to resolve the SSL- # certificate chain and manage your certificates. The localhost has a baked in self-signed- # certificate. If you change this name, also adjust manager#IDENTITY_NETWORK_HOST.- #DOMAINNAME: localhost-- # Provide your own email address for your SSL certificates!- LE_EMAIL: '[email protected]'-- # --staging requests fake certificates to avoid hitting limits during testing- #LE_EXTRA_ARGS: '--staging --logs-dir=/etc/letsencrypt'-- # Traffic should be forwarded to this service- PROXY_BACKEND_HOST: manager- PROXY_BACKEND_PORT: 8080-- # Customize log output- PROXY_LOGLEVEL: 'notice'-- # Run proxy, obtain and automatically renew SSL certificates if DOMAINNAME is not localhost (see help)+ # The public host name of this OpenRemote installation. Set this to request/manage an SSL+ # certificate with the free https://letsencrypt.org/ provider. The default 'localhost' will+ # rely on a baked-in self-signed certificate. If you change this, adjust manager#IDENTITY_NETWORK_HOST.+ # DOMAINNAME: localhost++ # Provide your own email address for your SSL certificates with Let's Encrypt. This should+ # be set when DOMAINNAME is not 'localhost'.+ # LE_EMAIL: '[email protected]'++ # Enable --staging will manage fake certificates, so avoid hitting the rate limits of Let's Encrypt+ # when testing (this is important, you are limited to 5 duplicate certificates per week!)+ # LE_EXTRA_ARGS: '--staging --logs-dir=/etc/letsencrypt'++ # Traffic should be forwarded to this service (defaults to manager:8080)+ # PROXY_BACKEND_HOST: manager+ # PROXY_BACKEND_PORT: 8080++ # The proxy supports up to 10 custom redirects from hostname to any path on the+ # backend service. This can be used to give consoles a vanity domain name.+ # PROXY_HOST_REDIRECT_1_NAME: www.my-console-master.tld+ # PROXY_HOST_REDIRECT_1_TARGET: /console/master+ # PROXY_HOST_REDIRECT_2_NAME: www.my-console-customer-a.tld+ # PROXY_HOST_REDIRECT_2_TARGET: /console/customerA+ # PROXY_HOST_REDIRECT_3_NAME: ...++ # Customize proxy log, defaults to 'notice', requests are logged at 'info'.+ # Available levels are: emerg, alert, crit, err, warning, notice, info, debug+ # PROXY_LOGLEVEL: 'notice'++ # Run proxy, obtain and automatically renew SSL certificates if DOMAINNAME is not localhost. Use+ # the command 'help' to get a list of all options.command: run# Expose a public web service mapped to ports on the host.@@ -75,6 +87,8 @@ services:environment:+ # It is important that all services have the same timezone and are time synchronized.+ # Bearer tokens are only valid for minutes, and authentication fails if Keycloak drifts.TZ: Europe/Zurich# If developer mode is enabled, all setup tasks will be executed on application startup.@@ -110,17 +124,17 @@ services:#SETUP_IMPORT_DEMO_AGENT: 'true'SETUP_IMPORT_DEMO_AGENT_KNX: 'false'- #SETUP_IMPORT_DEMO_AGENT_KNX_GATEWAY_IP: '10.0.0.11'- #SETUP_IMPORT_DEMO_AGENT_KNX_LOCAL_IP: '10.0.0.12'+ # SETUP_IMPORT_DEMO_AGENT_KNX_GATEWAY_IP: '10.0.0.11'+ # SETUP_IMPORT_DEMO_AGENT_KNX_LOCAL_IP: '10.0.0.12'SETUP_IMPORT_DEMO_AGENT_VELBUS: 'false'- #SETUP_IMPORT_DEMO_AGENT_VELBUS_COM_PORT: 'COM3'+ # SETUP_IMPORT_DEMO_AGENT_VELBUS_COM_PORT: 'COM3'SETUP_IMPORT_DEMO_AGENT_UPNP: 'false'# TODO: Additional docker settings are necessary to use com ports and multicast from within containers# The public host name of this OpenRemote installation. This name is used in bearer tokens# and must be the name you access the web services under. If you change proxy#DOMAINNAME, also# change this to match.- #IDENTITY_NETWORK_HOST: localhost+ # IDENTITY_NETWORK_HOST: localhost# Set if SSL is enabled on the frontend reverse proxy and all internal proxies should assume httpsIDENTITY_NETWORK_SECURE: 'true'@@ -215,6 +229,9 @@ services:image: openremote/keycloak:latestenvironment:++ # It is important that all services have the same timezone and are time synchronized.+ # Bearer tokens are only valid for minutes, and authentication fails if Keycloak drifts.TZ: Europe/Zurich# Switch to DEBUG to diagnose Keycloak problems.@@ -261,6 +278,9 @@ services:image: openremote/postgresql:latestenvironment:++ # It is important that all services have the same timezone and are time synchronized.+ # Bearer tokens are only valid for minutes, and authentication fails if Keycloak drifts.TZ: Europe/Zurich# Create database and user if there is no data. For production, rundiff --git a/proxy/entrypoint.sh b/proxy/entrypoint.shindex a6587f7e5..5a63301be 100644--- a/proxy/entrypoint.sh+++ b/proxy/entrypoint.sh@@ -1,34 +1,26 @@#!/bin/bash-# Create directories-mkdir -p /deployment/acme-webroot-mkdir -p /deployment/letsencrypt/live-# Configure letsencrypt+export LE_WEB_ROOT="/deployment/acme-webroot"+mkdir -p $LE_WEB_ROOTif [ -n "${LE_EMAIL}" ]; thenLE_EXTRA_ARGS+=" --email ${LE_EMAIL}"fi-if [ -n "${LE_RSA_KEY_SIZE}" ]; thenLE_EXTRA_ARGS+=" --rsa-key-size ${LE_RSA_KEY_SIZE}"fi-LE_WORK_DIR="/deployment/letsencrypt"-LE_CERT_ROOT="${LE_WORK_DIR}/live"-LE_WEB_ROOT="/deployment/acme-webroot"-LE_ARCHIVE_ROOT="/deployment/letsencrypt/archive"-LE_RENEWAL_CONFIG_ROOT="/deployment/letsencrypt/renewal"+export LE_CERT_ROOT="${LE_WORK_DIR}/live"+LE_ARCHIVE_ROOT="${LE_WORK_DIR}/archive"+LE_RENEWAL_CONFIG_ROOT="${LE_WORK_DIR}/renewal"LE_CMD="/usr/bin/certbot certonly --config-dir ${LE_WORK_DIR} -w ${LE_WEB_ROOT} ${LE_EXTRA_ARGS}"+mkdir -p $LE_CERT_ROOT# Configure haproxy-CERT_FILE="/opt/selfsigned/localhost.pem"+export CERT_FILE="/opt/selfsigned/localhost.pem"if [ -n "${DOMAINNAME}" ] && [ "${DOMAINNAME}" != "localhost" ]; then- CERT_FILE="/deployment/letsencrypt/live/${DOMAINNAME}/haproxy.pem"+ export CERT_FILE="${LE_CERT_ROOT}/${DOMAINNAME}/haproxy.pem"fi-export CERT_FILE=${CERT_FILE}-export PROXY_LOGLEVEL=${PROXY_LOGLEVEL}--# Assumeif [ ! -f ${CERT_FILE} ]; thenINIT=trueHAPROXY_CONFIG="/etc/haproxy/haproxy-init.cfg"@@ -78,13 +70,13 @@ function run_proxy {restartfi- log_info "Monitoring config file and cert $LE_WORK_DIR for changes..."+ log_info "Monitoring config file $HAPROXY_CONFIG and certs in $LE_CERT_ROOT for changes..."# Wait if config or certificates were changed, block this execution- while inotifywait -q -r --exclude '\.git/' -e modify,create,delete,move,move_self $HAPROXY_CONFIG $LE_WORK_DIR; do+ while inotifywait -q -r --exclude '\.git/' -e modify,create,delete,move,move_self $HAPROXY_CONFIG $LE_CERT_ROOT; dolog_info "Change detected..."restart- log_info "Monitoring config file and cert $LE_WORK_DIR for changes..."+ log_info "Monitoring config file $HAPROXY_CONFIG and certs in $LE_CERT_ROOT for changes..."done}@@ -377,9 +369,7 @@ function cron_auto_renewal {# Start crond if not runningif ! [ -f /var/run/crond.pid ]; then- log_info "CRON daemon starting..."service cron start- log_info "CRON daemon started"fi}@@ -388,6 +378,7 @@ log_info "HAPROXY_CERT_FILE: ${CERT_FILE}"log_info "HAPROXY_CONFIG: ${HAPROXY_CONFIG}"log_info "HAPROXY_CMD: ${HAPROXY_CMD}"log_info "HAPROXY_USER_PARAMS: ${HAPROXY_USER_PARAMS}"+log_info "PROXY_LOGLEVEL: ${PROXY_LOGLEVEL}"log_info "LE_CERT_ROOT: ${LE_CERT_ROOT}"log_info "LE_ARCHIVE_ROOT: ${LE_ARCHIVE_ROOT}"log_info "LE_RENEWAL_CONFIG_ROOT: ${LE_RENEWAL_CONFIG_ROOT}"diff --git a/proxy/haproxy-init.cfg b/proxy/haproxy-init.cfgindex a98ba23dc..93fa69612 100644--- a/proxy/haproxy-init.cfg+++ b/proxy/haproxy-init.cfg@@ -1,26 +1,19 @@#-# Serve ACME certificate validation challenges and act as an-# SSL reverse-proxy for host "manager:8080"+# Serve ACME certificate validation challenges and nothing else. This+# configuration is only used when an SSL certificate is generated for+# the first time. As soon as the certificate file exists, we switch to+# the regular haproxy.cfg.#globallog 127.0.0.1:514 local0 "${PROXY_LOGLEVEL}"# Used for serving certificate validation challenges- chroot /deployment/acme-webroot+ chroot "${LE_WEB_ROOT}"lua-load /etc/haproxy/acme-http01-webroot.lua- # Default SSL material locations, managed by letsencrypt container- crt-base /deployment/letsencrypt/live-- maxconn 1024- ssl-default-bind-ciphers AES256+EECDH:AES256+EDH:!aNULL;- tune.ssl.default-dh-param 4096-defaultslog globalmode http- # Enable to see detailed logs- # option httplogtimeout connect 30stimeout client 60stimeout server 60sdiff --git a/proxy/haproxy.cfg b/proxy/haproxy.cfgindex bdb3bbf05..a66687a7f 100644--- a/proxy/haproxy.cfg+++ b/proxy/haproxy.cfg@@ -1,16 +1,16 @@## Serve ACME certificate validation challenges and act as an-# SSL reverse-proxy for host "manager:8080"+# SSL reverse-proxy for an arbitrary backend service.#globallog 127.0.0.1:514 local0 "${PROXY_LOGLEVEL}"# Used for serving certificate validation challenges- chroot /deployment/acme-webroot+ chroot "${LE_WEB_ROOT}"lua-load /etc/haproxy/acme-http01-webroot.lua# Default SSL material locations, managed by certbot- crt-base /deployment/letsencrypt/live+ crt-base "${LE_CERT_ROOT}"maxconn 1024ssl-default-bind-ciphers AES256+EECDH:AES256+EDH:!aNULL;@@ -19,8 +19,7 @@ globaldefaultslog globalmode http- # Enable to see detailed logs- # option httplog+ option httplogtimeout connect 30stimeout client 60stimeout server 60s@@ -32,18 +31,40 @@ frontend http# Serve certificate validation challenges directly with Lua pluginacl url_acme_http01 path_beg /.well-known/acme-challenge/http-request use-service lua.acme-http01 if METH_GET url_acme_http01++ # Optional: redirects for root requests with certain host names to service paths+ acl is_root path -i /+ acl is_redirect_1 hdr(host) -i "${PROXY_HOST_REDIRECT_1_NAME}"+ acl is_redirect_2 hdr(host) -i "${PROXY_HOST_REDIRECT_2_NAME}"+ acl is_redirect_3 hdr(host) -i "${PROXY_HOST_REDIRECT_3_NAME}"+ acl is_redirect_4 hdr(host) -i "${PROXY_HOST_REDIRECT_4_NAME}"+ acl is_redirect_5 hdr(host) -i "${PROXY_HOST_REDIRECT_5_NAME}"+ acl is_redirect_6 hdr(host) -i "${PROXY_HOST_REDIRECT_6_NAME}"+ acl is_redirect_7 hdr(host) -i "${PROXY_HOST_REDIRECT_7_NAME}"+ acl is_redirect_8 hdr(host) -i "${PROXY_HOST_REDIRECT_8_NAME}"+ acl is_redirect_9 hdr(host) -i "${PROXY_HOST_REDIRECT_9_NAME}"+ acl is_redirect_10 hdr(host) -i "${PROXY_HOST_REDIRECT_10_NAME}"+ redirect code 302 location "https://${DOMAINNAME}${PROXY_HOST_REDIRECT_1_TARGET}" if is_root is_redirect_1+ redirect code 302 location "https://${DOMAINNAME}${PROXY_HOST_REDIRECT_2_TARGET}" if is_root is_redirect_2+ redirect code 302 location "https://${DOMAINNAME}${PROXY_HOST_REDIRECT_3_TARGET}" if is_root is_redirect_3+ redirect code 302 location "https://${DOMAINNAME}${PROXY_HOST_REDIRECT_4_TARGET}" if is_root is_redirect_4+ redirect code 302 location "https://${DOMAINNAME}${PROXY_HOST_REDIRECT_5_TARGET}" if is_root is_redirect_5+ redirect code 302 location "https://${DOMAINNAME}${PROXY_HOST_REDIRECT_6_TARGET}" if is_root is_redirect_6+ redirect code 302 location "https://${DOMAINNAME}${PROXY_HOST_REDIRECT_7_TARGET}" if is_root is_redirect_7+ redirect code 302 location "https://${DOMAINNAME}${PROXY_HOST_REDIRECT_8_TARGET}" if is_root is_redirect_8+ redirect code 302 location "https://${DOMAINNAME}${PROXY_HOST_REDIRECT_9_TARGET}" if is_root is_redirect_9+ redirect code 302 location "https://${DOMAINNAME}${PROXY_HOST_REDIRECT_10_TARGET}" if is_root is_redirect_10++ # Redirect all http requests to httpsredirect scheme https if !url_acme_http01frontend https-- # Demo certificate is self-signed- # Production certificate, should be created/stored/managed by letsencrypt sidecar container- bind :443 ssl no-tls-tickets crt "${CERT_FILE}" no-sslv3 no-tls-tickets no-tlsv10 no-tlsv11+ bind :443 ssl crt "${CERT_FILE}" no-sslv3 no-tls-tickets no-tlsv10 no-tlsv11reqadd X-Forwarded-Proto:\ httpsrspadd Strict-Transport-Security:\ max-age=15768000- use_backend custom_backend+ use_backend proxy_backend-backend custom_backend- server node1 "${PROXY_BACKEND_HOST}":"${PROXY_BACKEND_PORT}"+backend proxy_backend+ server proxy_backend_host "${PROXY_BACKEND_HOST}":"${PROXY_BACKEND_PORT}"