Console and remote API
console_listen serves the web console and the management API on one address, over TLS. api_listen serves the API
alone, so a script on another host can call it with an API token. The socket in the runtime directory keeps serving as
before. Only a binary built with the console holds the web console.
Build with the web console says how to build one. Such a build holds the
console of the same checkout, from the console/ directory.
Turn on the web console
Section titled “Turn on the web console”The short path for a home network is a certificate that the server makes for itself. Name an address in node.toml.
An address without a port takes port 5343:
console_listen = ["192.168.1.2:5343"]tls_self_signed = trueThen follow these steps:
- Use a binary built with the console. A binary built without it refuses this revision.
- Save the revision. The server starts to serve the address with no restart.
- Open
https://192.168.1.2:5343/in a browser. It warns about the certificate, because the server signed it itself. - Compare the SHA-256 fingerprint that the browser shows with the one that
tadoru healthgives over the socket. Then accept the certificate. A fingerprint that changed with no new certificate is the sign of an attack. - On a new server, Setting Up the First Administrator says how to use the setup token. Then log in with the account.
A certificate that the server makes says when the server
makes a new certificate, and the browser warns again. To get a certificate that a browser trusts at once, name tls_certificate_file and
tls_private_key_file in place of tls_self_signed, or use acme_names. The web console gives
the rules of the door, the proxy and HTTP/3.
Turn on api_listen
Section titled “Turn on api_listen”Name each address in node.toml, with a certificate. An address without a port takes port 8453:
api_listen = ["192.168.1.2:8453"]tls_certificate_file = "/etc/letsencrypt/live/dns.example.net/fullchain.pem"tls_private_key_file = "/etc/letsencrypt/live/dns.example.net/privkey.pem"The door uses the certificate of DNS over TLS: the two files, or a certificate from ACME through acme_names.
Encrypted DNS says how to get one, and Configuration gives the rules of each
setting. Get a certificate for the host name that your scripts call, because a client checks that name. The door
answers every name with that one certificate. With acme_names, the door closes each connection after its first TLS
message until the first certificate arrives. dns_api_tls_handshake_failures_total counts those under no_certificate.
Give the door a host name that no other web service shares. A browser sends the session cookie to every HTTPS service
on that host name, whatever the port. Secure, HttpOnly and SameSite do not keep a cookie to one port.
These lists are refused:
- A list with no certificate source.
- A wildcard address, such as
0.0.0.0. A wildcard reaches every network of the machine, also one that you did not mean. - An address and port that another TCP listener of this server holds, such as one of
tls_listen. - With
acme_challenge = "tls-alpn-01", an address on port 443. The door answers no ACME challenge.
The revision that adds an address starts to serve it, with no restart. An address that a revision removes
stops taking connections at once. Its open connections then get 10 seconds at most to finish their requests, and then
they close. A new certificate reaches the next connection.
To move an address and port from api_listen to another list, use two revisions.
Make a token
Section titled “Make a token”A token acts as the account that made it. On the server machine, log in over the socket and ask for a token. It is shown
once, so keep it. The socket is /run/tadoru/api.sock under the systemd unit, and ./data/run/api.sock in a checkout
with the paths of Install and run:
S=/run/tadoru/api.sock # or ./data/run/api.sockBODY=$(curl -s -D headers.txt -X POST --unix-socket $S \ -H 'content-type: application/json' \ -d '{"user":"alice","password":"a long enough passphrase"}' \ http://localhost/api/session)JAR=$(grep -i '^set-cookie:' headers.txt | sed 's/^[Ss]et-[Cc]ookie: //' | cut -d';' -f1)CSRF=$(printf '%s' "$BODY" | python3 -c 'import json,sys; print(json.load(sys.stdin)["csrf"])')curl -s -X POST --unix-socket $S \ -H "cookie: $JAR" -H "x-csrf-token: $CSRF" \ -H 'content-type: application/json' -d '{"label":"a script"}' \ http://localhost/api/tokensThe token field of the answer is the token. The token has the role of the account. Give a script an account with the
lowest role that it needs, such as viewer for a script that only reads. Accounts has the roles and the
first administrator, and API Reference has every route.
Call it
Section titled “Call it”From the other host:
TOK=7a9282af6cc6.9c459c458bee553bf742646574ac3299e0d29315c25230cfbabc28950e8c0f3acurl -s -H "authorization: Bearer $TOK" https://dns.example.net:8453/api/servercurl -s https://dns.example.net:8453/api/healthcurl -s -H "authorization: Bearer $TOK" https://dns.example.net:8453/api/healthWith no credential, /api/health answers {"live":true} alone, so a monitor can ask whether the server is up. With a
token of any role, it answers the whole report. A revoked token gets 401, so a monitor with an old token fails loudly.
What the door refuses
Section titled “What the door refuses”A caller on api_listen gets none of the trust that the socket gives its owner. A program on the same machine that
connects to 127.0.0.1 gets no more than a program on another host. So every route that needs an account answers 401
with no token or session. Four routes need no credential: GET /api/health, GET /api/openapi.json, POST /api/setup
and POST /api/session.
| Limit | What happens past it |
|---|---|
| TLS 1.3 alone | A client with TLS 1.2 alone fails the handshake |
ALPN h2 or http/1.1, or none |
A client that offers only other protocols fails the handshake |
| 10 seconds for the handshake | The connection closes |
| 256 connections for one door | A new connection closes at once |
| 16 connections for one client | A new connection closes at once. A proxy of api_trust has no such cap |
| 30 seconds with no request | The connection closes |
| 16 KiB for the head of a request | The request never reaches a route |
| The body limit of the route | 413 body-too-large. API Reference gives the limit of a route |
| 10 seconds for the body to arrive | 408 body-too-slow |
| The bodies in flight, together | 503 busy, after a wait of 5 seconds |
| The failed attempts of one address | 429, with the seconds to wait |
A door is one address of api_listen or of console_listen. A client is the whole IPv4 address, or the first 64 bits
of an IPv6 address. Failed attempts gives the limits of failed logins and of bad tokens.
No answer carries an Access-Control- header, and OPTIONS answers 405. So a page of another site cannot read an
answer. No answer carries Strict-Transport-Security, so a plain HTTP service on another port of the same host name
keeps working.
Behind a reverse proxy
Section titled “Behind a reverse proxy”The proxy connects to api_listen over TLS. Put the address of the proxy in api_trust. The door then counts each
request under the client that the proxy names, rather than under the proxy:
api_trust = ["192.168.1.10"]api_client_header = "X-Forwarded-For"The door reads the last address of api_client_header, because the proxy adds the address that it saw at the end. A
proxy of api_trust that sends no such address gets 400 proxy-header, and the server log names the proxy and the
header. A header from a peer outside api_trust changes nothing. Without api_trust, every user has the address of the
proxy. Then one stranger behind it can use up the failed attempts of every user.
The door reads one proxy. Behind a chain of two proxies, every user counts under the address of the outer one. The door reads no PROXY protocol header.
A change of api_trust counts from the next request. A proxy that a revision removes from api_trust loses its open
connections at their next request. A deny entry that holds the proxy, such as "!192.168.1.10" beside
"192.168.1.0/24", takes it out of api_trust the same way.
A login over api_listen sets the session cookie with Secure. Logging in says what to set on
a TLS proxy in front of the socket.
Metrics and logs
Section titled “Metrics and logs”Four metrics count the connections, the failed handshakes, the refused attempts and the bodies that waited, with the
label door. The doors of the API lists them. A failed login writes an INFO
line with the client address and the name. No line carries a password, a token or a cookie.
The web console
Section titled “The web console”The web console is a set of web pages inside the binary. It runs in a browser, and it calls the API on the address that
served it. Build with the web console says how to build a binary with it.
Turn on the web console shows the steps. A certificate from files or from ACME works as it
does for api_listen:
console_listen = ["192.168.1.2:5343"]tls_certificate_file = "/etc/letsencrypt/live/dns.example.net/fullchain.pem"tls_private_key_file = "/etc/letsencrypt/live/dns.example.net/privkey.pem"Then open https://dns.example.net:5343/ in a browser, and log in with an account. Accounts says how to
make the first administrator.
console_listen follows the rules of api_listen. It uses the same certificate, and the server refuses the same lists
for it. It has the same limits, and a revision changes it with no restart. Under /api, it answers as api_listen
does. Every other path is a page or a file of the console. An address and port cannot be in both lists.
A binary built without the console refuses a revision that names an address in console_listen. It says that this
build holds no console, so build it with the console or use api_listen.
Give the console a host name that no other web service shares. A browser sends the session cookie to every HTTPS service on that host name, whatever the port. So a page of another service on the same name, such as a router page on port 443, gets the cookie of the console.
The console behind a reverse proxy
Section titled “The console behind a reverse proxy”The proxy connects to console_listen over TLS, and the browser connects to the proxy. Put the address of the proxy in
api_trust, as for api_listen. Each failed login then counts under the client that the proxy names, and not under
the proxy. Behind a reverse proxy says how the server reads api_client_header.
Each page of the console goes out with a Content-Security-Policy header. It lists the hash of each script that the
pages carry, so it can be longer than 4 KiB. On most machines nginx keeps the headers of an answer in one buffer of
4 KiB, and it refuses a longer header with 502. A location of the console for nginx:
location / { proxy_pass https://192.168.1.2:5343; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_buffer_size 16k; proxy_buffers 4 16k;}proxy_set_header X-Forwarded-Foradds the address of the client at the end of the header, which is the address that the server reads. Without it, nginx passes on unchanged a header that the caller sent. So a caller can choose the address that its failed logins count under. A call to/apithat comes with no such header gets 400proxy-header, while the pages still load.proxy_buffer_sizeholds the headers of an answer. Change it together withproxy_buffers. With a largerproxy_buffer_sizealone,nginx -trefuses the configuration on most machines, because the buffers that it derives no longer fit.
The proxy must pass every header of the answer as it is. A proxy that removes or changes Content-Security-Policy
lets a page run scripts that the console did not ship.
HTTP/3
Section titled “HTTP/3”console_http3 = true serves each address of console_listen over HTTP/3 too, on the UDP port of the same address and
port. api_listen takes no HTTP/3.
console_listen = ["192.168.1.2:5343"]console_http3 = trueOpen UDP port 5343 in the firewall as well as TCP port 5343. A browser learns of the door from the Alt-Svc header,
which How a browser finds HTTP/3 explains. A request over HTTP/3 meets the same rules as
over TCP. These are the certificate, the session, the forgery token, the failed attempts, the body limits, the policy of
the pages, and the rule of a proxy of api_trust. The address of a client is the address that its QUIC handshake proved.
- No 0-RTT. A client that resumes a session sends no request before the handshake ends. So a write never runs twice.
- A connection keeps the address of its handshake. A client whose address changes opens a new connection.
- The tickets of a resumed session open on the UDP doors alone. A new certificate ends them.
- The UDP port of a door is its own, whether
console_http3is on or off. No DNS listener can take it.
| Limit | What happens past it |
|---|---|
| 256 connections on all the UDP doors | A new attempt is refused. A closed connection counts until it is gone: three probe timeouts after its close, about 3 seconds where the client sends no reply, longer for a slow client |
| 16 connections of one client, on all | A new attempt is refused. A closed connection counts until it is gone, and so does a handshake that failed after the client proved its address with a Retry. A proxy of api_trust has no such cap |
| 64 handshakes at once | A client whose address nothing proved yet must prove it first, with a Retry. An attempt from such an address counts here until it takes its place among the 16 of its client, or until it is gone |
| 10 seconds for the handshake | The attempt ends |
| 100 requests at once on one connection | The client waits for one to end |
| 1024 requests at once on all the doors | The request is refused, and the client can send it again |
| 64 requests at once of one client, on all | The request is refused, and the client can send it again. A proxy of api_trust has no such cap |
| 30 seconds with no request | The connection closes |
| 16 KiB for the head of a request | The request never reaches a route |
A revision that turns console_http3 off, or that takes an address out of console_listen, stops the UDP door. The
requests that still run get up to 10 seconds in all to finish. Then each connection whose handshake ended closes with the
code of no error, and the door closes. Its port is free a little over 11 seconds after the stop. A revision that names
the same address again within that time can fail to bind it. Save it again a moment later.
Four metrics count the handshakes in progress, the connections that hold a place, the Retries and the refusals of the UDP doors. Logs and metrics lists them.
How a browser finds HTTP/3
Section titled “How a browser finds HTTP/3”An answer of a door of console_listen over TCP names its UDP door in a header, such as:
Alt-Svc: h3=":5343"; ma=86400The header names the UDP port of the same address, for one day. A browser can then send its next requests over HTTP/3, and it can fall back to TCP when HTTP/3 does not answer. The door sends the header only where all of these hold:
- The UDP door of that address serves. The header starts with the revision that starts the door. It stops with
the revision that turns
console_http3off or takes the address out ofconsole_listen. - The UDP door has a certificate. The certificate must be valid for the name in the address bar of the browser, as over TCP.
- No DNS listener holds the same UDP port on any address of the node, in either family: not
listen,quic_listenorhttp3_listen. A browser can try the port at each address of the name that it asked for. A DNS listener there can take the requests of the console. - The UDP doors take attempts. No door is named while they refuse every attempt, as The UDP doors refuse every attempt says.
- The client is not a proxy of
api_trust. - Nothing was published while the request ran: no revision and no update of a zone.
An answer over HTTP/3 does not carry the header, and neither does an answer of api_listen. The door never sends
Alt-Svc: clear, so a browser can keep the header for up to a day after the door stops. Its HTTP/3 connections end
when the door stops, but while it holds the header it can try the port again. It can find nothing there and fall back
to TCP. Or it can reach another service on that port, as
The console fails over HTTP/3 after a change of ports
says.
The server cannot see two setups that send a browser to the wrong place:
- The name of the console resolves to an address that does not serve the console on that port, such as an IPv6
address beside the IPv4 address of
console_listen. Make each address of the name serve the console on that port. Or let it serve nothing on its UDP port. - A router forwards another port to the door, such as TCP port 443 to 5343. The header names 5343, which the browser then tries on the router. Forward the same port number for TCP and UDP.
Behind a reverse proxy, put the proxy in api_trust: the door then sends no Alt-Svc, because the browser cannot reach
the port of the door. Set Alt-Svc at the proxy where the proxy serves HTTP/3 itself. A proxy that is not in
api_trust passes the header on to the browser, unless it removes it.