Clients
Give a client a name in clients.toml, save the file, and the query log says that name beside
the address. Nothing is named until you do, and every query is the client default.
The console calls a client a device: a device of the console is an entry of clients.toml. The
Glossary defines the other words of this manual.
[[client]]name = "kids-tablet"addresses = ["192.168.1.42"]The watcher notices the save, and a query a moment later carries the name. There is no restart.
clients.toml: who is asking has every key this file
takes, with its range.
A name also decides what this server blocks for that machine. The entry joins a group, and a group is a blocking policy. Groups has two machines on two policies.
The three ways to recognize a client
Section titled “The three ways to recognize a client”A source address, a subnet, or the address of this server the query arrived on.
[[client]]name = "kids-tablet"addresses = ["192.168.1.42"]
[[client]]name = "guest-network"subnets = ["192.168.20.0/24", "2001:db8:20::/64"]
[[client]]name = "iot"arrived_on = ["10.0.5.53"]One client takes entries of all three kinds, up to 64 of them. addresses is one machine each.
subnets is a range, and every machine inside it reads as that client unless another entry
claims it. Write a range as an address, a /, and the bits that decide it. A range starts at its
own first address, so 192.168.1.42/24 is refused rather than read as 192.168.1.0/24. A bare
address under subnets is a range of one. arrived_on names a query by the address of this server
that took it.
The name is yours to choose. Lower case letters, digits and hyphens, 40 bytes at most. One file names 256 clients at most.
Which entry wins
Section titled “Which entry wins”A query can match more than one client, and the order is fixed. Where the entries sit in the file changes nothing.
- An
addressesentry that is the address that asked. - The narrowest
subnetsentry that holds that address. - An
arrived_onentry that is the address of this server the query arrived on. - Otherwise
default.
So 192.168.20.32/27 wins over 192.168.20.0/24, and either one wins over every arrived_on
entry. Give one machine inside the guest network its own addresses entry, and that machine
stops reading as guest-network.
A proxy in http_trust names the client behind it, and the server reads that claim first. A load
balancer in proxy_protocol_from names the client in a PROXY header, and the server reads that
claim the same way. Behind both, the claim of the proxy counts, because the proxy sits closer to
the client. The address a claim names goes through steps 1 and 2. Where neither step holds that
address, the address of the peer goes through steps 1 and 2, and then steps 3 and 4 follow. The
peer is the machine that opened the connection to this server: the proxy, or the load balancer
where one is in front. So a client that the file does not name reads as the client of that peer.
Behind a load balancer and a proxy, that is the load balancer and not the proxy. A client
subnet option from a sender in ecs_trust comes before all of these.
The address a query arrived on stays the address of this server, behind a load balancer too. So an
arrived_on entry still names the listener that the load balancer reached.
default is the client of every query the file does not name, and no entry declares it. A
server with no clients.toml names every query default, and so does a file with no
[[client]] in it.
Groups
Section titled “Groups”A group is a blocking policy with a name, and every client is in one group. The group says which blocklists apply, which names you allow or block for those machines alone, and what a blocked answer looks like for them.
[[client]]name = "kids-tablet"addresses = ["192.168.1.42"]group = "kids"
[[client]]name = "work-laptop"addresses = ["192.168.1.50"]group = "trusted"
[[group]]name = "kids"sources = ["hagezi-pro"]block = ["socialmedia.example"]mode = "nxdomain"
[[group]]name = "trusted"sources = "all"blocking = falseThose two groups behave differently on one server in the same second. The tablet gets NXDOMAIN for a name the strict list holds. The laptop gets the real answer for that same name, because nothing is tested for it at all.
A client names its group and a group never names its clients. You add a machine in one place, and the policy you wrote once stays where you wrote it.
A client with no group key is in the group default. Every server has that group, and it uses
every enabled source with the blocked answer blocking.toml gives. Write a [[group]] named
default to change it, and the whole house moves without one edit to one client entry.
A group can also write cname_blocking = false and keep every list it names. Then the names inside
an answer are not tested for those machines, and the name asked for still is.
clients.toml: who is asking has the key.
Which lists a group uses
Section titled “Which lists a group uses”sources says which, and every group needs the key.
sources = "all" # every enabled source, and the ones you add latersources = ["hagezi-pro"] # this one onlysources = [] # no listsall is a value rather than the absence of the key. A group on all follows a source you add
tomorrow, and a group that names ids keeps the set you tuned. The key is required even where
blocking = false, so turning that group back on takes one line.
A group carries its own block and allow names too, up to 1000 of each, and each name covers
the names under it. mode, block_v4 and block_v6 say what this group answers for a blocked
name. A group that writes none of those three takes the answer blocking.toml gives.
clients.toml: who is asking has every group key with its bounds.
blocking = false and sources = [] are two different switches. blocking = false tests
nothing: no list, no entry at the top of blocking.toml, and none of the group’s own names.
sources = [] drops the lists and keeps every name an operator typed, the group’s own and the
ones in blocking.toml.
What a query is tested against
Section titled “What a query is tested against”Six steps, in this order. The first step that answers ends the test.
- The disable switch. Blocking turned off answers the query normally.
- The
bypasslist ofblocking.toml, by the address that asked. - The client’s group. A group with
blocking = falseanswers normally. - The two names this server answers about itself, which
canaryandprivate_relayturn on and off. Blocking has both. - Allow, narrowest first. These are the group’s own
allownames, then the[[allow]]entries at the top ofblocking.toml, then the allow rules inside the group’s sources that carryexceptions = "global", then the[[regex]]rules withaction = "allow". - Block. These are the group’s own
blocknames, then the[[block]]entries at the top ofblocking.toml, then the group’s sources in the order the group names them, then the[[regex]]rules that block.
So a group’s allow name beats a block entry in blocking.toml. That entry applies where
nothing more specific does, and the group name is more specific: this name, for these machines. The
order inside step 6 changes no answer, because a block is a block. It decides which rule the log
row names, and your own entry comes before a list. A pattern rule is last in that order, so a row
names a pattern only where no name blocked first.
A blocked row names the group whose policy applied, and default where no [[group]] claimed
the client. The query log has that column and the three beside it.
Renaming a source
Section titled “Renaming a source”Two files name one source, so a rename takes three steps in this order.
- Add the new id in
blocking.toml. - Switch the groups in
clients.tomlto the new id. - Delete the old id from
blocking.toml.
The watcher makes one revision per file it sees change. Delete the old id first, and one revision has a group naming an id that is gone. The server refuses it. Troubleshooting has that refusal and what it prints.
Reading the policy back
Section titled “Reading the policy back”GET /api/clients answers the clients and the groups of the revision the server is running, and
clients.toml as that revision holds it.
curl -s --unix-socket ./data/run/api.sock http://localhost/api/clients | jqcurl -s --unix-socket ./data/run/api.sock -H 'accept: text/plain' http://localhost/api/clientsEach client answers its name, its group, and the selectors that pick it: addresses, sorted,
subnets, longest prefix first, and arrived_on, sorted. A subnet of one address reads as the
address alone. The default client has none, because it is every query that no selector picks.
Each group answers sources as you wrote it, which is all or named, beside
resolved_sources, which is the ids it uses right now. Those two differ for a group on all,
because that group follows the next source you add.
file is the file as the server runs it, in the shape that a change of the file takes back. A
top-level key that the file leaves out, such as group, is left out there too. A key that an entry
leaves out, such as the subnets of a client, is null. It differs from the lists in three places.
The lists name default as a client. They give the group of a client that names none. They count
the entries of a group where the file lists them.
The second command answers the file’s own text, with its comments, and empty text on a server that
has no clients.toml. Both answers carry an ETag, the revision they come from. Both read the file
of that revision from the disk. Where the copy on disk is damaged, both answer 500 and say to roll
back or restore. An edit in the configuration directory that no revision took yet does not
show here.
On the machine this needs no token: the server takes the operating system’s word for who connected
on its own socket, the same as tadoru config apply. From anywhere else it needs a credential of
any role. Any role sees the addresses, the subnets and the listening addresses that pick each
client, in the lists and in file. It holds no query and no address that asked.
API Reference has the answer field by field.
Changing the file on a running server
Section titled “Changing the file on a running server”To change the clients or the groups on a running server, send the lists that change as JSON. Take
them from file of a read, change them, and send them back with the ETag of that read:
curl -s --unix-socket ./data/run/api.sock -D headers.txt http://localhost/api/clients > policy.jsonTAG=$(grep -i '^etag:' headers.txt | cut -d' ' -f2 | tr -d '\r')jq '.file | {client: ((.client // []) + [{"name": "phone", "addresses": ["192.168.1.30"]}])}' policy.json | curl -s --unix-socket ./data/run/api.sock -X PATCH \ -H 'content-type: application/json' -H "if-match: $TAG" --data-binary @- \ http://localhost/api/clientsIf the configuration changed since that read, in this file or in any other, the answer is 409, and
nothing is written. A list you leave out stays as it is. A list goes whole. client replaces every
[[client]] block, and group every [[group]] block, in place. The comment lines above each
block stay at their place in the list, and do not follow their entry. The comment lines inside a
block are lost. A key of an entry sent as null, as a read gives it, is left out of the entry. An
empty list or null takes every block out.
A list that is the same as the one that runs changes nothing, so file sent back as it came spends
no revision. A file with no client and no group reads as file: {}. The server refuses {} sent
back with 400, because it names nothing to change. A server that has no clients.toml gets one with
the first change that writes an entry. A change that leaves it empty, such as
{"client": [], "group": []}, adds no file and spends no revision. Each other change is one
revision, with every check of the file. The body can be up to 4 MiB, the bound of one configuration
file, and a larger one is refused with 413.
The two lists are checked together. So to rename a group, send group and client in one body,
with the new name in both. A body with the group alone is refused while a client names the old name.
The checks that read blocking.toml too run on each change, and a refusal is 422. A group can only
name a source that blocking.toml defines. A group that a [[regex]] rule names in groups cannot
go or change its name. Change blocking.toml first, then this file. Add the new source before a
group names it. Before a group goes, delete the rule, or narrow its groups to the other groups.
A rule with no groups key applies to every group. So taking the key out widens the rule rather
than removing it, and the server refuses an empty groups list.
To rename a group that a rule names, take three steps in this order:
- In
clients.toml, add a group with the new name, a copy of the old one. The clients stay where they are. - In
blocking.toml, change the old name in the rule’sgroupsto the new one. - In
clients.toml, move the clients to the new group and delete the old group, in one body.
To replace the whole file, send its text with PUT:
curl -s --unix-socket ./data/run/api.sock -H 'accept: text/plain' -D headers.txt \ http://localhost/api/clients > clients.tomlTAG=$(grep -i '^etag:' headers.txt | cut -d' ' -f2 | tr -d '\r')KEY=$(uuidgen)# Edit clients.toml, then send it back with the ETag of that read.curl -s --unix-socket ./data/run/api.sock -X PUT -H "if-match: $TAG" \ -H "idempotency-key: $KEY" --data-binary @clients.toml http://localhost/api/clientsThe server keeps the text as you sent it, byte for byte, with its comments and its line ends. Any
content type is taken, so --data-binary alone does. The body can be up to 4 MiB, and a larger one
is refused with 413 before it is read. A server that has no clients.toml gets one. An empty body
writes an empty file: no client is left, and no group but the built-in default. A PATCH that
leaves the file empty adds no file. A PUT is different, because it says what the file is.
The text is checked as a whole, and against blocking.toml, before anything changes. The server
refuses these with 422:
- a file that does not read as TOML, or a key that the file does not take
- a client or a group that the server cannot use
- a group that names a source that
blocking.tomldoes not define - a file without a group that a
[[regex]]rule names
The answer names the line or the setting, and the file stays as it was.
$TAG is the ETag of the read. If any file of the configuration changed since that read, the
answer is 409 and nothing is written. Then read the file again, make your edit on it, and send it
with the new tag. Where the answer did not arrive, or was a 503 still-writing, you do not know
whether the change landed. Send the same request with the same $KEY. It answers with the outcome
of the first, and does not apply it twice. A request with a new key or with none is a new change.
Without a key, the same text sent again against the same revision is the same change. So a refused
text sent again answers 409 already-refused until something changes.
On the machine this needs no token, as for the read. From anywhere else it needs an operator’s or an administrator’s credentials, and a viewer is refused with 403.
To find out whether the server takes a change, without making it, send it to the check:
curl -s --unix-socket ./data/run/api.sock -X POST -H 'content-type: text/plain' \ -H "if-match: $TAG" --data-binary @clients.toml http://localhost/api/clients/checkThe check reads the body by its content type. A JSON object is checked as PATCH applies it. Text
sent as text/plain is checked as PUT applies the same text. Any other content type is refused
with 415, so name the type: PUT takes text in any type, and the check does not. The body can be up
to 4 MiB.
The answer is the answer of the save, and nothing is written. A 200 says that the change passes
every check of its save, with "unchanged": true where the save makes no new revision. A refusal
is the refusal of the save, with the same file, setting and line. The checks that read
blocking.toml run too. A group that names a source that blocking.toml does not define is named
in clients.toml, such as group.kids.sources. A group gone that a [[regex]] rule names is named
by the rule in blocking.toml, such as regex[0].groups. For a JSON change, line is a line of
the file that the change makes, not a line of your body. If-Match and Idempotency-Key are read
as the save reads them, and the check keeps no record, so the key stays free for the save. A change
that lands between the check and the save is not covered: send the save with the same $TAG, and
it answers 409 then.
A check waits for the same lock as a save. At most four checks wait at once. Past that, a check
answers 503 too-many-changes at once, so a save keeps at least four places. Send the check again
in a moment.
An operator or an administrator can check a change, and a viewer is refused with 403. On the machine, the server’s own user and root check with no token.
Reading the name back
Section titled “Reading the name back”The name goes in the query log, in a column beside the address.
S=./data/run/api.sockA="authorization: Bearer $TOK"
curl -s --unix-socket $S -H "$A" "http://localhost/api/queries?limit=20" \ | jq '.rows[] | {client, client_name}'The row carries the name and not a number, so it reads the same after you rewrite the file. A row written before this column existed carries no name at all, because nothing recorded one. The query log has the rest of a row and how to narrow the range.
The client parameter of that route takes an address and not a name. So you narrow by name in
whatever reads the rows, the way jq does above.
store_clients = false in server.toml leaves out the name with the address. A row saying
kids-tablet still says which machine asked, so that setting takes both columns or neither.
It changes new rows only, and The query log has how to clear the rows already
written.
An arrived_on entry names a listen address
Section titled “An arrived_on entry names a listen address”arrived_on matches the address of this server that received the query, and those addresses
are listen in node.toml. This is how you name a whole link without knowing the addresses on
it. Give the guest network its own listen address, and put that address in arrived_on. Every
query through that address is that client, unless an addresses or subnets entry claims the
machine that asked.
Nothing compares an arrived_on entry against listen. An address you never listen on is
accepted and matches no query, so a typo here is quiet. The port is left out of the comparison
too, so two listeners on one address are one door whatever ports they use.
listen refuses 0.0.0.0 and ::, so every listener you configure has one address of its own
to report. A server answering from an address the query did not arrive on makes the client
discard the reply.
A listening address belongs to one machine, and clients.toml is the same file on every node
of a cluster. So an entry naming 10.0.5.53 applies on whichever node holds that address.
An IPv6 device needs a stable address
Section titled “An IPv6 device needs a stable address”A phone with IPv6 privacy addresses changes its address every day and keeps its prefix. An
addresses entry for that phone stops matching tomorrow, and a /64 keeps matching.
What a /64 names is the link and not the phone. Every device on that link is the same client
under it, unless it has an entry of its own. So the entry answers “the guest network” rather
than “the tablet”. For one device over IPv6, give it a stable address. Set that address on the
device, or reserve it on whatever hands out IPv6 addresses for that link.
A link-local IPv6 address is refused in every selector. fe80::1 names a different machine on
every link, so no rule is about one. An IPv4 link-local address such as 169.254.1.5 is taken,
because it carries no zone anywhere.
What is refused
Section titled “What is refused”A file this server cannot use is refused whole, and the last good configuration keeps serving. The message names the file, the key, and both clients where two of them collide.
Two clients cannot name one selector. That covers one address, one subnet, and one
arrived_on address. It also covers one address written once bare and once as a whole subnet,
such as 10.0.0.1 and 10.0.0.1/32. A name is one client too, so one name twice is refused,
and so is a client called default.
A group has refusals of its own. One group name twice, default counted. A [[group]] with no
sources key, or a sources word that is not all. One source id twice in one group. More than
64 groups, counting default. A group key on a client that no [[group]] in the file declares.
One refusal reads both files. It is a group naming a source that blocking.toml does not define,
and tadoru config validate clients.toml cannot see that one.
A selector that cannot mean what it says is refused as well. A /0 subnet is one, because
that is what default already means. A link-local IPv6 address is another, and so is a subnet
that holds the whole of fe80::/10, such as fe00::/8. An IPv4 address or subnet written as an
IPv6 one is refused too, such as ::ffff:192.168.1.10. A client of it arrives as an IPv4 address,
and a rule of one family holds no address of the other. ::/96 and each subnet inside it, such
as ::/120, are refused for the same reason. A subnet that holds nothing but :: and ::1,
such as ::/127, is read. A client with no selector at all is refused, because no query can ever
be it.
Read the file before the server does:
tadoru config validate clients.tomlclients.toml: who is asking has each key with its
bounds, and Troubleshooting has the refusals you meet most, with what to do
about them.