SaltDns. Knot behaviour
(Salt v1.0.0)
The bridge between Salt DNS and the hidden Knot primary.
Postgres is the system of record; this behaviour is how its state reaches Knot. Implementations:
SaltDns.Knot.Knotc- the real adapter, drivingknotcSaltDns.Knot.Fake- an in-memory stand-in for unit tests
The adapter in use is Application.get_env(:salt_dns, :knot_adapter),
default SaltDns.Knot.Knotc.
Zone names are absolute, lower-case, without a trailing dot. All functions are idempotent: ensuring an existing zone, removing an absent one, adding a record that exists or removing one that does not all succeed.
Errors are tagged tuples. The ones callers should expect:
{:error, :no_such_zone}{:error, :transaction_in_progress}(a zone or configuration transaction is open that this call did not open){:error, {:invalid_zone, name}},{:error, {:invalid_change, change}}{:error, {:change_failed, change, reason}}(the whole batch was rolled back){:error, :no_ksk_ready}(ksk_submitted/1, nothing to confirm){:error, {:knotc, exit_status, output}},{:error, {:timeout, ms}},{:error, {:executable_not_found, binary}}
Summary
Types
One key from Knot's key store. state is :created | :pre_active | :published | :ready | :active | :retiring | :retired | :removed; a KSK in
:ready is waiting for its DS to be confirmed (ksk_submitted/1).
timers holds the key's timer names as atoms mapped to unix seconds.
DNSSEC mode of a zone: unsigned, or signed with NSEC or NSEC3 denial of existence.
One public edge as Knot's configuration knows it: the id of the remote,
its addresses without port (IPv4 and IPv6 literals) and the port.
SOA values for a new zone. Names have no trailing dot.
What ensure_zone/2 needs: the SOA, the apex NS target names (no trailing
dot), and the name of the catalog member template (default "member").
Apex records are only seeded when the zone is empty.
Callbacks
Aborts the zone's open transaction, if any (idempotent). For the zone's single writer to clear a transaction a crashed predecessor left open.
Applies the changes, in order, in one zone transaction (zone-begin,
zone-set/zone-unset, zone-commit). On any error the transaction is
aborted and nothing is applied. The SOA serial rises on every commit.
Whether the zone is signed, its mode, keys with their states, and pending events.
The DS (SHA-256), CDS and CDNSKEY that Knot publishes in the zone for the registrar. Empty lists while the zone is unsigned.
The edges this primary notifies: the remote sections that belong to the
notify groups (SALT_DNS_KNOT_BASE_NOTIFY, default knot-edge), read from
the configuration database. Read only; placeholder addresses are left out.
Makes sure the zone is configured on the primary (one configuration transaction) and has an SOA and apex NS records. Does nothing to a zone that already has data.
Makes this node's Knot a secondary of its peer for exactly zones
(customer zones, the organisations' catalogs and the edge catalog): every
listed zone gets the follower template (master: the peer) and loses any
signing, ACL and NOTIFY settings of its own; zones not listed are removed
(except :keep). Zones that were primaries here are retransferred, so
divergent data of a former leader is replaced. One configuration transaction.
Runs even when this node is not the leader: it is the demotion step.
Confirms that the parent now has the DS for a KSK in the :ready state
(knotc zone-ksk-submitted). Returns {:error, :no_ksk_ready} when no key
is waiting.
The zones this Knot has loaded (a serial), as lower-case names without the final dot.
Points this Knot's peer remote (the primary a secondary transfers from) at
address (SaltDns.Knot.PeerAddress, validated again here). One
configuration transaction, none when the address is already the only one.
Reads the committed zone: every record, as :add changes.
Asks this Knot (a secondary) to check its primary for these zones now
(knotc zone-refresh) instead of at its next poll. Only a speed-up; the poll
makes it correct anyway.
Removes the zone from the primary's configuration and deletes its stored data.
As remove_zone/1; with keys: true the zone's DNSSEC keys are purged too
(for a deleted zone, not a disabled one).
Switches DNSSEC signing for the zone: :off, or {:on, :nsec | :nsec3}
(one configuration transaction; Knot generates keys and signs on its own).
Switching on returns once DNSKEY is published. Switching on again with a
different mode changes the denial of existence and re-signs. Switching off
also removes the DNSSEC records (SaltDns.Knot.Protocol.dnssec_types/0)
from the zone; do that only after the DS is gone from the parent
(SaltDns.Dnssec.Lifecycle).
How many zones this Knot has configured to sign.
Status of the zone: role and current serial.
Makes Knot's distribution configuration for one organisation match spec
(SaltDns.Knot.OrgConfig): its catalog zone and member template, and a
transfer key, remote and ACL per secondary. One configuration transaction
if anything differs, none otherwise. Stale secondaries of the organisation
are removed.
The template the zone is configured with ({:ok, nil} when the zone is not
configured). The template names the organisation that owns the zone in Knot.
Types
@type cdnskey() :: %{ flags: non_neg_integer(), protocol: non_neg_integer(), algorithm: non_neg_integer(), public_key: String.t() }
@type dnssec_event() :: %{ event: String.t(), key_tag: non_neg_integer() | nil, in_seconds: non_neg_integer() }
@type dnssec_key() :: %{ id: String.t(), tag: non_neg_integer(), role: :ksk | :zsk | :csk, algorithm: non_neg_integer(), state: atom(), timers: %{optional(atom()) => non_neg_integer()} }
One key from Knot's key store. state is :created | :pre_active | :published | :ready | :active | :retiring | :retired | :removed; a KSK in
:ready is waiting for its DS to be confirmed (ksk_submitted/1).
timers holds the key's timer names as atoms mapped to unix seconds.
@type dnssec_mode() :: :off | {:on, :nsec | :nsec3}
DNSSEC mode of a zone: unsigned, or signed with NSEC or NSEC3 denial of existence.
@type dnssec_status() :: %{ signed: boolean(), mode: :nsec | :nsec3 | nil, policy: String.t() | nil, dnskey_published: boolean(), keys: [dnssec_key()], next_events: [dnssec_event()] }
@type ds() :: %{ key_tag: non_neg_integer(), algorithm: non_neg_integer(), digest_type: non_neg_integer(), digest: String.t() }
@type edge() :: %{id: String.t(), addresses: [String.t()], port: non_neg_integer()}
One public edge as Knot's configuration knows it: the id of the remote,
its addresses without port (IPv4 and IPv6 literals) and the port.
@type error() :: {:error, term()}
@type soa() :: %{ :mname => String.t(), :rname => String.t(), :refresh => non_neg_integer(), :retry => non_neg_integer(), :expire => non_neg_integer(), :minimum => non_neg_integer(), optional(:ttl) => pos_integer() }
SOA values for a new zone. Names have no trailing dot.
@type zone_opts() :: %{ :soa => soa(), :ns => [String.t(), ...], optional(:template) => String.t(), optional(:ns_ttl) => pos_integer() }
What ensure_zone/2 needs: the SOA, the apex NS target names (no trailing
dot), and the name of the catalog member template (default "member").
Apex records are only seeded when the zone is empty.
@type zone_status() :: %{ role: String.t(), serial: non_neg_integer() | nil, raw: String.t() }
Callbacks
Aborts the zone's open transaction, if any (idempotent). For the zone's single writer to clear a transaction a crashed predecessor left open.
@callback apply_changes(zone :: String.t(), [SaltDns.Zones.Change.t()]) :: :ok | error()
Applies the changes, in order, in one zone transaction (zone-begin,
zone-set/zone-unset, zone-commit). On any error the transaction is
aborted and nothing is applied. The SOA serial rises on every commit.
@callback dnssec_status(zone :: String.t()) :: {:ok, dnssec_status()} | error()
Whether the zone is signed, its mode, keys with their states, and pending events.
The DS (SHA-256), CDS and CDNSKEY that Knot publishes in the zone for the registrar. Empty lists while the zone is unsigned.
The edges this primary notifies: the remote sections that belong to the
notify groups (SALT_DNS_KNOT_BASE_NOTIFY, default knot-edge), read from
the configuration database. Read only; placeholder addresses are left out.
Makes sure the zone is configured on the primary (one configuration transaction) and has an SOA and apex NS records. Does nothing to a zone that already has data.
@callback follow(zones :: [String.t()] | :current, opts :: keyword()) :: {:ok, %{changed: non_neg_integer(), removed: non_neg_integer()}} | error()
Makes this node's Knot a secondary of its peer for exactly zones
(customer zones, the organisations' catalogs and the edge catalog): every
listed zone gets the follower template (master: the peer) and loses any
signing, ACL and NOTIFY settings of its own; zones not listed are removed
(except :keep). Zones that were primaries here are retransferred, so
divergent data of a former leader is replaced. One configuration transaction.
Runs even when this node is not the leader: it is the demotion step.
Confirms that the parent now has the DS for a KSK in the :ready state
(knotc zone-ksk-submitted). Returns {:error, :no_ksk_ready} when no key
is waiting.
The zones this Knot has loaded (a serial), as lower-case names without the final dot.
Points this Knot's peer remote (the primary a secondary transfers from) at
address (SaltDns.Knot.PeerAddress, validated again here). One
configuration transaction, none when the address is already the only one.
@callback read_zone(zone :: String.t()) :: {:ok, [zone_record()]} | error()
Reads the committed zone: every record, as :add changes.
Asks this Knot (a secondary) to check its primary for these zones now
(knotc zone-refresh) instead of at its next poll. Only a speed-up; the poll
makes it correct anyway.
Removes the zone from the primary's configuration and deletes its stored data.
As remove_zone/1; with keys: true the zone's DNSSEC keys are purged too
(for a deleted zone, not a disabled one).
@callback set_dnssec(zone :: String.t(), dnssec_mode()) :: :ok | error()
Switches DNSSEC signing for the zone: :off, or {:on, :nsec | :nsec3}
(one configuration transaction; Knot generates keys and signs on its own).
Switching on returns once DNSKEY is published. Switching on again with a
different mode changes the denial of existence and re-signs. Switching off
also removes the DNSSEC records (SaltDns.Knot.Protocol.dnssec_types/0)
from the zone; do that only after the DS is gone from the parent
(SaltDns.Dnssec.Lifecycle).
@callback signing_zones() :: {:ok, non_neg_integer()} | error()
How many zones this Knot has configured to sign.
@callback status(zone :: String.t()) :: {:ok, zone_status()} | error()
Status of the zone: role and current serial.
@callback sync_organisation(SaltDns.Knot.OrgConfig.spec()) :: :ok | error()
Makes Knot's distribution configuration for one organisation match spec
(SaltDns.Knot.OrgConfig): its catalog zone and member template, and a
transfer key, remote and ACL per secondary. One configuration transaction
if anything differs, none otherwise. Stale secondaries of the organisation
are removed.
The template the zone is configured with ({:ok, nil} when the zone is not
configured). The template names the organisation that owns the zone in Knot.
Functions
See abort_zone/1.
@spec apply_changes(String.t(), [SaltDns.Zones.Change.t()]) :: :ok | error()
See apply_changes/2.
@spec dnssec_status(String.t()) :: {:ok, dnssec_status()} | error()
See dnssec_status/1.
See ds_records/1.
See edges/0.
See ensure_zone/2.
See follow/2.
See ksk_submitted/1.
See loaded_zones/0.
See point_peer/1.
@spec read_zone(String.t()) :: {:ok, [zone_record()]} | error()
See read_zone/1.
See refresh_zones/1.
See remove_zone/1.
@spec set_dnssec(String.t(), dnssec_mode()) :: :ok | error()
See set_dnssec/2.
@spec signing_zones() :: {:ok, non_neg_integer()} | error()
See signing_zones/0.
@spec status(String.t()) :: {:ok, zone_status()} | error()
See status/1.
@spec sync_organisation(SaltDns.Knot.OrgConfig.spec()) :: :ok | error()
See sync_organisation/1.
See zone_template/1.