SaltDns. Presets
(Salt v1.0.0)
Ready-made record sets that connect a domain to a service: a Balie site, a Tienda shop, Kantoor mail, Google Workspace or Microsoft 365.
A preset is a list of parts (:site, :mx, :spf, :dmarc, :discovery,
:autodiscover). A part becomes the records of one or more rrsets, written
into the zone through SaltDns.Import in merge mode
(plan/4 → SaltDns.Import.plan/4 → apply/5). It never makes the zone
equal to the preset: records the preset does not name are left alone, and
the preview shows exactly what adding the preset would change.
The rules follow the customer manual (shiloh/docs, "DNS records for your
own domain"):
- an existing SPF record is merged into, not replaced: our mechanisms
are added once, the sender's existing mechanisms and
allqualifier stay; - an existing DMARC record is never weakened: the preset writes one only when there is none;
- existing MX records are replaced (a domain has one set of mail servers), and an existing record set's TTL is kept;
- everything else (a missing DMARC record, the discovery records, the site addresses) is added.
The addresses and host names come from configuration, so an installation names its own platform:
config :salt_dns, SaltDns.Presets,
balie: %{ipv4: ["192.0.2.10"], ipv6: ["2001:db8::10"]},
tienda: nil,
mail: %{
mx: "mx.mail.example",
spf: ["include:spf.example"],
kantoor: "kantoor.example",
dmarc_rua: nil
}A preset without its configuration is listed as unavailable, with the reason, and writes nothing.
Summary
Functions
Writes a preset in one audited batch (audit source preset). The plan is
made at the moment of applying, so the review on screen never hides a
change made in between. Nothing is written when the parts change nothing.
Writes a DKIM record in one audited batch (source preset), planned now.
Writes the TLS reporting record in one audited batch (source preset).
The presets with their parts, whether the installation can offer them and, when it cannot, why.
The catalogue for a given configuration (tests inject one).
The configured platform targets, as a map.
The record that publishes a DKIM key or delegation: one rrset at
<selector>._domainkey.<zone>, with the value the mail provider gave.
The rrsets a DKIM record would write, without a database (the page and its
tests use this): {:ok, [rrset]} or {:error, reason} with
:invalid_selector, :empty_dkim, :dkim_without_key, :invalid_dkim_target
or :invalid_dkim_type.
One preset of the catalogue, or nil.
The mail configuration, or nil when the installation has none.
Merges mechanisms into an existing SPF record.
The parts of a preset that can be applied, as %{id, label} maps, or [].
Builds and plans a preset (or some of its parts) against the zone as it is
now. parts defaults to every part of the preset.
Plans a preset against a zone's current rrsets, without a database (the
page tests use this). Options: :config, and the TTL bounds :ttl_min,
:ttl_max, :default_ttl of SaltDns.Import.plan/4.
The records a preset would write for these parts, as rrsets, without a zone
(for the page's summary). state is the zone's current rrsets in the shape
SaltDns.Import.current_state/1 returns.
The TLS reporting record: _smtp._tls.<zone> with v=TLSRPTv1; rua=mailto:<address>.
The TLS reporting rrset, without a database: {:ok, [rrset]} or
{:error, :empty_address | :invalid_address}.
Types
@type part_id() :: :site | :mx | :spf | :dmarc | :discovery | :autodiscover
@type preset_id() ::
:balie_site
| :tienda_shop
| :kantoor_mail
| :google_workspace
| :microsoft_365
@type rrset() :: %{ name: String.t(), type: String.t(), ttl: pos_integer(), records: [String.t()] }
Functions
@spec apply( SaltDns.Zones.Zone.t(), atom(), [atom()], SaltDns.Zones.Actor.t(), keyword() ) :: {:ok, [SaltDns.Zones.Change.t()]} | {:error, term()}
Writes a preset in one audited batch (audit source preset). The plan is
made at the moment of applying, so the review on screen never hides a
change made in between. Nothing is written when the parts change nothing.
{:error, {:conflicts, conflicts}} when the zone's own records block the
preset (a CNAME where the preset writes other data); the conflicts are the
report's, and nothing is written.
@spec apply_dkim( SaltDns.Zones.Zone.t(), String.t(), String.t(), SaltDns.Zones.Actor.t(), keyword() ) :: {:ok, [SaltDns.Zones.Change.t()]} | {:error, term()}
Writes a DKIM record in one audited batch (source preset), planned now.
@spec apply_tls_rpt( SaltDns.Zones.Zone.t(), String.t(), SaltDns.Zones.Actor.t(), keyword() ) :: {:ok, [SaltDns.Zones.Change.t()]} | {:error, term()}
Writes the TLS reporting record in one audited batch (source preset).
@spec catalogue() :: [map()]
The presets with their parts, whether the installation can offer them and, when it cannot, why.
The catalogue for a given configuration (tests inject one).
@spec config() :: map()
The configured platform targets, as a map.
@spec dkim(SaltDns.Zones.Zone.t(), String.t(), String.t(), keyword()) :: {:ok, %{report: SaltDns.Import.Report.t(), records: [tuple()], rrsets: [rrset()]}} | {:error, term()}
The record that publishes a DKIM key or delegation: one rrset at
<selector>._domainkey.<zone>, with the value the mail provider gave.
Options: :type, "TXT" (default; value must hold p= and, when present,
start with v=DKIM1) or "CNAME" (Microsoft 365's selectors are CNAMEs to
the tenant's onmicrosoft.com name). The key or name is the provider's,
never one Salt invents.
@spec dkim_rrsets(String.t(), String.t(), String.t(), [map()], keyword()) :: {:ok, [rrset()]} | {:error, atom()}
The rrsets a DKIM record would write, without a database (the page and its
tests use this): {:ok, [rrset]} or {:error, reason} with
:invalid_selector, :empty_dkim, :dkim_without_key, :invalid_dkim_target
or :invalid_dkim_type.
One preset of the catalogue, or nil.
@spec mail_config() :: map() | nil
The mail configuration, or nil when the installation has none.
Merges mechanisms into an existing SPF record.
The record's own mechanisms stay in order and its all qualifier is kept
(or ~all is added when there is none); a mechanism the record already
has (case-insensitively) is not added twice. redirect= and exp= stay at
the end. This never removes or changes a sender's own mechanism.
The parts of a preset that can be applied, as %{id, label} maps, or [].
@spec plan(SaltDns.Zones.Zone.t(), atom(), [atom()], keyword()) :: {:ok, %{report: SaltDns.Import.Report.t(), records: [tuple()], rrsets: [rrset()]}} | {:error, term()}
Builds and plans a preset (or some of its parts) against the zone as it is
now. parts defaults to every part of the preset.
Returns {:ok, %{report: report, records: records, rrsets: rrsets}} for the
review screen (the report is SaltDns.Import's dry run in merge mode), or
{:error, reason}:
{:unavailable, reason}— the installation has no target for it;{:unknown_part, part}— a part the preset does not have;{:spf_conflict, count}— the zone has more than one SPF record, so merging would have to guess which one is meant;{:invalid_records, reason}— a value from configuration did not parse.
@spec plan_state(String.t(), [map()], atom(), [atom()] | nil, keyword()) :: {:ok, %{report: SaltDns.Import.Report.t(), records: [tuple()], rrsets: [rrset()]}} | {:error, term()}
Plans a preset against a zone's current rrsets, without a database (the
page tests use this). Options: :config, and the TTL bounds :ttl_min,
:ttl_max, :default_ttl of SaltDns.Import.plan/4.
The records a preset would write for these parts, as rrsets, without a zone
(for the page's summary). state is the zone's current rrsets in the shape
SaltDns.Import.current_state/1 returns.
@spec tls_rpt(SaltDns.Zones.Zone.t(), String.t(), keyword()) :: {:ok, %{report: SaltDns.Import.Report.t(), records: [tuple()], rrsets: [rrset()]}} | {:error, term()}
The TLS reporting record: _smtp._tls.<zone> with v=TLSRPTv1; rua=mailto:<address>.
@spec tls_rpt_rrsets(String.t(), String.t(), [map()], keyword()) :: {:ok, [rrset()]} | {:error, atom()}
The TLS reporting rrset, without a database: {:ok, [rrset]} or
{:error, :empty_address | :invalid_address}.