Choosing a sub-domain: is the name free?
An app that lets people pick a sub-domain under a zone hosted in Salt (for
example alice.apps.example.com) has to ask whether the name is available, and
then claim it without racing another person. Salt answers with three
calls on the HTTP API (openapi.json has every field).
The answer
For one label (a single name part directly under the zone, no dots) the status is one of:
| Status | Meaning |
|---|---|
taken | A record set exists at the name, or anywhere below it. A name with records below it exists in DNS even when it has none of its own, and below a delegation (an NS set) everything belongs to someone else. reason is records or records_below. |
reserved | The label is on the zone's reserved list (see below). |
free | Neither. |
taken wins over reserved: a reserved name that gets records is reported as
taken (the reservation member is still returned). Labels are case-insensitive;
they may contain letters, digits, hyphen and underscore, at most 63 characters.
A label with a dot, a wildcard or an empty label is a 422.
curl -H "Authorization: Bearer $TOKEN" \
https://dns.salt-dns.example/api/v1/zones/apps.example.com/names/alice
{"name": "alice.apps.example.com", "label": "alice", "status": "free",
"reason": null, "reservation": null}Reserving, atomically
curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"note": "alice, ticket 1234"}' \
https://dns.salt-dns.example/api/v1/zones/apps.example.com/names/alice/reserve
201with the same shape as the check (statusis nowreserved).409with the problemname_takenorname_reservedwhen it was not free. The problem has the membersnameandavailability.
The body is optional; note is text of at most 200 characters, and reference (at most 128 characters) is the caller's own handle, stored with the reservation (it is what claim uses to recognise a retry). Reserving is one
insert against a unique index in Postgres, so of any number of simultaneous
requests for one label, on any number of replicas, exactly one gets 201. The
usual flow is: check (to show the person a good answer), then reserve (to claim
it), then create the records, then keep or release the reservation as your app
sees fit.
A reservation is not a lock on the zone: it does not stop anyone with write
access from adding records at the name through the API, the console or RFC 2136,
and it is not part of the zone's audit log or version. It is an answer to the
check. The reservation records who made it (source, created_at, note).
The one race it does not cover is a record being added at the label between the
check and the insert; the reservation is then still stored and the check reports
taken.
The reserved list
GET /zones/{zone}/reserved-names?limit=100&after=<label>
DELETE /zones/{zone}/reserved-names/{label}The list is ordered by label; pass next as after for the following page.
DELETE is 204, or 404 when the label is not reserved. The same list is in
the console, on the Names tab of a zone: anyone who can read the zone sees
it and can check a name; owners, admins and editors can reserve and release.
Use it to keep back names such as www, admin or mail.
Permissions
The calls are authorised on the zone as a whole, not on the single name:
| Call | Needs |
|---|---|
| check, list | read on the zone |
reserve, claim, release (DELETE .../names/{label} and DELETE .../reserved-names/{label}) | update on the zone |
For an API token this means a grant that covers the apex (@); a grant with
names ["*"] does, a grant for ["*.apps"] alone does not. The token also
needs to belong to the organisation that owns the zone: another organisation's
zone (even one with the same name) is a plain 404, and reservations are
per zone, so the same label in two organisations' zones never interacts. The
zone must not be disabled to reserve or release.
Reserving and writing the records in one step
An app that also writes the records of the name it hands out should use POST /zones/{zone}/names/{label}/claim, which does the check, the reservation and the
records in one transaction. It is described, with the rest of what a provisioning
system needs, in the Provisioning API.