Clients and APIs
Salt has three ways in. All of them end up in the same checked zone store, with the same grants, and every change appears in the zone's history.
| Interface | Authentication | Use it for |
|---|---|---|
REST API /api/v1 | Authorization: Bearer <token> | Your own automation. |
PowerDNS-compatible API /api/v1/servers/localhost | X-API-Key: <token> | Tools that already speak the PowerDNS API (lego, acme.sh, octoDNS, external-dns). |
| RFC 2136 dynamic update (UDP and TCP, port 53) | TSIG, hmac-sha256 (also hmac-sha384, hmac-sha512) | certbot, lego, nsupdate, DHCP servers. |
Credentials (API tokens and TSIG keys) are created in the web console. Each has
grants: which zone, which names, which record types, and whether it may
read, update or manage. Give a client only what it needs; an ACME client needs
TXT on _acme-challenge and nothing else. A secret is shown once.
REST API
The reference is the OpenAPI 3.1 document, served without authentication at
https://dns.salt-dns.example/api/v1/openapi.json(in the source tree: priv/static/openapi.json). It describes zones, rrsets,
batch changes, the audit log, zone verification and import, name availability
and reservation (guide), provisioning for external systems
(guide), the request and
response bodies, the problem details (RFC 9457) errors, ETag/If-Match
concurrency control and the rate limits (429 with Retry-After).
curl -H "Authorization: Bearer $TOKEN" \
https://dns.salt-dns.example/api/v1/zones/example.org/rrsets
Owner names in the URL are absolute: /zones/example.org/rrsets/www.example.org/A,
not /rrsets/www/A (a relative name is answered out_of_zone). @ is the apex:
/zones/example.org/rrsets/@/MX.
Importing and exporting a zone
Console (a zone's Import tab) and API (import/preview, then
import/apply) read the records from a zone file or by zone transfer (AXFR)
from another server, show what would change, and apply it in one audited batch
(one audit row, one serial bump). merge replaces whole record sets that
appear in the source and keeps the rest; replace makes the zone equal to the
source. SOA, the apex NS set and DNSSEC records are managed by Salt and left
out with a note.
The zone file may be pasted or uploaded, and is read as an RFC 1035 master
file: $ORIGIN and $TTL, absolute and relative names, @, comments (;),
parentheses, and multi-string TXT. $INCLUDE and $GENERATE are refused. A
parse error names the line and shows it.
The review is a diff preview in record sets — added, replaced (same name and type, other data or a new TTL), removed (replace mode) and already as they are — followed by the record-level changes, and by what is rejected: a name outside the zone, or data Salt cannot carry. A rejected entry is left out; the rest is applied.
Conflicts. A record set that the zone's own data at the same name blocks
(a CNAME where the name has other records, or other records where it has a
CNAME) is reported under conflicts with the record sets that would have to
go: %{name, type, ttl, count, delete: [%{name, type}]}. The caller may
choose to replace them by passing the same list back in "replace":
{"source": "zone_file", "zone_file": "...", "mode": "merge",
"replace": [{"name": "autoconfig.example.org", "type": "A"}]}The deletion and the new record set then arrive in the same single audited batch. Left out, the conflict stays rejected.
Undo. Every batch keeps its inverse in the audit row. In the zone's
History an entry with an inverse has Undo this change, which applies it
as one new audited batch (Zones.undo/3, action rrset.undo); the undo is
itself a batch and can be undone in turn.
Export. GET /api/v1/zones/:zone/export (and Export on the records
page) answers the zone as a zone file (text/dns): one line per served
record, an absolute owner name, the rrset's TTL, a header comment with the
time and counts. Disabled records are not served, so they are not in the file
(the header says how many). SOA and DNSSEC records are generated by the
nameserver and are not in it. The file imports back unchanged.
A transfer needs a source that:
- is given as an IP address (not a name), public unless the installation
allows internal addresses (
SaltDns.AddressFilter); - allows transfers to the address this installation connects from (its
outgoing address, which is not the address of its own primary) and, if it asks
for one, the TSIG key you give (
hmac-sha256,-384or-512).
A server that does not may answer REFUSED or NOTAUTH; the error says which
(the server answered refused). Importing from this installation's own
primary does not work for the same reason: it allows transfers only to a
secondary's registered address.
RFC 2136 recipes
The TSIG algorithm must be hmac-sha256 or stronger. hmac-md5, hmac-sha1
and hmac-sha224 are refused. Replace dns.salt-dns.example, the key name and
the secret with the values the console shows for your credential. The
integration tests run lego and certbot against the listener (with Pebble).
A mail server that publishes its own records has a dedicated contract: the
mail preset's names and record types, the listener's UDP/TCP behaviour, the
rate limits and a worked nsupdate example are in
Mail servers.
nsupdate
nsupdate signs with HMAC-MD5 unless you name the algorithm with -y:
nsupdate -y hmac-sha256:acme-key:BASE64SECRET <<'END'
server dns.salt-dns.example 53
zone example.org
update add test.example.org 300 TXT "hello"
send
END
certbot (dns-rfc2136)
# rfc2136.ini (chmod 600)
dns_rfc2136_server = dns.salt-dns.example
dns_rfc2136_port = 53
dns_rfc2136_name = acme-key
dns_rfc2136_secret = BASE64SECRET
dns_rfc2136_algorithm = HMAC-SHA256certbot certonly --dns-rfc2136 --dns-rfc2136-credentials ./rfc2136.ini -d example.org
lego (rfc2136)
lego writes the algorithm with a trailing dot:
export RFC2136_NAMESERVER=dns.salt-dns.example:53
export RFC2136_TSIG_ALGORITHM=hmac-sha256.
export RFC2136_TSIG_KEY=acme-key
export RFC2136_TSIG_SECRET=BASE64SECRET
lego --dns rfc2136 -d example.org -m you@example.org run
Updates are only accepted for active zones of the key's organisation.
Anything else is answered NOTAUTH, so the existence of other organisations'
zones is not revealed. A wrong key or clock skew is also NOTAUTH (BADKEY,
BADSIG or BADTIME); the server log says which, with a hint.
PowerDNS compatibility
Base path: /api/v1/servers/localhost (the server id localhost, or the
alias set with config :salt_dns, SaltDnsWeb.PDNS, server_alias:).
Authentication: X-API-Key: <an API token>. lego (pdns) and acme.sh
(dns_pdns) are run against it in the integration tests; the request
sequences of octoDNS and external-dns (through go-powerdns) are replayed in
contract tests; the answers are compared with golden files
(test/fixtures/pdns).
| Endpoint | Status | Notes |
|---|---|---|
GET /api, GET /api/v1 | supported | Version list, no key needed. |
GET /api/v1/servers, GET .../servers/localhost | supported | Fixed daemon type and version strings. |
GET .../config | supported | Neutral values. |
GET .../zones (?zone= filter) | supported | Only zones the token may read. |
POST .../zones | supported | Creates a pending zone (needs the grant for creating zones). Kinds Native, Master, Producer; Slave and Consumer are 422. dnssec: true switches DNSSEC on. |
GET .../zones/{zone_id} | supported | With rrsets. The apex SOA and NS are listed read only. |
PATCH .../zones/{zone_id} | supported | REPLACE and DELETE, all or nothing in one transaction. Deleting a missing rrset is not an error. Changing SOA, apex NS or DNSSEC types is 422. comments are ignored. |
DELETE .../zones/{zone_id} | supported | |
PUT .../zones/{zone_id}/notify | accepted, no effect | Salt notifies secondaries after every change. Needs only read, so ACME-only tokens can call it. |
PUT .../zones/{zone_id} (zone metadata) | not supported | |
.../axfr-retrieve, .../export, .../rectify | not supported | Import or export zone data with the REST API (import, export) or the console. |
.../cryptokeys, .../metadata | not supported | DNSSEC is managed in the console or REST API. |
.../tsigkeys, .../autoprimaries | not supported | Credentials are managed in the console. |
.../search-data, .../statistics, .../cache/flush | not supported |
Endpoints that are not supported answer 404. Errors have the PowerDNS shape,
{"error": "message"}: 401 (also for a missing key), 403, 404, 409, 422, 429.
A zone id is the zone name with a trailing dot, every byte outside
[A-Za-z0-9._-] written as =XX (so a / is =2F).
Fields PowerDNS has but Salt has no use for (masters, nameservers,
soa_edit, soa_edit_api, account, catalog, api_rectify, nsec3param,
nsec3narrow, presigned, TSIG key ids) are accepted and ignored on input and
have fixed neutral values in answers.
lego (pdns)
export PDNS_API_URL=https://dns.salt-dns.example
export PDNS_API_KEY=salt_...
lego --dns pdns -d example.org -m you@example.org run
acme.sh (dns_pdns)
export PDNS_Url="https://dns.salt-dns.example"
export PDNS_ServerId="localhost"
export PDNS_Token="salt_..."
export PDNS_Ttl=60
acme.sh --issue --dns dns_pdns -d example.org