Skip to content

Accounts

An account is what the management API authenticates. There are three roles, an account is not configuration, and there is no account file: the whole of one lives in auth.sqlite inside the state root. The name, the role, the password verifier, the API tokens and the sessions have one lifecycle, so they live in one place.

Role Can do
admin Anything, including the accounts and setting somebody else’s password
operator Changes settings, rolls back, changes zones and their records, reads the configuration, the query log, the statistics and the recent lines of the log, clears the query log, flushes the cache, and asks any DNS server through the DNS client
viewer Reads the configuration, the zones and their records, the query log, the statistics and the cache

There will not be a fourth.

Some routes need no account on the machine itself. That is for a caller on the management socket whose user is the one the server runs as, or root. The server takes the operating system’s word for who connected and treats that caller as an operator. That holds for the configuration and revision routes, the blocking routes, the two cache routes, GET /api/cache and POST /api/cache/flush, and the zone routes: the list, a zone, its records and its export, making, changing and deleting a zone, its import, its freeze, its thaw, its checkpoint, and a change of its records. It holds for the three routes of the secrets of the node too, below. Every other route wants a token or a session. Only an administrator reads the account list, so a viewer does not learn who exists. An operator sees the names of accounts in the recent lines of the log, such as the line of a failed login or of a change, so an operator can learn who exists there.

The secrets of the node, such as the password of a PKCS #12 file, have three routes. GET /api/node/secrets says which secrets are set and readable, and needs an operator or an admin. PUT and DELETE /api/node/secrets/{name} write and clear one, and need an admin. On the management socket, root and the user of the server use all three with no account, because they can write the files of the secrets on the disk already. This is one of two places where the socket does what an admin does, beside the grants of a list below, and it gives no other power of an admin. A caller on the socket that sends a token or a session is judged by that credential instead, so an operator’s token there cannot change a secret. tadoru secret uses the socket this way. No route returns a value. The log names the account of each change, or uid:N for a caller on the socket, never the value.

There are two secrets: tls_pkcs12_password, the password of a PKCS #12 file, and outbound_proxy_password, the password of the user of the outbound proxy. A write of the password of the proxy is not tried on the network. The route checks only that the kind of the proxy of the configuration that runs can carry it: SOCKS5 carries 1 to 255 bytes, and HTTP Basic carries no control character. A value that the kind cannot carry is refused with secret-refused, and the value of before stays. Where a user of the proxy is set, a write, and a clear of a value that is set, answer reload: next_request: the next request through the proxy takes the new password. Where no user is set, they answer reload: none, and a request that sends a user later reads the password of its own moment. With no proxy set, the route checks only the rule of every secret. The answer reads the configuration of the moment of the write, so a change of the proxy at the same moment gives the answer of the configuration that the next request meets.

Three changes let the fetch of a list reach the network of the house, and only an admin makes them: private = true on a source, a url outside the catalog of known lists that the outbound proxy carries, and fetches of a url source through a proxy that no list fetch of the running revision went through: another outbound_proxy, a new one, or one that sat unused while the lists went direct (Configuration). An operator’s change that gives one, a rollback to a revision that held one, and a change of node.toml that sends such a source through the proxy are refused with needs-admin. What the running revision holds already stays, so an operator can keep such a source and change its other keys. The server’s own uid or root on the socket, with no credential, gives them too, because it can write the file already: that is the second place where the socket does what an admin does. A token or a session on the socket is judged by its role.

Why a list could not be read names addresses and ports. An admin, and the socket with no credential, read that text in GET /api/blocking/sources, in the answer of a refresh and in GET /api/health. An operator and a viewer read a short phrase of its kind instead, which names no address, and so does the log. That hides the addresses and the reasons of a failure from a lower role, and no more. The time a refresh takes still tells a refused connection from a silent one, a global address of the house that no prefix of rebind_inside names is public to the rule (Blocking), and the forwarders that go through the outbound proxy are outside this rule. The DNS client below can still probe the network, 60 targets a minute.

The DNS client, POST /api/dns-client, needs an operator or an admin, with a token or a session on the socket too. It makes this server send a question to a server that the caller names, so a viewer cannot ask, and the limits of The DNS client hold for every caller.

The recent lines of the log, GET /api/logs, need an operator or an admin, with a token or a session on the socket too. The lines hold the names of accounts, the addresses of clients and the paths of files. With store_names off, a line at info or warn names no query. At debug and trace the log names queries whatever store_names says, and the route shows what the log wrote. Observability says more.

A start with no account writes a one-time setup token, because nobody can use the API yet. The token lasts a day, it works once, and presenting it spends it.

Terminal window
S=./data/run/api.sock
TOKEN=$(cat ./data/state/setup-token)
curl -s -X POST --unix-socket $S \
-H 'content-type: application/json' \
-d "{\"token\":\"$TOKEN\",\"user\":\"alice\",\"password\":\"a long enough passphrase\"}" \
http://localhost/api/setup

That makes the account and spends the token in one transaction, and then the token file is deleted. It is not a configuration change, so it produces no revision.

A page learns whether setup is still needed from GET /api/setup, which needs no account:

Terminal window
curl -s --unix-socket $S http://localhost/api/setup

{"needed": true, "token_usable": true} means that nobody can administer the server yet, and that the token in the state root works. "token_usable": false means that the next start writes a new token, for one of these reasons:

  • The file setup-token is missing.
  • The file does not read as a token.
  • The file no longer matches the token that the server recorded.
  • The token is more than a day old.
  • On Linux and macOS, the file can be read by more than its owner, because its mode is wider than 0600.

Restart the server, and the start writes a new token. Until that start, a token that you copied before can still create the first administrator. Once an administrator can log in, the answer is {"needed": false}. The answer never carries the token.

The server prints the token to a terminal only. A secret printed to a log lives in journalctl and in docker logs for as long as those are kept. So the token goes to a file at mode 0600 instead.

A program sends Authorization: Bearer <id>.<secret>. A browser logs in and gets a cookie plus a forgery token. API Reference has the whole sequence as commands you can run, and every route that takes them.

A change made with a cookie must echo the session’s forgery token in the x-csrf-token header. A browser sends a cookie whether or not the page meant to. So a cookie on its own lets another site make a request in your name. A change without the header answers 403. A bearer token needs no forgery token, because a browser does not send one by itself.

A page reads its session back with GET /api/session and the cookie alone. The answer is the one the login gave: the account, the role, the forgery token, and expires_at, the time the session ends in seconds since the Unix epoch. So a reload of a page, or a new tab, keeps the session. The read does not make the session last longer: a session still ends eight hours after the login, and a logout or a new password ends it at once. With no session the answer is 401, and a bearer token gets 400. Because the cookie alone gets the forgery token back, somebody who steals the cookie can make changes until the session ends.

The login answer and the read of the session send Cache-Control: no-store and Vary: Cookie. A proxy that keeps a copy of an answer despite no-store keeps one per cookie, and so stores forgery tokens. Do not put such a proxy in front of the server.

The cookie of a session carries no Secure flag on the socket, so a bridge of plain HTTP on the same machine still works in every browser. If you put a TLS proxy in front of api.sock, make the proxy add Secure to the cookie, or the browser sends it to any plain HTTP port of the same host name. With nginx 1.19.3 or later, that is proxy_cookie_flags tadoru_session secure;. With Caddy, it is header_down Set-Cookie "^(tadoru_session=.*)$" "$1; Secure" inside the reverse_proxy block. A proxy in front of api_listen or console_listen needs neither, because a TCP door sets Secure itself.

A session stays on the server that issued it. A restore ends the sessions the archive carried, and a failover in a later release asks for the password again.

The server counts failed attempts in a window of one minute. A wrong password, a wrong setup token and a wrong current password count as logins. A bad API token and a bad session count as credentials. The two have separate budgets, so bad tokens never use up the budget of a login.

What is counted Limit a minute
Failed logins of one name from one address 10
Every failed login from one address 30
Every failed login from one IPv6 /48 120
Failed tries of one token or one session 10
Every failed token or session from one address 30
Every failed token or session from one IPv6 /48 120

An address is the whole IPv4 address, or the first 64 bits of an IPv6 address. The rows of an address apply to api_listen. Behind a proxy of api_trust, the address is the client that the proxy names. On the socket, the server counts the first row and the fourth: a login counts under the uid of the caller and the name, and a setup token or a change of your own password under its token or its account. Past a limit, the answer is 429 and says how many seconds to wait. A try that answers 503 accounts-busy, because the accounts did not answer in time, counts no failure. A good password or token clears the count of its name or token. The count of the address stays until its minute ends. So a stranger who guesses at your name from another address does not lock you out.

Each failed login writes the line a login failed at INFO, with the door, the client and the uid. The line names a name only where an account has that name, as the stored name of that account. Where no account has the name, the line says an unknown name. It never holds a password, or a name that no account has, because operators read the recent lines of the log, and such a name can be a password that went into the wrong field.

The server also counts the failed logins of each account over every address and door together, in a sliding hour. A wrong current password on a change of your own password counts there too. When one account reaches 50 in an hour, the server writes one line at WARN, the failed logins at one account reached the threshold of an hour, from every address together, with the name of the account, and adds one to dns_api_accounts_guessed_total. It writes no other such line for that account in the hour after. A good login does not clear the count, so the owner who logs in while others guess does not hide the guessing. Every name with no account counts as one, and its line says an unknown name. Even so, somebody who can read the metrics and makes failed logins of their own can learn from the counter whether a name has an account. That is one more reason to keep metrics_listen on an address that only you can reach. This count makes nobody wait and refuses nothing. The limits above still decide each answer.

A name is lower case letters, digits, and - _ . at most 64 characters. Anything else is refused, so that one person cannot become two accounts. A display name is up to 128 characters with no control characters, and it is what a person sees instead of the login name.

A password is at least twelve characters, and there are no rules about which characters. Length is what makes a password hard to guess, and a rule about punctuation mostly makes people write it down. Passwords are stored as argon2id verifiers, never as text.

An account can exist with no password, which is what an administrator adding somebody leaves behind. That person cannot set the first one themselves, because nothing can authenticate as an account with no password. An administrator sets it. After that, a change of your own password takes the password being replaced, so a borrowed session cannot lock its owner out.

A token acts as the account that made it, with that account’s role. It is shown once, at the moment it is made, and stored as a hash. A token that is lost is revoked and replaced rather than recovered.

Every role can make a token for itself and revoke its own. An administrator sees and revokes anybody’s. A token does not expire.

While the server runs, use the API. POST /api/accounts makes one. PATCH changes a role, a display name or the name. DELETE removes the account with its tokens and its sessions. PUT /api/accounts/{account}/password sets a password, and GET /api/accounts/history says what was done to the accounts and by whom.

GET /api/accounts/history answers one page at a time, newest first, in the order of the writes. Each row has a seq, a number that grows with each change. While the server runs it never moves and is never used twice, and it belongs to this server alone: each node has its own. limit is how many rows a page holds, from 1 to 1000, and 200 by default. To read an older page, send the smallest seq of the page you hold as before: ?before=38&limit=200 lists the changes with a seq under 38. An empty array is the end of the history. A change made while you read has a larger seq and does not move an older page. A restore puts the history of the backup back, and later changes take the numbers after it, so start again at the first page after a restore.

The routes take the account’s identifier rather than its name, because a name moves and an identifier never does. GET /api/accounts answers with both, so a person works by name and a program works by identifier.

Or use tadoru accounts, which works whether or not the server is running. It refuses while a restore of the state root runs, and after a restore that stopped half-way, because a restore can replace the accounts with those of its archive. It then reads and changes no account. The command line has every subcommand and flag.

A removed account, a new password, a logout, a session that ran out and a revoked token remove rows from auth.sqlite. The verifier of a password lets somebody guess the password offline, so the server zeroes each copy of a removed row that it can reach. Three things hold, at three moments:

  • When the change answers, the row is gone, and nothing reads it again.
  • At the same moment, the space of the row and every page that the change freed hold zeros. A backup after the change copies those zeros.
  • Then the server folds the change into the file and empties auth.sqlite-wal, so no older copy of the page stays in the two files.

A program that reads the file at that moment, such as a tadoru accounts command beside the server, can hold the last step. The change still answers. The server retries at its start and every minute. Until a retry ends it, dns_auth_log_cut_pending reads 1. When its own change waits for the step, tadoru accounts says so on standard error, and tadoru restore in its report, each with the reason. While a reader holds the file, the log grows only by the writes of the accounts, such as a login. At the next reset of the log after it, SQLite keeps at most 1 MiB of the log on the disk.

The last step pauses the writes of the accounts. It copies the log into the file and syncs both, as SQLite does on its own every 1000 pages. A request that reads an account waits for it, on a thread of its own, so it holds none of the workers that answer DNS. DNS answers that need only a worker go on, and work that needs a thread of its own, such as a DNSSEC validation, can wait where every such thread is busy. At most 16 reads run or wait for a thread at once, and the rest wait for one of those places. The reads of one request wait 3 seconds in all. Past that, the request answers 503 accounts-busy and changes nothing. The copy is what the log held since the last step, which is small unless a reader held the file for long.

Some copies stay, by design or because only a rewrite of the file clears them:

  • The unused space inside a page that stays in use can keep a copy of a removed row. A rewrite of the file with the server stopped clears it: tadoru rewrite --only auth, as The command line says.
  • A file that an older build wrote keeps what its deletions left in its free pages.
  • An archive keeps what auth.sqlite held at the end of the backup’s copy of it, as Backup and restore says.
  • The history of the accounts keeps each account name, the name of each actor, each display name that a change recorded, and the identifier of each token. A removal does not erase them, so GET /api/accounts/history can still say who removed whom.
  • The blocks of the disk can keep old bytes after the file changes. That is outside the server.

The last administrator who can log in is not demoted, not removed, and not left without a usable password. There is no file to repair that from.

If you are locked out anyway, there are two ways back. Use tadoru accounts password <name> --password-file ./passphrase, which needs no current password, no credential, and no stopped server. Or, for a server nobody can administer at all, let a start write a setup token and redeem it.

Give that redemption the name you cannot log in as. It mends that account rather than refusing the name: the same account, the same history, and a new password. Give it another name instead, and you get a second administrator beside the one you cannot use.

A state root from an earlier build does not open, and that is the other way to lose the accounts. This project has no release, so such a root is a development one: auth.sqlite records a schema version this build refuses, and deleting that file is the way on. A start with no account then writes a setup token.