docs

Running liuska serve securely

liuska serve renders whatever templates and data it receives. Templates can name files (fonts, images, snippets, sample data), so treat the API like any other service that reads from disk. This page covers the protections built in and how to set them up for a public demo or a shared deployment.

Quick start

Local use needs no setup. By default the server:

To expose the server:

# keys.txt: one key per line, "#" comments allowed. Generate keys with e.g.
#   openssl rand -base64 32
liuska serve --addr 0.0.0.0:8080 --templates ./templates \
  --api-key-file /run/secrets/liuska-keys --read-only

The server refuses to listen on a non-loopback address without API keys. Pass --no-auth to override this, but only when the port is reachable from trusted clients alone, such as a sidecar on a private network.

Flags

Flag Default Description
--addr 127.0.0.1:8080 Listen address. Use 0.0.0.0:PORT (or a specific interface) explicitly to accept remote connections.
--api-key KEY – Require this key. Repeatable. Flags show up in process lists, so prefer one of the next two.
--api-key-file FILE – Keys, one per line. Blank lines and # comments are ignored. Repeatable.
LIUSKA_API_KEYS / LIUSKA_API_KEY – Environment variables with comma-separated keys.
--read-only off Reject PUT, PATCH and DELETE under /api/, for example saving templates. Rendering (POST) still works.
--cors-origin ORIGIN – (CORS off) Allow browser calls from this exact origin, e.g. https://app.example.com. Repeatable. * is not accepted.
--allowed-host HOST localhost names on a loopback address; any otherwise Accepted Host header values (name or name:port). Repeatable. Set this behind a reverse proxy.
--asset-dir DIR – Extra directory templates may read images, snippets and sample data from. Repeatable.
--font-dir DIR – Font directory. It is also an allowed root for font files.
--max-body SIZE 32MB Maximum request body size. Bigger bodies get 413.
--timeout DUR 30s Deadline per API request, including time spent waiting for a render slot. On timeout the server answers 503. 0 disables it.
--max-concurrent N 2 × CPUs Number of POST /api/… requests (render, preview, validate, layout) that run at the same time. Others wait until --timeout, then get 503 with Retry-After.
--max-pages N 5000 Fail a render with 422 once the layout passes N pages.
--max-rows N 200000 Fail a render with 422 when one table has more than N data rows.
--no-auth off Allow a non-loopback address without keys.

PNG previews are also capped at 64 megapixels per page (an A4 page at 600 dpi is about 35 MP), and images whose header claims more than 100 megapixels are refused before they are decoded.

API keys

Send the key as Authorization: Bearer <key>. X-API-Key: <key> also works. Keys must be at least 16 characters with no whitespace.

GET /healthz and GET /api/healthz answer {"ok":true,"authRequired":true} without a key. With a valid key, or when no keys are configured, they also return version, templatesDir and readOnly.

Designer

When the server needs a key, the designer asks for it the first time an API call returns 401. It keeps the key in sessionStorage, so the key is forgotten when the tab is closed. The key is never saved in templates or localStorage. If you cancel the prompt, the designer stops asking until you reload the page. If the key is wrong, the server rejects it and the designer asks again.

Template file access

Templates can reference files in fonts[].src, image src (including paths that come from data bindings and file:// URLs), snippetPath and sampleDataFile. In serve, every such path has to resolve to a file inside an allowed root:

Rules:

The CLI commands (render, validate, batch) do not restrict file access. The person running them already controls the files.

Go callers that embed the renderer can use the same policy:

tmpl.Files = renderer.NewFileAccess("/srv/templates", "/srv/assets") // nil = unrestricted
eng, _ := renderer.NewEngine(renderer.Options{MaxPages: 5000, MaxTableRows: 200000, MaxRasterPixels: 64_000_000})

Browser-facing protections

Other limits

  1. Run behind a TLS-terminating reverse proxy. liuska serve speaks plain HTTP only. Set --allowed-host to your public hostname.
  2. Use --api-key-file with one key per client, and --read-only unless people really edit templates on that server.
  3. Keep templates and assets in a dedicated directory, not your home directory or repository root.
  4. Run as an unprivileged user with read-only access to the templates directory, plus write access only if you allow saving. In a container, use a read-only root filesystem.
  5. Put rate limiting in the proxy. --max-concurrent and --timeout protect the process itself, not the network.

For developers: adding endpoints

All routes are registered on the server's single http.ServeMux in generator/, and newServer wraps that mux in secure() (generator/security.go). A new route under /api/ therefore gets auth, read-only mode, body limits, the timeout, the concurrency limit and the headers automatically. Rules:

Known limits