Put a proxy in front of Kraft
Before you start
For the board:
- A password. Set a password says how.
- The name your browser types, such as
kraft.example.com. It goes inallowed_hosts. - A firewall you control, to close Kraft's own port to every address but the proxy's.
- A second device to check from.
For webhooks and scripts:
- Kraft is bound to
127.0.0.1, which is the default. - A tunnel or reverse proxy on this machine: cloudflared, ngrok, Caddy or nginx.
- A second device to check from. A request from this machine names a loopback client, and Kraft asks it for no password.
Choose the fix
A tunnel or reverse proxy on this machine that passes on the name its clients
used gets a 403 for every request: unexpected Host for a server bound to 127.0.0.1. Scripts and webhooks get it too, and allowed_hosts isn't read.
Who may call has the rule. Coming from 1.4,
see Network access.
Choose the fix by what has to reach Kraft:
- The board: serve it with a password and the name in
allowed_hosts, as Serve the board behind a reverse proxy below says. For a way in with no proxy of your own, see Remote access. A loopback-bound Kraft behind a proxy serves webhooks and scripts only, never the board, because Kraft refuses the browser's sign-in and changes as cross-site. - Webhooks and scripts only: have the proxy send
Host: localhost, as SendHost: localhostfrom the proxy says.
Serve the board behind a reverse proxy
Caddy, nginx or another proxy you run can serve the board at a name of your own
while Kraft listens on a network bind behind it. Kraft listens on plain HTTP, so
the proxy serves HTTPS. Off loopback, Kraft asks every client for the password or
a token before any API call, a proxy on this machine included. /api/health, the
page and its assets are open. Kraft also checks the Host and Origin the proxy
passes on.
- Set a password with the commands in Set a password.
- In
access.yaml, setbindoff loopback and add the name your browser types toallowed_hosts:config/access.yamlbind: 0.0.0.0 allowed_hosts: - kraft.example.com
Bind0.0.0.0, not127.0.0.1, even when the proxy runs on this machine. On a loopback bind Kraft ignoresallowed_hostsand answers only a loopbackHost. Every request is refused unless the proxy sendsHost: localhost, and then the board's sign-in and every change are refused as cross-site. That is why the webhook way serves webhooks and scripts only.
Until the restart, change nothing on the Access screen: a change there rewritesaccess.yamlfrom what the running server holds and undoes this edit. - Block port 8765 at your firewall for every address but the proxy's, before you restart. The wider bind listens on every network this machine is on, and a request that reaches the port directly meets only the password or a token, over plain HTTP.
- Set the proxy to pass what What the proxy must pass lists, with the setting your proxy uses for each.
- Restart Kraft so it binds the new address.
- Check it as Check it worked says, at the proxy's own name, including the two requests for this way.
Send Host: localhost from the proxy
- sender: another deviceHost: the name it used
- proxy on this machinesends Host: localhost and X-Forwarded-For: the sender
- Kraft finds the clientthe last X-Forwarded-For that isn't loopback
- remote, no password: 403 refusedno password set
- otherwise: Kraft checks the Host
- not localhost: 403unexpected Host
- localhost: is the client this machine?
- yes: header missing, or loopback passed through: no sign-in askedthe API is open
- no: a credentialsession, mcp-token bearer, or trigger token on POST /api/triggers
- valid: API answers
- none valid: 401no valid credential
- no: a credentialsession, mcp-token bearer, or trigger token on POST /api/triggers
- localhost: is the client this machine?
- otherwise: Kraft checks the Host
Before you rewrite Host, know what it does to sign-in. A loopback-bound Kraft
asks a request from this machine for no password, and a request through a proxy
on this machine is one, unless the proxy names its client in X-Forwarded-For.
So:
- First set a password, as in Set a password.
- Make sure the proxy sets that header itself: nginx doesn't unless you add
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;, which appends the client's address. Appending or replacing is right. Never let the proxy pass a caller's ownX-Forwarded-Forthrough as it came: a caller who sendsX-Forwarded-For: 127.0.0.1would then be taken for a client on this machine, and Kraft would ask it for no login. - Make the proxy send
Host: localhost, with the setting for yours.
| Proxy | Setting |
|---|---|
| cloudflared | httpHostHeader: localhost in the ingress rule's originRequest, or --http-host-header localhost on the command line |
| ngrok | --host-header=rewrite |
| Caddy | header_up Host localhost in the reverse_proxy block |
| nginx | proxy_set_header Host localhost; |
Kraft then asks every API call through the proxy for a session, for the
mcp-token as a bearer, or, on POST /api/triggers, for the
trigger token.
/api/health, the page shell and its assets need none. While no password is set
it refuses every request. Without X-Forwarded-For, everyone who reaches the
proxy has the whole API, with no sign-in, password or not.
A proxy that is itself fed from loopback, such as an ssh -R endpoint or a second proxy on
this machine, passes every request on as local, and Kraft asks it for no
password even with one set. Put nothing like that in front of a loopback-bound
Kraft.
Check it worked
Make the requests from another device, not from this machine: a request from this machine names a loopback client, and Kraft asks it for no password.
The board
- Request the health endpoint, which needs no login. Replace the address with the
proxy's name:
curl -s https://kraft.example.com/api/health
A JSON status confirms the request reaches Kraft. - Open the same address without
/api/healthin a browser. You should see the login page. Sign in with your password. - On a computer, the sidebar reads live next to Kraft once the board's event connection is open, and the board updates without a reload.
- Request an API route with no credentials. Put your proxy's name in
name:name=kraft.example.com curl -s -o /dev/null -w '%{http_code}\n' "https://$name/api/work-items"
It must print401. A401alone isn't proof of this setup: signing in at step 2 is. - From a machine other than the proxy's, request the health endpoint at Kraft's
own port. Set
machineto this machine's address before you run it:machine=192.168.1.20 curl -m 5 "http://$machine:8765/api/health"
With the port blocked, this must fail: it times out, or is refused.
Webhooks and scripts
/api/healthanswers with a JSON status./api/work-items, with no credentials, answers401. Then send it again withX-Forwarded-For: 127.0.0.1added: it must still answer401.
If it fails
Find what you saw, then do what it says.
A 403 that says unexpected Host
For webhooks, the proxy still sends the name its client used. Make it send
Host: localhost, as
Send Host: localhost from the proxy says. For the board, the same 403 means
Kraft still binds 127.0.0.1: restart it so it reads bind: 0.0.0.0.
A 403 with no password set
Kraft refuses every request through the proxy until a password is set. Set one
as step 1 of the way you follow says. For the board, a 403 also means Kraft
still binds 127.0.0.1, so restart it.
A 200 where 401 is expected
For the board, Kraft took the request for a local one. It still binds
127.0.0.1, behind a proxy that sends Host: localhost. That is the webhook
setup, not this one.
For webhooks, the proxy isn't sending X-Forwarded-For, so Kraft takes every
request for a local one and everyone who reaches the proxy has the whole API.
Fix that before you go on. Then send the request again with
X-Forwarded-For: 127.0.0.1 added: it must still answer 401, and a 200 means
the proxy passes a caller's own header through.
cross-site request refused or reconnecting…
The proxy rewrote Host to localhost or 127.0.0.1, changed Origin or
doesn't pass the WebSocket. If the sidebar stays on reconnecting…, check that
anything between the browser and Kraft passes WebSocket connections through and
keeps the Host header the browser sent. The rows of
What the proxy must pass say what each header does.
A 502 or another answer
The answer comes from the proxy itself, such as a 502 when it can't reach
Kraft.
The health request at Kraft's own port answers
A JSON status means the port is still open to the sign-in over plain HTTP: block it at your firewall before you go on.
What the proxy must pass
For the board, set the proxy to pass what the table lists, with the setting your proxy uses for each. The first four rows are what the board needs. The last one keeps the sign-in lockout per client.
| The proxy must | What Kraft does with it | Without it |
|---|---|---|
Pass Host as the browser sent it, port included. Don't set it to localhost or to Kraft's own address. | Checks the name against allowed_hosts for a browser request, and compares the Host with the Origin of every write and of the live-update socket. | An unlisted name gets a 403 (the page names it). A Host rewritten to localhost or 127.0.0.1 (nginx's default) loads the page, but Kraft refuses the sign-in, every change and the socket as cross-site request refused. |
Pass Origin through unchanged. | Refuses a write (any request but GET or HEAD) or a socket whose Origin names another host and port than Host, unless it names this machine. | An Origin the proxy changes gets the 403, cross-site request refused. One it drops turns the cross-site check off for writes. |
Pass the WebSocket upgrade for /api/ws/events. | Applies the same checks and the sign-in to the socket, and closes it when one fails. | No live updates: the sidebar shows reconnecting… instead of live. |
Send X-Forwarded-Proto: https when it serves HTTPS. | Marks the session cookie Secure when the request is HTTPS or this header says https. | The cookie isn't marked Secure. |
Append the client's address to X-Forwarded-For. Don't pass a caller's own header through as sent. | Takes the client from the last address in the header that isn't 127.0.0.1 or ::1, and counts failed logins per client. | Every visitor counts as one address: 5 failed logins from anyone lock everyone out for 15 minutes. A header passed through as sent lets a caller pick its own address, so it is never locked out. |
For the loopback-bound Kraft of the webhook way, leave FORWARDED_ALLOW_IPS
unset. On a proxy on another machine, set FORWARDED_ALLOW_IPS in the server's
environment to that proxy's address only, never *. Kraft reads
X-Forwarded-For only from a peer at 127.0.0.1 or ::1 (uvicorn's default
list), and a proxy on another machine connects from its own address, so without
the setting Kraft takes every client for that proxy and the lockout is shared.
The hop from a proxy on another machine to Kraft is plain HTTP, so the password crosses that network in the clear.
A proxy that is itself fed from loopback passes every request on as local: see
the warning under
Send Host: localhost from the proxy.
Next steps
- Remote access: reach the board over Tailscale, your local network or a tunnel
- Who may call: the rule behind the 403
- Inbound triggers: call
POST /api/triggersfrom off-machine with the trigger token - Security: the threat model behind the password and the host check