2 Commits
Author SHA1 Message Date
bryanpedini a67183b646 feat: manage TLSA records
Test / test (push) Successful in 28m4s
Build and publish image / image (push) Successful in 28m43s
2026-11-22 11:31:59 +01:00
bryanpedini 9c2fb9d15b feat(ui): rename the zone list problems column to status 2026-11-22 11:31:59 +01:00
16 changed files with 143 additions and 17 deletions

No files matched your search

+7 -5
View File
@@ -47,7 +47,7 @@ In scope:
- User management from the web UI for admins: create, change role, set password, delete. Deletion only sets `deleted_at`; the row stays in the database for the audit.
- Zone list with record counts, SOA serial and problem counts.
- Zone creation (SOA and NS records in one transaction) and zone deletion, by admins.
- Creation, editing and deletion of records of every type the plugin serves: `A`, `AAAA`, `CNAME`, `NS`, `MX`, `TXT`, `SRV`, `CAA`, `SOA`. Wildcard names are supported.
- Creation, editing and deletion of records of every type the plugin serves: `A`, `AAAA`, `CNAME`, `NS`, `MX`, `TXT`, `SRV`, `CAA`, `TLSA`, `SOA`. Wildcard names are supported.
- Bulk deletion of records.
- Automatic SOA serial management.
- Zone checks that report every row the plugin cannot serve correctly.
@@ -94,7 +94,7 @@ The table belongs to the operator and is shared with CoreDNS and possibly with o
- `name`: the owner name relative to the zone, without trailing dot; the empty string is the apex. `*` as the complete leftmost label is a wildcard (`*`, `*.dev`). Names are matched through the column collation, so case does not affect lookups, but the application stores them lowercase.
- `ttl`: seconds. `0` is served as 360 seconds (the plugin's built-in default). The plugin scans the column into an unsigned integer, so a `NULL` or a negative value makes every query that reads the row fail with SERVFAIL. The application never writes `NULL` or negative values.
- `content`: a JSON object whose shape depends on the type (below). A `NULL` or a value that is not valid JSON makes every query that reads the row fail with SERVFAIL.
- `record_type`: one of the nine uppercase type names. The plugin selects rows with a case-insensitive `IN (...)` and then dispatches on the exact string, so a lowercase `a` or an unknown type makes queries of that type answer NOTIMP. The application only writes the nine uppercase names.
- `record_type`: one of the ten uppercase type names. The plugin selects rows with a case-insensitive `IN (...)` and then dispatches on the exact string, so a lowercase `a` or an unknown type makes queries of that type answer NOTIMP. The application only writes the ten uppercase names.
### Content JSON per type
@@ -110,6 +110,7 @@ The keys are those of the plugin source (`types.go`). In particular the MX key i
| `TXT` | `{"text": "v=spf1 -all"}` | the plugin splits the text into 255-byte strings |
| `SRV` | `{"priority": 10, "weight": 5, "port": 443, "target": "host.example.org."}` | 0 to 65535 each, FQDN |
| `CAA` | `{"flag": 0, "tag": "issue", "value": "ca.example.net"}` | |
| `TLSA` | `{"usage": 3, "selector": 1, "matching_type": 1, "certificate": "0123...cdef"}` | 0 to 255 each, lowercase hex |
| `SOA` | `{"ns": "ns1.example.org.", "MBox": "hostmaster.example.org.", "refresh": 3600, "retry": 600, "expire": 604800, "minttl": 300, "serial": 2026111700}` | only at the apex |
The application writes content in a canonical form: the keys above in the order above, numbers as JSON numbers, no other keys. Rows written by other writers are read tolerantly (any key order, extra keys ignored) and rewritten in canonical form only when edited.
@@ -329,6 +330,7 @@ The CoreDNS user keeps `SELECT` on `coredns_records` only, so it cannot read pas
| `TXT` | 1 to 4096 bytes of printable ASCII without backslash |
| `SRV` | owner name starts with `_service._proto`; priority, weight, port 0 to 65535; target host or `.` |
| `CAA` | flag `0` or `128`; tag 1 to 15 lowercase letters or digits (`issue`, `issuewild`, `iodef` suggested); value 1 to 1024 bytes of printable ASCII without backslash |
| `TLSA` | usage, selector, matching type 0 to 255; certificate association data 1 to 65532 bytes as even-length hex, stored lowercase; matching type `1` needs 32 bytes, `2` needs 64 bytes |
| `SOA` | apex only; `ns` and `MBox` FQDN; refresh, retry, expire, minttl 0 to 2147483647 |
After field validation every record is converted to the `miekg/dns` RR the plugin would build from it and packed into a message; a record that does not pack is refused. This catches anything the field rules miss.
@@ -586,7 +588,7 @@ Errors (the plugin fails or serves something different):
| `ttl_negative` | `ttl` below 0 |
| `content_null` | `content` is `NULL` |
| `content_json` | `content` is not a JSON object |
| `type_unknown` | `record_type` not one of the nine uppercase names |
| `type_unknown` | `record_type` not one of the ten uppercase names |
| `field_invalid` | a field missing or outside the per-type rules (the plugin skips or misserves the record) |
| `name_not_fqdn` | host, target, `ns` or `MBox` without trailing dot |
| `mx_priority_key` | MX content with `priority` and no `preference` |
@@ -783,7 +785,7 @@ Core flow:
1. Start the stack and wait for `/health`.
2. The login page shows the bootstrap command; create the first admin through `docker exec ... /app user add <username> admin`, log in.
3. Create a zone, wait for the plugin's zone reload, verify SOA and NS answers.
4. Create, edit and delete records of all nine types, including wildcards, CNAME chains, null MX and SRV `.` targets, verifying each change with `dig` and the SOA serial bump.
4. Create, edit and delete records of all ten types, including wildcards, CNAME chains, null MX and SRV `.` targets, verifying each change with `dig` and the SOA serial bump.
5. Bulk delete; export; replace-import of the export produces no changes; merge and replace imports with diffs verified.
6. Check panel and `check` CLI against rows broken on purpose through direct SQL (each error code), and the UI's repair of those rows.
7. Users and delegation: the admin creates two users with role `user` and a second admin from the Users page and delegates two zones to the first user. The first user sees and edits only those zones, verified with `dig`; the second sees no zone; both get `404` on every other zone and `403` on admin routes. Revoking a delegation takes effect on the next request of an open session; promotion and demotion likewise. Deleting a user ends their sessions and refuses their login; the row is still in MySQL with `deleted_at` set and its delegations and audit rows intact; creating a user with the same username is refused. The last active admin cannot be demoted or deleted.
@@ -831,7 +833,7 @@ Each phase ends with all tests green and its commits.
- The binary starts the HTTP server with no arguments and provides `help`, `version`, `healthcheck`, `user list|add|passwd|role|delete`, `check [zone]` and `audit [n]` with the documented output and exit codes.
- The application never creates or alters the records table, verifies its contract at startup and works with the least-privilege grants of section 6.
- Zones and records of all nine types can be created, edited and deleted from the UI; every write is validated, serialized per zone, protected by ETags, bumps a managed SOA serial once and is audited in the same transaction.
- Zones and records of all ten types can be created, edited and deleted from the UI; every write is validated, serialized per zone, protected by ETags, bumps a managed SOA serial once and is audited in the same transaction.
- Admins see and do everything; users see and operate only on the zones delegated to them, on every page and API route. Admins create users, change roles, set passwords, delete users and delegate zones from the web UI. Usernames are unique across all users, deleted ones included; deleting a user only sets `deleted_at`; at least one active admin always remains.
- Every operation of section 9 has exactly one audit row with the specified columns, reads and refused requests included, and the audit table is append-only.
- Every row written by the application is served by CoreDNS with exactly the entered data, verified end to end with `dig`.
+3 -2
View File
@@ -9,7 +9,7 @@ The same binary starts the HTTP server when run without arguments and provides s
- Login with local users, sessions and password change.
- Two roles: `admin` sees and does everything, `user` sees and operates only on the zones delegated to them.
- Zone creation (SOA and NS records in one transaction) and deletion, by admins.
- Creation, editing and deletion of records of every type the plugin serves: `A`, `AAAA`, `CNAME`, `NS`, `MX`, `TXT`, `SRV`, `CAA` and `SOA`. Wildcard names are supported. Bulk deletion of records.
- Creation, editing and deletion of records of every type the plugin serves: `A`, `AAAA`, `CNAME`, `NS`, `MX`, `TXT`, `SRV`, `CAA`, `TLSA` and `SOA`. Wildcard names are supported. Bulk deletion of records.
- Automatic SOA serial management.
- A zone check that reports every row the plugin cannot serve correctly, with a repair path in the UI.
- Zone file export and import (RFC 1035 master file format).
@@ -53,7 +53,7 @@ The application's own tables live in the same database, prefixed with `<prefix>w
- `zone`: the zone apex, lowercase, with the trailing dot (`example.org.`). The plugin lists zones with `SELECT DISTINCT zone`, so a zone exists as soon as one row carries it.
- `name`: the owner name relative to the zone, lowercase, without trailing dot. The empty string is the apex. `*` as the complete leftmost label is a wildcard.
- `ttl`: an integer from 0 to 2147483647. Never `NULL`, never negative.
- `record_type`: one of the nine uppercase type names.
- `record_type`: one of the ten uppercase type names.
- `content`: a JSON object in canonical form (keys in the order below, no other keys). Rows written by other writers are read tolerantly (any key order, extra keys ignored) and rewritten in canonical form only when edited.
- Every host, target, `ns` and `MBox` is stored as a lowercase FQDN with the trailing dot, because the plugin does not make `NS`, `MX`, `SRV` and `SOA` names fully qualified and packing fails on names without it.
@@ -67,6 +67,7 @@ The application's own tables live in the same database, prefixed with `<prefix>w
| `TXT` | `{"text": "v=spf1 -all"}`, 1 to 4096 bytes of printable ASCII without backslash |
| `SRV` | `{"priority": 10, "weight": 5, "port": 443, "target": "host.example.org."}`, the owner name starts with `_service._proto` |
| `CAA` | `{"flag": 0, "tag": "issue", "value": "ca.example.net"}`, flag `0` or `128` |
| `TLSA` | `{"usage": 3, "selector": 1, "matching_type": 1, "certificate": "0123...cdef"}`, usage, selector and matching type 0 to 255, certificate association data as lowercase even-length hex (32 bytes for matching type `1`, 64 bytes for `2`); served only by a plugin build with TLSA support |
| `SOA` | `{"ns": "ns1.example.org.", "MBox": "hostmaster.example.org.", "refresh": 3600, "retry": 600, "expire": 604800, "minttl": 300, "serial": 2026111700}`, only at the apex |
After field validation every record is converted to the `miekg/dns` RR the plugin builds from it and packed into a message; a record that does not pack is refused.
+8
View File
@@ -44,6 +44,7 @@ const IPV4: Field = { valid: ['192.0.2.55', '198.51.100.7', '203.0.113.200'], ho
const IPV6: Field = { valid: ['2001:db8::55', '2001:db8:0:0:0:0:0:56', '2001:DB8::57'], hostile: ['192.0.2.55', '::ffff:192.0.2.1', '2001:db8::g', SQL_INJECTION, SCRIPT, '', 1] };
const CAA_TAG: Field = { valid: ['issue', 'issuewild', 'iodef'], hostile: ['bad tag', SCRIPT, SQL_INJECTION, '', 'x'.repeat(256), 1] };
const CAA_FLAG: Field = { valid: [0, 128], hostile: [256, -1, '0', SQL_INJECTION, null] };
const OCTET: Field = { valid: [0, 1, 2, 3, 255], hostile: [256, -1, '3', 1.5, null, SQL_INJECTION] };
const SOA_TIMER: Field = { valid: [60, 3600, 604800, 2147483647], hostile: [0, -1, 2147483648, 4294967296, '3600', null, SQL_INJECTION] };
function hosts(zone: string): Field {
@@ -71,6 +72,13 @@ function fields(zone: string, type: RecordType): Record<string, Field> {
return { priority: U16, weight: U16, port: U16, target: { valid: ['sip.example.net.', '.'], hostile: host.hostile } };
case 'CAA':
return { flag: CAA_FLAG, tag: CAA_TAG, value: { valid: TEXT.valid.filter((t) => t !== '' && String(t).length < 256), hostile: TEXT.hostile } };
case 'TLSA':
return {
usage: OCTET,
selector: OCTET,
matching_type: { valid: [0], hostile: OCTET.hostile },
certificate: { valid: ['0123456789abcdef', '30' + 'AB'.repeat(40), 'ff'], hostile: ['', 'abc', 'xyz0', '0x1234', 'ab cd', SCRIPT, SQL_INJECTION, 7, null] },
};
case 'SOA':
return {
ns: { valid: ['ns1.example.net.', `ns1.${zone}`], hostile: host.hostile },
+6 -1
View File
@@ -3,7 +3,7 @@
import { expect } from '@playwright/test';
export const TYPES = ['A', 'AAAA', 'CNAME', 'NS', 'MX', 'TXT', 'SRV', 'CAA', 'SOA'] as const;
export const TYPES = ['A', 'AAAA', 'CNAME', 'NS', 'MX', 'TXT', 'SRV', 'CAA', 'TLSA', 'SOA'] as const;
export type RecordType = (typeof TYPES)[number];
export const EDITABLE_TYPES = TYPES.filter((t) => t !== 'SOA');
@@ -16,6 +16,7 @@ export const CANONICAL_KEYS: Readonly<Record<RecordType, readonly string[]>> = {
TXT: ['text'],
SRV: ['priority', 'weight', 'port', 'target'],
CAA: ['flag', 'tag', 'value'],
TLSA: ['usage', 'selector', 'matching_type', 'certificate'],
SOA: ['ns', 'MBox', 'refresh', 'retry', 'expire', 'minttl', 'serial'],
};
@@ -92,6 +93,8 @@ export function digData(type: RecordType, d: RecordData): string {
return `${d.priority} ${d.weight} ${d.port} ${d.target}`;
case 'CAA':
return `${d.flag} ${d.tag} ${dnsQuote(String(d.value))}`;
case 'TLSA':
return `${d.usage} ${d.selector} ${d.matching_type} ${d.certificate}`;
case 'SOA':
return `${d.ns} ${d.MBox} ${d.serial} ${d.refresh} ${d.retry} ${d.expire} ${d.minttl}`;
}
@@ -113,6 +116,8 @@ export function uiValue(type: RecordType, d: RecordData): string {
return `${d.priority} ${d.weight} ${d.port} ${d.target}`;
case 'CAA':
return `${d.flag} ${d.tag} "${d.value}"`;
case 'TLSA':
return `${d.usage} ${d.selector} ${d.matching_type} ${d.certificate}`;
case 'SOA':
return [d.ns, d.MBox, d.serial ?? 'dynamic', d.refresh, d.retry, d.expire, d.minttl].join(' ');
}
+15 -2
View File
@@ -7,7 +7,7 @@ import type { GroupConfig } from './env';
import type { RecordRow } from './mysql';
import type { Recorder } from './recorder';
export const PLUGIN_TYPES = ['A', 'AAAA', 'CNAME', 'NS', 'MX', 'TXT', 'SRV', 'CAA', 'SOA'];
export const PLUGIN_TYPES = ['A', 'AAAA', 'CNAME', 'NS', 'MX', 'TXT', 'SRV', 'CAA', 'TLSA', 'SOA'];
const MAX_CNAME_CHAIN = 10;
const DEFAULT_TTL = 360;
@@ -123,6 +123,14 @@ function rrFor(row: RecordRow, now: () => number): ModelRR | null {
if (str(c.value) === '' || str(c.tag) === '') return null;
return { name: owner, ttl, type: 'CAA', data: `${u32(c.flag) & 0xff} ${str(c.tag)} ${quote(str(c.value))}` };
}
case 'TLSA': {
const octet = (v: unknown) => typeof v === 'number' && Number.isInteger(v) && v >= 0 && v <= 255;
if (!octet(c.usage) || !octet(c.selector) || !octet(c.matching_type)) throw new ModelFailure('SERVFAIL');
const cert = str(c.certificate);
if (cert === '' || cert.length % 2 !== 0 || !/^[0-9a-fA-F]+$/.test(cert)) throw new ModelFailure('SERVFAIL');
if ((c.matching_type === 1 && cert.length !== 64) || (c.matching_type === 2 && cert.length !== 128)) throw new ModelFailure('SERVFAIL');
return { name: owner, ttl, type: 'TLSA', data: `${c.usage} ${c.selector} ${c.matching_type} ${cert.toLowerCase()}` };
}
case 'SOA': {
const serial = u32(c.serial) === 0 ? now() : u32(c.serial);
return {
@@ -242,12 +250,17 @@ export class PluginModel {
}
}
function tlsaData(data: string): string {
const [usage, selector, matching, ...certificate] = data.trim().split(/\s+/);
return `${usage} ${selector} ${matching} ${certificate.join('').toLowerCase()}`;
}
function canon(rrs: Array<ModelRR | DigRR>, wildcardOk: string): string[] {
return rrs
.map((r) => {
const name = r.name.toLowerCase();
const n = name.startsWith('*.') ? wildcardOk : name;
const data = r.type === 'SOA' ? r.data.toLowerCase().replace(/^(\S+ \S+) \d+/, '$1 SERIAL') : r.data;
const data = r.type === 'SOA' ? r.data.toLowerCase().replace(/^(\S+ \S+) \d+/, '$1 SERIAL') : r.type === 'TLSA' ? tlsaData(r.data) : r.data;
return `${n} ${r.ttl} ${r.type} ${data}`;
})
.sort();
+8
View File
@@ -168,6 +168,8 @@ test.describe('core flow', () => {
nosrv: { name: '_none._tcp', type: 'SRV', ttl: 3600, data: { priority: 0, weight: 0, port: 0, target: '.' } },
caa: { name: '', type: 'CAA', ttl: 3600, data: { flag: 0, tag: 'issue', value: 'ca.example.net' } },
iodef: { name: '', type: 'CAA', ttl: 3600, data: { flag: 128, tag: 'iodef', value: 'mailto:security@example.net' } },
tlsa: { name: '_25._tcp.mail', type: 'TLSA', ttl: 3600, data: { usage: 3, selector: 1, matching_type: 1, certificate: '0123456789abcdef'.repeat(4) } },
tlsafull: { name: '_443._tcp.www', type: 'TLSA', ttl: 300, data: { usage: 0, selector: 1, matching_type: 0, certificate: '302a300506032b6570032100d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a' } },
sub: { name: 'sub', type: 'NS', ttl: 3600, data: { host: 'ns.example.net.' } },
wild: { name: '*', type: 'A', ttl: 0, data: { ip: '192.0.2.99' } },
wilddev: { name: '*.dev', type: 'TXT', ttl: 600, data: { text: 'wildcard dev' } },
@@ -235,6 +237,8 @@ test.describe('core flow', () => {
await add('SRV with the . target', R.nosrv, input(R.nosrv, { priority: '0', weight: '0', port: '0', target: '.' }));
await add('CAA issue', R.caa, input(R.caa, { flag: '0', tag: 'issue', value: 'ca.example.net' }));
await add('CAA iodef critical', R.iodef, input(R.iodef, { flag: '128', tag: 'iodef', value: 'mailto:security@example.net' }));
await add('TLSA DANE-EE SHA-256 pasted with colons and uppercase', R.tlsa, input(R.tlsa, { usage: '3', selector: '1', matching_type: '1', certificate: '01:23:45:67:89:AB:CD:EF:'.repeat(4).slice(0, -1) }));
await add('TLSA with zero usage and exact match', R.tlsafull, input(R.tlsafull, { usage: '0', selector: '1', matching_type: '0', certificate: String(R.tlsafull.data.certificate) }));
await add('NS of a delegated subdomain', R.sub, input(R.sub, { host: 'ns.example.net' }));
await add('wildcard A with TTL 0', R.wild, input(R.wild, { ip: '192.0.2.99' }));
await adminUi.expectRow({ name: '*', type: 'A', value: '192.0.2.99', ttl: 'default (360 s)' });
@@ -271,6 +275,9 @@ test.describe('core flow', () => {
R.srv = { ...R.srv, data: { ...R.srv.data, port: 5061 } };
await edit('edit CAA value', R.iodef, { ...R.iodef, data: { flag: 128, tag: 'iodef', value: 'mailto:dns@example.net' } }, input(R.iodef, { flag: '128', tag: 'iodef', value: 'mailto:dns@example.net' }));
R.iodef = { ...R.iodef, data: { flag: 128, tag: 'iodef', value: 'mailto:dns@example.net' } };
const sha512 = 'fedcba9876543210'.repeat(8);
await edit('edit TLSA to SHA-512', R.tlsa, { ...R.tlsa, data: { usage: 2, selector: 0, matching_type: 2, certificate: sha512 } }, input(R.tlsa, { usage: '2', selector: '0', matching_type: '2', certificate: sha512 }));
R.tlsa = { ...R.tlsa, data: { usage: 2, selector: 0, matching_type: 2, certificate: sha512 } };
await edit('edit NS host', R.sub, { ...R.sub, data: { host: 'ns2.example.net.' } }, input(R.sub, { host: 'ns2.example.net.' }));
R.sub = { ...R.sub, data: { host: 'ns2.example.net.' } };
await edit('edit wildcard address', R.wild, { ...R.wild, data: { ip: '192.0.2.98' } }, input(R.wild, { ip: '192.0.2.98' }));
@@ -287,6 +294,7 @@ test.describe('core flow', () => {
await del('delete long TXT', R.longtxt);
await del('delete SRV with the . target', R.nosrv);
await del('delete CAA', R.iodef);
await del('delete TLSA', R.tlsafull);
await del('delete NS of the subdomain', R.sub);
await del('delete wildcard TXT', R.wilddev);
await del('delete one A of an RRset', R.www2);
+1
View File
@@ -132,6 +132,7 @@ test('seeded requests cover every API operation, path parameter, filter and DNS
TXT: { text: 'random fixture' },
SRV: { priority: 0, weight: 0, port: 0, target: '.' },
CAA: { flag: 0, tag: 'issue', value: 'ca.example.net' },
TLSA: { usage: 3, selector: 1, matching_type: 1, certificate: '0123456789abcdef'.repeat(4) },
SOA: { ns: 'ns.example.net.', MBox: 'hostmaster.example.net.', refresh: 3600, retry: 600, expire: 604800, minttl: 300 },
};
for (const [type, data] of Object.entries(types)) {
+12 -1
View File
@@ -68,6 +68,13 @@ type caaData struct {
Value string `json:"value"`
}
type tlsaData struct {
Usage uint8 `json:"usage"`
Selector uint8 `json:"selector"`
MatchingType uint8 `json:"matching_type"`
Certificate string `json:"certificate"`
}
type soaData struct {
NS string `json:"ns"`
MBox string `json:"MBox"`
@@ -182,7 +189,7 @@ func fieldDescription(kind reflect.Kind) string {
func encodeRecord(data any) (string, error) {
switch data.(type) {
case aData, aaaaData, cnameData, nsData, mxData, txtData, srvData, caaData, soaData:
case aData, aaaaData, cnameData, nsData, mxData, txtData, srvData, caaData, tlsaData, soaData:
encoded, err := json.Marshal(data)
return string(encoded), err
default:
@@ -307,6 +314,10 @@ func buildRecordRR(row recordRow, data any, now time.Time) (dns.RR, error) {
if v.Tag != "" && v.Value != "" {
return &dns.CAA{Hdr: header, Flag: v.Flag, Tag: v.Tag, Value: v.Value}, nil
}
case tlsaData:
if v.Certificate != "" {
return &dns.TLSA{Hdr: header, Usage: v.Usage, Selector: v.Selector, MatchingType: v.MatchingType, Certificate: v.Certificate}, nil
}
case soaData:
if v.Serial == 0 {
v.Serial = uint32(now.Unix())
+18 -1
View File
@@ -47,6 +47,8 @@ func TestRecordCanonicalEncodingAndPluginRR(t *testing.T) {
{"SRV", "_https._tcp.dev", `{"port":443,"weight":0,"priority":65535,"target":"@"}`, `{"priority":65535,"weight":0,"port":443,"target":"example.org."}`, "65535 0 443 example.org."},
{"SRV", "_https._tcp", `{"port":0,"weight":65535,"priority":0,"target":"."}`, `{"priority":0,"weight":65535,"port":0,"target":"."}`, "0 65535 0 ."},
{"CAA", "", `{"value":"ca.example.net","tag":"issue","flag":0}`, `{"flag":0,"tag":"issue","value":"ca.example.net"}`, `0 issue "ca.example.net"`},
{"TLSA", "_25._tcp.mail", `{"certificate":"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF","matching_type":1,"selector":1,"usage":3}`, `{"usage":3,"selector":1,"matching_type":1,"certificate":"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"}`, "3 1 1 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"},
{"TLSA", "_443._tcp", `{"usage":255,"selector":255,"matching_type":255,"certificate":"00"}`, `{"usage":255,"selector":255,"matching_type":255,"certificate":"00"}`, "255 255 255 00"},
{"SOA", "@", `{"MBox":"First.Last@EXAMPLE.ORG","ns":"Ns.Example.Net","serial":4294967295,"minttl":0,"expire":2147483647,"retry":600,"refresh":3600}`,
`{"ns":"ns.example.net.","MBox":"first\\.last.example.org.","refresh":3600,"retry":600,"expire":2147483647,"minttl":0,"serial":4294967295}`,
`ns.example.net. first\.last.example.org. 4294967295 3600 600 2147483647 0`},
@@ -132,6 +134,21 @@ func TestRecordFieldValidation(t *testing.T) {
{"CAA", "x", `{"flag":0,"tag":"Issue","value":"ca.example"}`, "tag", 0},
{"CAA", "x", `{"flag":0,"tag":"a1234567890abcde","value":"ca.example"}`, "tag", 0},
{"CAA", "x", `{"flag":0,"tag":"issue","value":""}`, "value", 0},
{"TLSA", "_25._tcp", `{"usage":0,"selector":0,"matching_type":0,"certificate":"ab"}`, "", 0},
{"TLSA", "_25._tcp", `{"usage":3,"selector":1,"matching_type":1,"certificate":"` + strings.Repeat("ab", 32) + `"}`, "", 0},
{"TLSA", "_25._tcp", `{"usage":3,"selector":1,"matching_type":1,"certificate":"` + strings.Repeat("ab", 31) + `"}`, "certificate", 0},
{"TLSA", "_25._tcp", `{"usage":3,"selector":1,"matching_type":2,"certificate":"` + strings.Repeat("ab", 64) + `"}`, "", 0},
{"TLSA", "_25._tcp", `{"usage":3,"selector":1,"matching_type":2,"certificate":"` + strings.Repeat("ab", 32) + `"}`, "certificate", 0},
{"TLSA", "_25._tcp", `{"usage":3,"selector":1,"matching_type":0,"certificate":""}`, "certificate", 0},
{"TLSA", "_25._tcp", `{"usage":3,"selector":1,"matching_type":0,"certificate":"abc"}`, "certificate", 0},
{"TLSA", "_25._tcp", `{"usage":3,"selector":1,"matching_type":0,"certificate":"not-hex"}`, "certificate", 0},
{"TLSA", "_25._tcp", `{"usage":3,"selector":1,"matching_type":0,"certificate":"0x12"}`, "certificate", 0},
{"TLSA", "_25._tcp", `{"usage":3,"selector":1,"matching_type":0,"certificate":"` + strings.Repeat("ab", 65533) + `"}`, "certificate", 0},
{"TLSA", "_25._tcp", `{"usage":256,"selector":1,"matching_type":0,"certificate":"ab"}`, "usage", 0},
{"TLSA", "_25._tcp", `{"usage":3,"selector":-1,"matching_type":0,"certificate":"ab"}`, "selector", 0},
{"TLSA", "_25._tcp", `{"usage":3,"selector":1,"matching_type":"1","certificate":"ab"}`, "matching_type", 0},
{"TLSA", "_25._tcp", `{"selector":1,"matching_type":0,"certificate":"ab"}`, "usage", 0},
{"TLSA", "_25._tcp", `{"usage":3,"selector":1,"matching_type":0}`, "certificate", 0},
{"SOA", "child", `{"ns":"ns.example.","MBox":"hostmaster.example.","refresh":0,"retry":0,"expire":0,"minttl":0}`, "name", 0},
{"SOA", "@", `{"ns":"ns.example.","MBox":"hostmaster.example.","refresh":2147483648,"retry":0,"expire":0,"minttl":0}`, "refresh", 0},
{"SOA", "@", `{"ns":"ns.example.","MBox":"hostmaster.example.","refresh":0,"retry":0,"expire":0,"minttl":0,"serial":4294967296}`, "serial", 0},
@@ -190,7 +207,7 @@ func TestPluginRRLegacyRows(t *testing.T) {
if rr, err := recordRR(soa, modelNow); err != nil || rr.Header().Name != soa.Zone || rr.(*dns.SOA).Serial != uint32(modelNow.Unix()) {
t.Fatalf("raw populated SOA = %v, %v", rr, err)
}
for _, typ := range []string{"A", "AAAA", "CNAME", "NS", "MX", "TXT", "SRV", "CAA"} {
for _, typ := range []string{"A", "AAAA", "CNAME", "NS", "MX", "TXT", "SRV", "CAA", "TLSA"} {
row := modelRawRow(1, "child", typ, 0, `{}`)
if rr, err := recordRR(row, modelNow); rr != nil || err != nil || recordValue(row, modelNow) != "{}" {
t.Errorf("raw empty %s = %v, %v", typ, rr, err)
+16
View File
@@ -5,6 +5,7 @@ package main
import (
"cmp"
"encoding/hex"
"errors"
"net/netip"
"reflect"
@@ -31,6 +32,7 @@ var recordRules = map[string]recordTypeRule{
"TXT": {dns.TypeTXT, reflect.TypeFor[txtData]()},
"SRV": {dns.TypeSRV, reflect.TypeFor[srvData]()},
"CAA": {dns.TypeCAA, reflect.TypeFor[caaData]()},
"TLSA": {dns.TypeTLSA, reflect.TypeFor[tlsaData]()},
"SOA": {dns.TypeSOA, reflect.TypeFor[soaData]()},
}
@@ -120,6 +122,20 @@ func normalizeRecordData(zone string, data any) (any, map[string]string) {
fields["tag"] = "must contain 1 to 15 lowercase ASCII letters or digits"
}
text("value", v.Value, 1024)
case tlsaData:
v.Certificate = strings.ToLower(v.Certificate)
certificate, err := hex.DecodeString(v.Certificate)
switch {
case err != nil || len(certificate) == 0:
fields["certificate"] = "must be a non-empty even-length hexadecimal string"
case len(certificate) > 65535-3:
fields["certificate"] = "must be at most 65532 bytes"
case v.MatchingType == 1 && len(certificate) != 32:
fields["certificate"] = "must be a 32-byte SHA-256 digest for matching type 1"
case v.MatchingType == 2 && len(certificate) != 64:
fields["certificate"] = "must be a 64-byte SHA-512 digest for matching type 2"
}
data = v
case soaData:
v.NS = host("ns", v.NS, false)
mailbox, err := normalizeMailbox(v.MBox)
+9 -1
View File
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2026 Bryan Joshua Pedini
export const EDITABLE_TYPES = ["A", "AAAA", "CNAME", "NS", "MX", "TXT", "SRV", "CAA"];
export const EDITABLE_TYPES = ["A", "AAAA", "CNAME", "NS", "MX", "TXT", "SRV", "CAA", "TLSA"];
export const KNOWN_TYPES = [...EDITABLE_TYPES, "SOA"];
export const FIELD_SPECS = {
@@ -35,6 +35,12 @@ export const FIELD_SPECS = {
{ key: "tag", label: "Tag", placeholder: "issue" },
{ key: "value", label: "Value", placeholder: "ca.example.net" },
],
TLSA: [
{ key: "usage", label: "Certificate usage", options: [["0", "0 (PKIX-TA)"], ["1", "1 (PKIX-EE)"], ["2", "2 (DANE-TA)"], ["3", "3 (DANE-EE)"]] },
{ key: "selector", label: "Selector", options: [["0", "0 (full certificate)"], ["1", "1 (SubjectPublicKeyInfo)"]] },
{ key: "matching_type", label: "Matching type", options: [["0", "0 (exact match)"], ["1", "1 (SHA-256)"], ["2", "2 (SHA-512)"]] },
{ key: "certificate", label: "Certificate association data (hex)", multiline: true, hex: true, placeholder: "0123456789abcdef..." },
],
};
export function presentValue(record) {
@@ -55,6 +61,8 @@ export function presentValue(record) {
return data.priority + " " + data.weight + " " + data.port + " " + data.target;
case "CAA":
return data.flag + " " + data.tag + ' "' + data.value + '"';
case "TLSA":
return data.usage + " " + data.selector + " " + data.matching_type + " " + data.certificate;
case "SOA":
return [data.ns, data.MBox !== undefined ? data.MBox : data.mbox, data.serial == null || data.serial === 0 ? "dynamic (Unix time)" : data.serial, data.refresh, data.retry, data.expire, data.minttl].join(" ");
default:
+3 -2
View File
@@ -309,7 +309,8 @@ function buildTypeFields(type, values) {
let control;
const current = values[spec.key] === undefined || values[spec.key] === null ? "" : String(values[spec.key]);
if (spec.options) {
control = h("select", { id, name: spec.key }, spec.options.map(([value, label]) => option(value, label, value === current)));
const choices = current !== "" && !spec.options.some(([value]) => value === current) ? [...spec.options, [current, current]] : spec.options;
control = h("select", { id, name: spec.key }, choices.map(([value, label]) => option(value, label, value === current)));
} else if (spec.multiline) {
control = h("textarea", { id, name: spec.key, rows: 3, autocomplete: "off", spellcheck: "false", placeholder: spec.placeholder, value: current });
} else {
@@ -376,7 +377,7 @@ function recordBody(form) {
const data = {};
for (const spec of FIELD_SPECS[type] || []) {
const value = form.elements[spec.key].value;
data[spec.key] = spec.numeric || spec.options ? parseNumber(value) : spec.multiline || (type === "CAA" && spec.key === "value") ? value : value.trim();
data[spec.key] = spec.numeric || spec.options ? parseNumber(value) : spec.hex ? value.replace(/[\s:]/g, "").toLowerCase() : spec.multiline || (type === "CAA" && spec.key === "value") ? value : value.trim();
}
return { name: form.elements.name.value.trim(), type, ttl: parseNumber(form.elements.ttl.value), data };
}
+1 -1
View File
@@ -18,7 +18,7 @@ function problemCell(zone) {
}
const counts = state.counts.get(zone.name) || { error: 0, warning: 0 };
if (counts.error === 0 && counts.warning === 0) {
cell.append(h("span", { class: "badge badge-ok", text: "none" }));
cell.append(h("span", { class: "badge badge-ok", text: "OK" }));
return cell;
}
if (counts.error > 0) cell.append(h("span", { class: "badge badge-error", text: plural(counts.error, "error", "errors") }), " ");
+1 -1
View File
@@ -15,7 +15,7 @@
<div class="table-wrap">
<table class="table" id="zones-table">
<thead>
<tr><th scope="col">Zone</th><th scope="col" class="num">Records</th><th scope="col">SOA serial</th><th scope="col">Problems</th></tr>
<tr><th scope="col">Zone</th><th scope="col" class="num">Records</th><th scope="col">SOA serial</th><th scope="col">Status</th></tr>
</thead>
<tbody id="zones-body"></tbody>
</table>
+2
View File
@@ -273,6 +273,8 @@ func zoneFileRecordData(rr dns.RR) (any, error) {
case *dns.CAA:
value, err := unescapeZoneText(v.Value)
return caaData{v.Flag, v.Tag, value}, err
case *dns.TLSA:
return tlsaData{v.Usage, v.Selector, v.MatchingType, strings.ToLower(v.Certificate)}, nil
case *dns.SOA:
return soaData{v.Ns, v.Mbox, v.Refresh, v.Retry, v.Expire, v.Minttl, 0}, nil
default:
+33
View File
@@ -309,3 +309,36 @@ func TestZoneFingerprint(t *testing.T) {
t.Fatal("raw JSON change did not change fingerprint")
}
}
func TestZoneFileTLSA(t *testing.T) {
parsed := modelParseZone(t, `$ORIGIN example.org.
@ IN SOA ns.example.net. hostmaster.example.org. 1 3600 600 604800 300
_25._tcp.mail 300 IN TLSA 3 1 1 0123456789ABCDEF0123456789ABCDEF 0123456789ABCDEF0123456789ABCDEF
_443._tcp IN TLSA ( 0 1 0
302a300506032b6570032100d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a )
`)
if len(parsed.Rows) != 3 || len(parsed.Skipped) != 0 ||
parsed.Rows[1].Name != "_25._tcp.mail" || parsed.Rows[1].RecordType != "TLSA" ||
parsed.Rows[1].Content.String != `{"usage":3,"selector":1,"matching_type":1,"certificate":"`+strings.Repeat("0123456789abcdef", 4)+`"}` ||
parsed.Rows[2].Content.String != `{"usage":0,"selector":1,"matching_type":0,"certificate":"302a300506032b6570032100d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a"}` {
t.Fatalf("unexpected parsed TLSA: %+v", parsed)
}
rows := parsed.Rows
for i := range rows {
rows[i].ID = int64(i + 1)
}
file, err := exportZoneFile("example.org.", rows, modelNow)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(file, "TLSA\t3 1 1 "+strings.Repeat("0123456789abcdef", 4)) && !strings.Contains(file, "TLSA 3 1 1 "+strings.Repeat("0123456789abcdef", 4)) {
t.Fatalf("export lacks the TLSA record:\n%s", file)
}
diff, err := diffZoneImport("example.org.", rows, modelParseZone(t, file), "replace", modelNow)
if err != nil || !diff.Changes.empty() || len(diff.Problems) != 0 || len(diff.Unchanged) != len(rows) {
t.Fatalf("TLSA round trip = %+v, %v\n%s", diff, err, file)
}
if _, err := parseZoneFile("example.org.", strings.NewReader("_25._tcp IN TLSA 3 1 1 abcd\n"), modelNow); err == nil {
t.Fatal("accepted a SHA-256 TLSA with a short digest")
}
}