Skip to content

The reverse proxy and TLS#

The Empowerment Center frontend is both the web application server and the reverse proxy to the backend. This page explains how to publish it with TLS, alone or behind the organization's proxy, which headers it sets and removes, how to replace it with another web server and how to share the load among several backend instances.

The frontend variables#

Variable Default What it is
ECENTER_BACKEND_URL http://backend:8080 The backend, without a trailing slash.
ECENTER_RESOLVER 127.0.0.11 The DNS with which the backend name is resolved on each request: Docker's or, in Kubernetes, the cluster's. This way a backend that restarts with another address is still found.
ECENTER_CLIENT_MAX_BODY_SIZE 100m The largest body accepted. It must be at least ECENTER_MAX_UPLOAD, the largest file the backend accepts (100MB).
ECENTER_BEHIND_PROXY off on if there is another proxy in front.
ECENTER_CSP_MAP_ORIGINS (empty) The base map origins, separated by spaces (https://api.maptiler.com).
ECENTER_CSP_IDP_ORIGINS (empty) The origins of the identity provider to which SAML sign-out sends a form, separated by spaces.

In deploy/compose.yaml, the last four are taken from deploy/.env.

Two ways to set up TLS#

Two ways to set up TLS Two variants: with another proxy that terminates TLS, the proxy sets and overwrites the X-Forwarded-* and the frontend respects them; with the frontend as the entry point, the frontend terminates TLS on 8443 and calculates the X-Forwarded-* without trusting the client's. In both cases it removes Forwarded, X-Forwarded-Prefix and X-Forwarded-Ssl. HTTPS HTTP sets X-Forwarded-Proto, -Host, -Port; overwrites X-Forwarded-For; HSTS respects the X-Forwarded-* received; removes Forwarded, X-Forwarded-Prefix and X-Forwarded-Ssl HTTPS :8443 calculates the X-Forwarded-*; does not trust the client's; removes Forwarded, X-Forwarded-Prefix and X-Forwarded-Ssl Another proxy terminates TLS The frontend is the entry point Client Organization's proxy Frontend ECENTER_BEHIND_PROXY=on Backend Client Frontend with TLS ECENTER_BEHIND_PROXY=off Backend
Two ways to set up TLS Two variants: with another proxy that terminates TLS, the proxy sets and overwrites the X-Forwarded-* and the frontend respects them; with the frontend as the entry point, the frontend terminates TLS on 8443 and calculates the X-Forwarded-* without trusting the client's. In both cases it removes Forwarded, X-Forwarded-Prefix and X-Forwarded-Ssl. HTTPS HTTP sets X-Forwarded-Proto, -Host, -Port; overwrites X-Forwarded-For; HSTS respects the X-Forwarded-* received; removes Forwarded, X-Forwarded-Prefix and X-Forwarded-Ssl HTTPS :8443 calculates the X-Forwarded-*; does not trust the client's; removes Forwarded, X-Forwarded-Prefix and X-Forwarded-Ssl Another proxy terminates TLS The frontend is the entry point Client Organization's proxy Frontend ECENTER_BEHIND_PROXY=on Backend Client Frontend with TLS ECENTER_BEHIND_PROXY=off Backend
Two ways to set up TLS View full size View full size

A load balancer, a Traefik or the organization's proxy receives HTTPS and sends the traffic to the frontend over HTTP.

  1. Set ECENTER_BEHIND_PROXY=on in deploy/.env and recreate the frontend.
  2. Configure the proxy in front to send everything for its name to http://<server>:<ECENTER_HTTP_PORT>/, without changing the path.
  3. Make the proxy in front set X-Forwarded-Proto, X-Forwarded-Host, X-Forwarded-Port and X-Forwarded-For, and remove those the client brings.
  4. Make it overwrite X-Forwarded-For with the address it sees, instead of adding it to the one the client brings.
  5. Set HSTS (Strict-Transport-Security) on that proxy.

With on, the frontend respects the X-Forwarded-* it receives and adds its own address to X-Forwarded-For. The backend takes the first address of that list as the client's: if the proxy in front does not overwrite it, each client chooses with which address it appears in the audit and in the sessions.

The frontend receives users directly, with ECENTER_BEHIND_PROXY=off (the default). It calculates the X-Forwarded-* itself and does not trust those the client brings.

For it to terminate TLS itself:

  1. Copy the image's template, /etc/nginx/templates/default.conf.template (in the sources, frontend/nginx/ecenter.conf.template), for example to deploy/nginx/default.conf.template.
  2. In the copy, replace listen 8080; with these three lines:

    listen 8443 ssl;
    ssl_certificate /etc/nginx/tls/cert.pem;
    ssl_certificate_key /etc/nginx/tls/key.pem;
    
  3. Mount the modified template over the image's one and the certificate in /etc/nginx/tls/, and publish 8443 instead of 8080. With Docker Compose, in a deploy/compose.override.yaml:

    services:
      frontend:
        volumes:
          - ./nginx/default.conf.template:/etc/nginx/templates/default.conf.template:ro
          - ./tls:/etc/nginx/tls:ro
        ports: !override
          - "443:8443"
    

    !override replaces the ports of compose.yaml instead of adding to them (Docker Compose 2.24 or later). With -f deploy/compose.yaml, also add -f deploy/compose.override.yaml to each command.

  4. Recreate the frontend.

nginx runs unprivileged (user 101): that user must be able to read the certificate key. Keep everything else of the template in your copy: the paths that go to the backend, the headers and the ECENTER_* variables, which the image substitutes at startup. When upgrading ECenter, compare your copy with the new template.

What goes to the backend#

The frontend sends these paths to the backend, untouched, and serves the web application on all the others:

Prefix What it is
/api/ The API.
/embed/ The embedding page, the print mode of the headless browser and the embedding SDK.
/.well-known/oauth-protected-resource/ The MCP server's metadata.
/oauth2/, /login/oauth2/ The OIDC round trip.
/saml2/, /login/saml2/ The SAML round trip, and its sign-out.

/ayuda/ is the manuals, which the frontend itself serves (see The manuals at /ayuda/), with the English ones at /ayuda/en/; /ayuda without a slash redirects to /ayuda/. The rest is the web application: the file, if it exists, and if not index.html.

Headers#

Toward the backend, the frontend sets Host and the four X-Forwarded-* (its own, or those of the proxy in front with ECENTER_BEHIND_PROXY=on), and always removes three headers that the client could choose and that the backend also reads:

Header removed Why
Forwarded The backend would prefer it to the X-Forwarded-* for the address, the name and the scheme. As the frontend removes it, the proxy in front has to give the X-Forwarded-*: Forwarded is not used.
X-Forwarded-Prefix It would change the path of redirects.
X-Forwarded-Ssl It would change the scheme.

With that data the backend rebuilds the original request: the identity provider's return addresses, secure cookies behind TLS and the client address that the audit and the sessions record.

Toward the browser, the frontend sets on the web application:

Header Value
X-Frame-Options DENY
Content-Security-Policy frame-ancestors 'none': nobody can frame the application.
X-Content-Type-Options nosniff
Referrer-Policy strict-origin-when-cross-origin
Content-Security-Policy-Report-Only The complete content policy, with the origins of ECENTER_CSP_MAP_ORIGINS and ECENTER_CSP_IDP_ORIGINS.
Permissions-Policy It turns off what the application does not use: accelerometer, camera, screen capture, geolocation, gyroscope, HID, magnetometer, microphone, MIDI, payment, serial port and USB. Fullscreen and the clipboard remain.

The manuals at /ayuda/ carry the same headers, with their own content policy (also report-only): their inline scripts go by their hash, which is calculated when building the image.

To what comes from the backend it sets none: the embedding page carries its own frame-ancestors with the origins of each host application, and another header would break it. If you put another proxy in front, it must not add framing headers to the /embed/ paths either.

The content policy#

In version 8.0 the content policy only reports: whatever violates it appears in the browser developer tools console and is neither blocked nor sent anywhere. Check yours like this:

  1. Open the application with the browser developer tools open, in the console tab.
  2. Go through what is used in your installation: a map with its base map and, if there is SAML, signing out of the application.
  3. If a warning “… violates the following Content Security Policy directive …” appears, add the origin it names to ECENTER_CSP_MAP_ORIGINS or ECENTER_CSP_IDP_ORIGINS and recreate the frontend.

Cache, compression and timeouts#

  • The application's fingerprinted files (main-….js, chunk-….js, styles-….css) are cached for a year; fonts, for a day; index.html and the rest are checked again on each visit. After an upgrade, users load the new version when reloading.
  • In the manuals, fingerprinted files are cached for a year, fonts for a day, screenshots for an hour, and pages and the search index are checked again on each visit.
  • Everything goes compressed, including the GeoJSON and the map tiles.
  • Timeouts toward the backend are 300 s between two reads. A long download (the audit export can last up to 30 minutes) is not cut off while data keeps arriving. A proxy in front should not cut it off earlier.

Another web server instead of the frontend#

If the organization already has its own proxy (nginx, Apache, HAProxy or a Kubernetes Ingress), it can serve the web application with it:

  1. Copy the application files to the web server (the dist/frontend/browser folder of the build, or the contents of /usr/share/nginx/html of the frontend image).
  2. Send the paths of What goes to the backend to the backend, without changing the path.
  3. Serve index.html on any other path that is not a file.
  4. Set its headers on the web application and leave those of the backend untouched.
  5. Set the X-Forwarded-*, overwrite X-Forwarded-For and remove Forwarded, X-Forwarded-Prefix and X-Forwarded-Ssl.
  6. Adjust the timeouts (300 s) and the maximum body size (at least ECENTER_MAX_UPLOAD).
  7. If you want the manuals, serve at /ayuda/ the site that manuales/construir.sh leaves in manuales/site/ (or the contents of /usr/share/nginx/ayuda of the frontend image), with the English manuals inside it, in en/. python3 frontend/nginx/help-site.py manuales/site /ayuda/ help-csp.conf removes the printable version and the PDFs, puts the prefix in its error page and writes its content policy.
  8. Tell the backend where to read index.html for embedding with ECENTER_EMBEDDING_INDEX_LOCATION: a URL that serves it (http://frontal/index.html) or a file (file:/srv/ecenter/frontend/index.html).

Several backend instances#

Jobs and their results live in the memory of the instance that calculates them, so the load balancer must always send the requests of the same client to the same instance. The affinity key is, in this order:

  1. the X-ECenter-Embed-Session header, sent by an embedded document and by the headless browser;
  2. the Authorization header, of the query API and the MCP;
  3. the SESSION cookie, of the application.

With nginx, replacing proxy_pass $ecenter_backend in the backend paths with proxy_pass http://ecenter_backend:

map "$http_x_ecenter_embed_session|$http_authorization|$cookie_SESSION" $ecenter_affinity {
    "~^(?<embed>[^|]+)\|" $embed;
    "~^\|(?<bearer>[^|]+)\|" $bearer;
    default $cookie_SESSION;
}
upstream ecenter_backend {
    hash $ecenter_affinity consistent;
    server backend-1:8080;
    server backend-2:8080;
}

Each instance carries its ECENTER_INSTANCE_NAME and its own headless browser. What the instances share and what they do not is in Architecture.

Common problems#

Symptom Cause What to do
After signing in with the identity provider, it rejects the return address, or the return goes to http:// instead of https://. The backend does not receive the original scheme or name. With a proxy in front, ECENTER_BEHIND_PROXY=on and that proxy must set X-Forwarded-Proto and X-Forwarded-Host. Without containers, SERVER_FORWARD_HEADERS_STRATEGY=framework.
The audit and the sessions record the proxy's address, not the user's. The proxy in front does not set X-Forwarded-For, or ECENTER_BEHIND_PROXY=on is missing. Configure it as in Two ways to set up TLS.
An external data upload fails with 413. The file exceeds ECENTER_CLIENT_MAX_BODY_SIZE or ECENTER_MAX_UPLOAD, or the limit of a proxy in front. Raise all three at once.
Embedding is not shown in the host application. A proxy in front adds X-Frame-Options or frame-ancestors to /embed/. Remove those headers from the backend paths.
With several instances, a cube stays loading or disappears when moving to another window. The load balancer distributes without affinity. Configure the affinity of Several backend instances.

See also#