Repository navigation
TLS and ACME
form.md serves plain HTTP by default, on loopback only. For anything reachable from other machines, put HTTPS in front in one of these ways: give the server a certificate you manage, let it fetch and renew certificates itself over ACME (Let's Encrypt by default, set up from the environment or from Instance settings), run it behind a reverse proxy that terminates TLS, or use a Cloudflare tunnel (Tunnel). Sign-in cookies are marked Secure only when the server sees the request as HTTPS, so pick one before inviting people.
| Path | What lives there |
|---|---|
internal/config/config.go |
FORMMD_TLS_CERT, FORMMD_TLS_KEY, FORMMD_ACME_DOMAINS, FORMMD_ACME_EMAIL, FORMMD_ACME_DIRECTORY, FORMMD_HTTP_ADDR and their checks |
internal/app/app.go |
Run: serves TLS when a certificate or ACME is configured, starts the challenge listener, shuts both down |
internal/app/acme.go |
The ACME manager (golang.org/x/crypto/acme/autocert), its cache, and the HTTP challenge listener |
internal/server/server.go |
Build: turns on ACME from the https.auto and https.domain instance settings |
internal/httpx/request.go |
How the server works out the client address, scheme and origin, with or without a trusted proxy |
DATADIR/acme/ |
The certificate cache (account key and certificates) |
FORMMD_ADDR=0.0.0.0:443
FORMMD_TLS_CERT=/etc/form-md/tls/fullchain.pem
FORMMD_TLS_KEY=/etc/form-md/tls/privkey.pemBoth must be set together. The files are read at start, so restart the server after replacing them. form-md doctor loads the pair and warns when the certificate expires within 14 days.
FORMMD_ADDR=0.0.0.0:443
FORMMD_ACME_DOMAINS=notes.example.com
FORMMD_ACME_EMAIL=ops@example.comPut these in /etc/form-md/env and restart. The systemd unit grants CAP_NET_BIND_SERVICE, so the form-md user can bind ports 443 and 80.
What happens:
- The server listens for HTTPS on
FORMMD_ADDRand answers the CA's TLS-ALPN challenge there. - It opens a second, plain HTTP listener on
FORMMD_HTTP_ADDR(default:80) that answers HTTP-01 challenges and redirects every other request to HTTPS. The log showsacme http listener addr=... domains=.... - On the first HTTPS request for a listed name it gets a certificate, then renews it on its own. Only the names in
FORMMD_ACME_DOMAINS(comma-separated) are served; requests for other names get no certificate. - Certificates and the ACME account key are cached in
DATADIR/acme/, so a restart does not ask the CA again. With Encryption on, every cache entry is sealed with the data key; an entry that cannot be unsealed counts as missing and is fetched again.
| Variable | Default | Purpose |
|---|---|---|
FORMMD_ACME_DOMAINS |
unset | Names to get certificates for; turns ACME on |
FORMMD_ACME_EMAIL |
unset | Contact address given to the CA |
FORMMD_ACME_DIRECTORY |
https://acme-v02.api.letsencrypt.org/directory |
The CA's directory URL; set a staging or private CA's URL to test |
FORMMD_HTTP_ADDR |
:80 |
The challenge and redirect listener |
Check it:
journalctl -u form-md -n 20
curl -fsS https://notes.example.com/healthz
form-md doctor # reports: ok tls ACME for notes.example.com via <directory>Without touching the environment, an admin can turn on the same ACME setup in Instance settings, General:
| Field | Setting |
|---|---|
| Domain for automatic HTTPS |
https.domain, the host name people reach the server at, for example notes.example.com
|
| Automatic HTTPS |
https.auto, off by default |
It takes effect at the next start (sudo systemctl restart form-md). At start, when neither FORMMD_TLS_CERT nor FORMMD_ACME_DOMAINS is set, https.auto is on and a domain is saved, the server:
- uses that one domain as if it were
FORMMD_ACME_DOMAINS, - moves the listener to
:443ifFORMMD_ADDRis the default127.0.0.1:8750(the installer writes exactly that value, so an installed server moves too); any otherFORMMD_ADDRis kept as given, - logs
automatic HTTPS from Instance settings domain=... addr=....
form-md doctor reports this as ok tls automatic HTTPS for <domain> from Instance settings (turn off with: form-md admin set https.auto false).
Everything else is as described under Built-in ACME: the challenge listener on FORMMD_HTTP_ADDR, the redirect, and the cache in DATADIR/acme/. Settings in the environment always win: with FORMMD_TLS_CERT or FORMMD_ACME_DOMAINS set, https.auto is ignored.
Before restarting, point the domain's DNS at the server and make sure ports 443 and 80 are reachable. If the server does not come back, journalctl -u form-md -n 50 names the stage that failed (for example a port already in use). To turn automatic HTTPS off without a working server, write the setting directly and start again (on a systemd install use the fm function from Operations):
sudo systemctl stop form-md
fm admin set https.auto false
sudo systemctl start form-mdLeave the server on loopback (FORMMD_ADDR=127.0.0.1:8750, the default) and let the proxy terminate TLS. The proxy must:
- forward the WebSocket at
/sync(the realtime document socket) with its upgrade headers, - forward the event stream at
/api/eventswithout buffering, - send
X-Forwarded-Proto: https, - send
X-Forwarded-Hostwith the public host name (without it the server uses theHostheader the proxy passes on, which must then be the public name), - send
X-Forwarded-For(orX-Real-Ip) so rate limits and the audit log see real client addresses.
The server only reads those headers when the instance setting net.trust_proxy is on. Turn it on in one of two ways:
-
Before the first set-up: add
FORMMD_TRUST_PROXY=trueto/etc/form-md/envand restart. The variable is the setting's default, so it applies from the first request, including the set-up screen.echo 'FORMMD_TRUST_PROXY=true' | sudo tee -a /etc/form-md/env sudo systemctl restart form-md
-
Or from the command line:
fm admin set net.trust_proxy true(see Operations), then restart the server. This saves the setting itself, so it works before anyone has signed in. -
Later: Instance settings, General, Behind a reverse proxy. A value saved there wins over the variable.
Also set Public address (Instance settings, General) to the https:// address people use; it is used for links in mail, invitations and sign-in callbacks.
Why it matters: browser requests that change something (including sign-in and the first set-up) are refused as cross-site request refused unless their Origin matches the request origin as the server sees it, or the Public address. The /sync socket only accepts an Origin equal to the request origin as the server sees it. With net.trust_proxy off, the server sees http:// behind a TLS proxy, refuses those requests and the socket, and does not mark session cookies Secure.
form-md doctor reports warn tls off: serve behind a TLS proxy or set FORMMD_ACME_DOMAINS in this setup; that is expected.
-
FORMMD_ACME_DOMAINSandFORMMD_TLS_CERTare mutually exclusive, and the certificate and key are set together;config.Loadenforces both. Keep new TLS options inside the same checks. - Anything written into
DATADIR/acme/goes through the cache inacme.go, which seals it when encryption is on.acme/is in the backup and inform-md encrypt. - Code that needs the client address, scheme or origin calls
httpx.ClientIP,httpx.RequestSchemeorhttpx.RequestOriginwith thenet.trust_proxysetting, never the raw headers. - Only enable
net.trust_proxywhen the server can be reached through the proxy alone; otherwise anyone can forge the forwarded headers.
- With ACME,
FORMMD_ADDRmust be on port 443: TLS-ALPN challenges and the redirect from port 80 both assume it. - Port 80 must be free for the challenge listener; if it cannot bind, the server does not start.
form.md
Running an instance
Using it
- Data-views
- Offline
- API-and-agents
- Form-family
- Context-and-knowledge
- Terminal-and-Claude-Code
- Extensions
Changing the code