Skip to content

S07-03 - DNS

Purpose: How wb-netd answers the guest’s DNS queries: synthetic addresses, the name form, negative answers and the wildcard budget.

wb-netd answers DNS, on UDP and TCP port 53 on the gateway only. How it refuses a name, and the hold before each refusal, are on S07-04-dns-refusalsS07-04-dns-refusals: DNS RefusalsHow wb-netd refuses a name: approval events, the hold before each refusal, quiet refusals, and the answer that is the same for every reason..

wb-netd reads the header and the question from the wire bytes itself, and passes the question’s labels to the name form check as they are. It answers a message only when it is a query of at most 512 bytes with:

  • QR clear and the opcode QUERY;
  • exactly one question, of class IN, with no compression pointer and no label type other than a plain label;
  • no answer or authority records;
  • at most one additional record, an OPT for the root name;
  • no bytes after the last record.

Any other message is dropped without an answer, and counted with the rule dns-message-form and the fault (SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped.).

A response echoes the question’s wire bytes. The guest gets back the case it sent. A response copies RD and sets RA. It has no OPT record.

Each query that passes “Messages” goes through these steps in order. The first that refuses decides the answer:

  1. Local answers. A last label of arpa or local, in any case (“Local answers”).
  2. Query rate. dns-query-rate (“Wildcard budget”). A name that fails the form spends a token too, so many bad names in a burst are dropped like other queries (SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped.).
  3. Name form. dns-name-form (“Name form”).
  4. Host state. audit-budget, audit-bytes or event-channel-blocked (S09-11-auditS09-11-audit: AuditWhat the audit log records, the budgets that bound it, and what happens when the log can't be written.).
  5. The name’s class in the effective policy: allowed by an exact entry, allowed by a wildcard, denied, in a part that is off, or not allowed. A name that isn’t allowed and is on the guest OS’s background list is a background name. The class doesn’t decide yet.
  6. The wildcard budget debit, for every name that isn’t allowed by an exact entry, refused names included (“Wildcard budget”). A budget that is used up refuses with wildcard-budget, and a failed or late record with accounting-write-failed. Either rule replaces the class’s refusal, and no approval event is raised.
  7. The class’s refusal or the answer:
    • a denied name is refused with name-denied;
    • a name in a part that is off with profile-part-off;
    • a background name with guest-os-background;
    • any other name the policy doesn’t allow with name-not-allowed, which is the one that reaches the approval hook;
    • for an allowed A query, the pool writes the entry’s record and sends the name report before the answer.

A query over the rate in step 2 is dropped at once without an answer. A burst then fills the held-query table only at the rate (S07-04-dns-refusalsS07-04-dns-refusals: DNS RefusalsHow wb-netd refuses a name: approval events, the hold before each refusal, quiet refusals, and the answer that is the same for every reason., “Over the rate”). Every refusal after step 2 builds its bytes when the query arrives and holds them (S07-04-dns-refusalsS07-04-dns-refusals: DNS RefusalsHow wb-netd refuses a name: approval events, the hold before each refusal, quiet refusals, and the answer that is the same for every reason., “Hold”). The rate comes before anything that can debit.

The log record of every refusal after step 5 has a class attribute, so a name refused with wildcard-budget or accounting-write-failed still shows the class rule that would have refused it. A background name is counted on the background list, whatever rule refuses it after step 5.

A queries for allowlisted names are answered with a synthetic address from a reserved range, 198.18.0.0/15. The address is allocated per name, and remembered with a TTL.

Real upstream addresses are never revealed to the guest. Before each such answer leaves, wb-netd reports the name and address to wb-proxyd (S07-05-stream-hand-offS07-05-stream-hand-off: Stream Hand-offHow wb-netd hands each stream to wb-proxyd, and the checks that keep a compromised wb-netd from widening what a stream may reach.).

Each VM has the 131,072 addresses of 198.18.0.0/15. An address is never given to another name:

  • while a connection to it is open;
  • before its TTL plus a guard interval has passed since its last answer.

wb-netd releases an entry when it expires: once its TTL plus the guard has passed since its last answer and no connection to it is open. It doesn’t wait until another name needs the address. It records the release with wb-hostd and reports it to wb-proxyd before the address is free again (S07-06-name-mappingS07-06-name-mapping: Name MappingHow wb-proxyd keeps its own checked copy of the names wb-netd gave synthetic addresses: name reports, releases, replay, lifetime, the second count of the wildcard budget, and the copy wb-hostd keeps., “Releases”). Free addresses are given out in the order they were freed, so a released address is reused as late as possible.

When no address is free, a new name gets SERVFAIL, logged with the rule synthetic-pool-full.

TCP to a synthetic address with no live entry is reset at its first SYN with the rule synthetic-unmapped (S07-02-packet-pathS07-02-packet-path: Packet PathHow wb-netd carries the guest's frames: the packet transport, the stack, the link filter, its caps, addressing, the MTU and connections., “Connections”). TCP on an allowed port while wb-netd has no hand-off socket is reset with the rule handoff-unavailable.

Inspected plain HTTP requires the Host header to equal the name mapped to the synthetic address.

For allowlisted names:

  • AAAA, HTTPS and SVCB queries get an empty answer;
  • other record types get REFUSED at once, logged with the rule dns-type-refused. The name is allowed, and the timing tells the guest nothing it doesn’t know. The answer isn’t held.

The macOS resolver asks for HTTPS before most A queries. The spike refused HTTPS. The empty answer is a choice nobody measured (B17-network-pathB17-network-path: Does a macOS guest work on our userspace network stack, reaching only the proxy, and how fast?Yes, with conditions.).

The empty answer gives no HTTPS record that could hold an encrypted ClientHello configuration, or an HTTP/3 hint that wb-proxyd can’t honor. Giving no HTTPS or SVCB record is a deliberate compatibility measure: clients that look up ECH keys in DNS don’t try ECH. It isn’t a control against a guest that brings its own ECH keys (S07-16-tls-and-tunnelsS07-16-tls-and-tunnels: TLS and TunnelsWhat wb-proxyd does with client certificates, encrypted ClientHello and tunnels, and which refusals no mode or approval relaxes., “Encrypted ClientHello”).

wb-netd answers these names itself:

  • every name under .arpa: reverse lookups, _dns.resolver.arpa, ipv4only.arpa, home.arpa;
  • every name under .local.

The answer is NXDOMAIN with the zero SOA record (“Negative answers”), sent at once. It doesn’t debit the budget or raise an approval event, and is logged with the rule dns-local-answer. The match is on the last label as it is on the wire, before the name form check, so a local name that fails the form, such as _dns.resolver.arpa, still gets the local answer. Its name is logged through the log escaping of guest text, since it never passed the form.

An idle macOS guest asks for its own reverse name and for _dns.resolver.arpa after each lease (X03-network-pathX03-network-path: Network pathA macOS guest boots on the file-handle attachment with the gVisor stack: gets a DHCP lease, resolves only allowlisted names, reaches only the proxy.).

The form is checked on the labels as they are on the wire:

The canonical form of a name that passes is lower case, without a trailing dot (S07-06-name-mappingS07-06-name-mapping: Name MappingHow wb-proxyd keeps its own checked copy of the names wb-netd gave synthetic addresses: name reports, releases, replay, lifetime, the second count of the wildcard budget, and the copy wb-hostd keeps., “Name reports”). The policy loader and wb allow remove one trailing dot from a host before the check.

Outside the local answers above, a query whose name breaks the form gets NXDOMAIN with the rule dns-name-form. That check comes before any other check of the name. Only the query rate, which reads no name, comes first (“Order of checks”).

Such a name raises no approval event, and stays off every learn list. So no control byte or non-ASCII character from a name reaches a notification, wb status or wb learn report.

The policy loader and wb allow refuse a host that fails this rule. For a wildcard host they check the part after its leading *.. The refusal has the same rule name, and an error that names the host and the character or length at fault (NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.). So an allowed host never loads and then fails to resolve.

A name whose last label is all digits, or is 0x or 0X followed by hexadecimal digits or by nothing, is an IPv4 address in a form some resolvers accept. It fails the name form rule as above:

  • a query gets NXDOMAIN with the rule dns-name-form;
  • the policy loader and wb allow refuse it as a host.

An IPv6 literal has colons, and already fails the LDH rule. So no policy host names an address (SEC05-default-denySEC05-default-deny: Default-deny egress, enforced on the hostOnly allowlisted hostnames are reachable.).

Every NXDOMAIN that wb-netd sends, the local answers included, carries an SOA record for the root zone in its authority section. The record has a TTL of 0 and a MINIMUM of 0, and is the same every time.

A resolver caches a negative answer for the smaller of the two (RFC 2308). So the guest doesn’t cache a refusal, and a lookup after a later approval reaches wb-netd and succeeds.

  • Allowed names. An empty answer for an allowed name (AAAA, HTTPS, SVCB) has the same SOA record, with the TTL and MINIMUM of that name’s A answer. So the guest doesn’t ask for those types more often than for A.
  • Program caches. The SOA record doesn’t reach a negative cache inside a program, such as Java’s (10 seconds by default). Such a program’s lookups of a name fail until its cache expires.

Wildcard allowlist entries are bounded. Each VM may resolve at most a fixed number of new names under wildcards in an active period (S07-01-per-vm-policyS07-01-per-vm-policy: Enforced per VMWhy the VM is the unit the gateway enforces, how the policies of its projects combine, and what happens when they conflict or change.).

A query debits the budget once per distinct canonical name per active period, when it passed steps 2 to 4 of “Order of checks” and its name isn’t allowed by an exact entry. So a new name allowed only by a wildcard debits, and so does a refused name, a background name included. A query refused for its name form or the host state, or dropped for its rate, doesn’t debit. The debit’s record is written to wb-hostd before the answer, within 100 ms. A failed or late write refuses the query with accounting-write-failed. At start, wb-netd takes the debited names or the count wb-hostd kept (S04-07-supervisionS04-07-supervision: SupervisionWho starts and restarts each host process, what happens when wb-hostd stops or the bundle is upgraded, and daemon outages., “What a restart keeps”). A new active period clears them.

At the start of a new active period (S07-01-per-vm-policyS07-01-per-vm-policy: Enforced per VMWhy the VM is the unit the gateway enforces, how the policies of its projects combine, and what happens when they conflict or change.), wb-hostd clears its own set of the VM’s debits, then sends the running wb-netd an ActivePeriodStart that names the VM and doesn’t hold a descriptor. wb-netd clears the debited names and their count, keeps its name mapping, and logs it with the rule active-period-start. It doesn’t acknowledge the message. One that names another VM than its own, or holds a descriptor, ends the control channel.

A debit written before wb-netd reads the message is added to wb-hostd’s new set, so that set never holds fewer names than wb-netd counts. It can hold more. A restart takes those names as debits of the new period, which only lowers the budget. With the budget at its largest, 65,535 names, one of them can make a debit the 65,536th. wb-hostd refuses that record with wildcard-count (S07-06-name-mappingS07-06-name-mapping: Name MappingHow wb-proxyd keeps its own checked copy of the names wb-netd gave synthetic addresses: name reports, releases, replay, lifetime, the second count of the wildcard budget, and the copy wb-hostd keeps., “Kept by wb-hostd”), which ends wb-netd and stops its VM.

The name length is limited (“Name form”). A query over the VM’s query rate limit, 100 queries a second with a burst of 200, is dropped with the rule dns-query-rate (S07-04-dns-refusalsS07-04-dns-refusals: DNS RefusalsHow wb-netd refuses a name: approval events, the hold before each refusal, quiet refusals, and the answer that is the same for every reason., “Over the rate”). The limit stops floods, not normal use.

Every NXDOMAIN carries the root SOA record with TTL and MINIMUM 0.

Status: Draft