SaltDns.Knot.Protocol (Salt v1.0.0)

Pure helpers for talking to Knot 3.6 through knotc: validating names, building argument lists, parsing output and classifying errors.

Output formats and error texts were checked against Knot DNS 3.6.2 (see the control-socket note in the project's planning documents).

Summary

Functions

Builds the knotc arguments for one change in zone.

Classifies a failed knotc call by its Knot 3.6 error text.

True for a record type that Knot manages in a signed zone.

The record types Knot creates and owns in a signed zone. They are never part of the desired data in Postgres; SaltDns.Knot.read_zone/1 returns them for a signed zone, and callers comparing zone contents must drop them.

Appends the root dot, tolerating a name that already has one.

True if the zone has an SOA among the records returned by parse_zone_read/1.

Future key timers as events %{event, key_tag, in_seconds}, soonest first.

Parses CDNSKEY rdata 257 3 13 <base64>.

Parses knotc conf-read zone[<zone>].dnssec-signing / .dnssec-policy output (zone[x.].dnssec-policy salt-nsec3) to the value. Empty output means the item is not set.

Parses CDS rdata 15350 13 2 F51A... (digest lower-cased).

Parses keymgr -j <zone> list (a JSON array) into key maps

Pending zone events from knotc -e zone-status (re-sign: +12D12h23m42s), as %{event, key_tag: nil, in_seconds}. Events shown as - are not pending.

Parses knotc zone-read output into :add changes.

Parses knotc zone-status <zone> output, e.g. [example.com.] role: master | serial: 1794337202 | catalog: @cat.invalid.

The SOA rdata for ensure_zone/2, with a serial.

Validates a record owner name (a leading * label is allowed).

Validates a zone name: absolute, lower-case, no trailing dot, no wildcard.

Functions

change_args(zone, change)

@spec change_args(String.t(), SaltDns.Zones.Change.t()) ::
  {:ok, [String.t()]} | {:error, term()}

Builds the knotc arguments for one change in zone.

Adding is zone-set <zone> <owner> <ttl> <type> <rdata>; removing is zone-unset <zone> <owner> <type> <rdata>. The rdata is one argument.

classify_error(arg1)

@spec classify_error(term()) ::
  :no_such_zone
  | :transaction_in_progress
  | :no_transaction
  | :exists
  | :absent
  | :no_node
  | :no_ksk_ready
  | :duplicate_identifier
  | :invalid_identifier
  | :other

Classifies a failed knotc call by its Knot 3.6 error text.

:exists and :absent are the two idempotent outcomes of zone-set and zone-unset.

dnssec_type?(type)

@spec dnssec_type?(String.t()) :: boolean()

True for a record type that Knot manages in a signed zone.

dnssec_types()

@spec dnssec_types() :: [String.t()]

The record types Knot creates and owns in a signed zone. They are never part of the desired data in Postgres; SaltDns.Knot.read_zone/1 returns them for a signed zone, and callers comparing zone contents must drop them.

fqdn(name)

@spec fqdn(String.t()) :: String.t()

Appends the root dot, tolerating a name that already has one.

has_soa?(records)

@spec has_soa?([SaltDns.Zones.Change.t()]) :: boolean()

True if the zone has an SOA among the records returned by parse_zone_read/1.

key_events(keys, now)

@spec key_events([map()], integer()) :: [map()]

Future key timers as events %{event, key_tag, in_seconds}, soonest first.

parse_cdnskey(rdata)

@spec parse_cdnskey(String.t()) :: {:ok, map()} | :error

Parses CDNSKEY rdata 257 3 13 <base64>.

parse_conf_value(output)

@spec parse_conf_value(String.t()) :: String.t() | nil

Parses knotc conf-read zone[<zone>].dnssec-signing / .dnssec-policy output (zone[x.].dnssec-policy salt-nsec3) to the value. Empty output means the item is not set.

parse_ds(rdata)

@spec parse_ds(String.t()) :: {:ok, map()} | :error

Parses CDS rdata 15350 13 2 F51A... (digest lower-cased).

parse_keys(json, now)

@spec parse_keys(String.t(), integer()) ::
  {:ok, [map()]} | {:error, {:unparseable, String.t()}}

Parses keymgr -j <zone> list (a JSON array) into key maps:

%{id, tag, role: :ksk | :zsk | :csk, algorithm, state, timers: %{...}}

state is derived from the timers at now (unix seconds): :created, :pre_active, :published, :ready (a KSK waiting for its DS to be confirmed, see zone-ksk-submitted), :active, :retiring, :retired, :removed. timers maps the timer names (atoms) to unix seconds, absent when unset (0 in keymgr).

parse_zone_events(output)

@spec parse_zone_events(String.t()) :: [map()]

Pending zone events from knotc -e zone-status (re-sign: +12D12h23m42s), as %{event, key_tag: nil, in_seconds}. Events shown as - are not pending.

parse_zone_read(output)

@spec parse_zone_read(String.t()) ::
  {:ok, [SaltDns.Zones.Change.t()]} | {:error, {:unparseable, String.t()}}

Parses knotc zone-read output into :add changes.

Each line is <owner> <ttl> <type> <rdata>; owners are absolute with a trailing dot (stripped here).

parse_zone_status(output)

@spec parse_zone_status(String.t()) ::
  {:ok, SaltDns.Knot.zone_status()} | {:error, {:unparseable, String.t()}}

Parses knotc zone-status <zone> output, e.g. [example.com.] role: master | serial: 1794337202 | catalog: @cat.invalid.

soa_rdata(soa, serial)

@spec soa_rdata(SaltDns.Knot.soa(), non_neg_integer()) :: String.t()

The SOA rdata for ensure_zone/2, with a serial.

valid_owner?(name)

@spec valid_owner?(term()) :: boolean()

Validates a record owner name (a leading * label is allowed).

validate_zone(name)

@spec validate_zone(term()) :: {:ok, String.t()} | {:error, {:invalid_zone, term()}}

Validates a zone name: absolute, lower-case, no trailing dot, no wildcard.