Karta.DNS.Provider behaviour (Karta v1.0.0)

The DNS server Karta publishes its records through, behind one interface, so that another server or service can take PowerDNS's place.

A provider is a module that implements this behaviour and is compiled into the release; Karta loads no provider code at run time. The one in use is named by KARTA_DNS_PROVIDER (powerdns, the default, or rfc2136; a module name selects a provider added to the build, see the guide on writing a provider). A provider reads its own settings from the environment in config/0; nil means Karta publishes nothing.

The three calls are a dry run and a write:

  • list_zones/1 - the zones the server holds, each with an id (as the provider uses it in its own calls), its name (absolute, lower case, with the final dot) and its kind;
  • read_zone/3 - a zone's records at the names Karta may write and the records of Karta's own, which the provider recognises by the owner tag Karta writes with them (a PowerDNS comment, an entry in the inventory record of the RFC 2136 provider). names is a hint: a provider that can read the whole zone at once ignores it;
  • apply/3 - one change set to a zone: the RRsets to replace (with their owner tag) and the RRsets to delete. It returns warnings for what could not be finished after the records were written (a failed NOTIFY, say) and an error text for a change that was not written at all.

Records are in zone-file presentation form: absolute names in lower case with the final dot, TXT contents as quoted strings of at most 255 octets, other names absolute. Karta publishes only TXT and CNAME records; a provider need not accept other types.

What a provider must not do. It writes in the zones the operator allows (allowed_zone?/2, covered?/2) and only the RRsets Karta owns: read_zone/3 never reports an RRset as Karta's unless it holds the owner tag, and apply/3 deletes only the RRsets in its change set. Credentials come from the environment, are never logged, and are left out of errors and inspect output.

Karta.PowerDNS is the default implementation; Karta.RFC2136 speaks dynamic update (RFC 2136) with TSIG to BIND, Knot, PowerDNS and other authoritative servers.

Summary

Types

A provider's configuration; nil when Karta publishes nothing.

A zone as list_zones/1 shows it.

Callbacks

Writes a change set: {:ok, warnings} or {:error, text}.

The configuration in use, or nil when publishing is off.

The zones the server holds, each with its id, name and kind.

The provider's name, for people ("PowerDNS").

A zone with the RRsets at names and Karta's own (Karta.DNS.Zone).

Functions

True when zone (with or without the final dot) is on the configuration's allowlist.

The selected provider's configuration, or nil when it publishes nothing.

True when name is one of the allowed zones or under one: the only names Karta may publish.

The selected provider's name.

Makes a list of zone names ready to compare with: lower case, without the final dot, in ASCII form (names that are not domain names are left out; labels may begin with an underscore, as in _domainkey.example.com).

The selected provider module (KARTA_DNS_PROVIDER, PowerDNS by default).

Types

config()

@type config() :: struct() | nil

A provider's configuration; nil when Karta publishes nothing.

zone_summary()

@type zone_summary() :: %{id: String.t(), name: String.t(), kind: String.t() | nil}

A zone as list_zones/1 shows it.

Callbacks

apply(config, t, list)

@callback apply(config(), Karta.DNS.Zone.t(), [Karta.DNS.Change.t()]) ::
  {:ok, [String.t()]} | {:error, String.t()}

Writes a change set: {:ok, warnings} or {:error, text}.

config()

@callback config() :: config()

The configuration in use, or nil when publishing is off.

list_zones(config)

@callback list_zones(config()) :: {:ok, [zone_summary()]} | {:error, String.t()}

The zones the server holds, each with its id, name and kind.

name()

@callback name() :: String.t()

The provider's name, for people ("PowerDNS").

read_zone(config, zone_id, names)

@callback read_zone(config(), zone_id :: String.t(), names :: [String.t()]) ::
  {:ok, Karta.DNS.Zone.t()} | {:error, String.t()}

A zone with the RRsets at names and Karta's own (Karta.DNS.Zone).

Functions

allowed_zone?(zone, arg2)

@spec allowed_zone?(String.t(), config()) :: boolean()

True when zone (with or without the final dot) is on the configuration's allowlist.

config(provider \\ provider())

@spec config(module()) :: config()

The selected provider's configuration, or nil when it publishes nothing.

covered?(name, arg2)

@spec covered?(String.t(), config()) :: boolean()

True when name is one of the allowed zones or under one: the only names Karta may publish.

name(provider \\ provider())

@spec name(module()) :: String.t()

The selected provider's name.

normalize_zones(zones)

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

Makes a list of zone names ready to compare with: lower case, without the final dot, in ASCII form (names that are not domain names are left out; labels may begin with an underscore, as in _domainkey.example.com).

provider()

@spec provider() :: module()

The selected provider module (KARTA_DNS_PROVIDER, PowerDNS by default).