SaltDns. Certificates
(Salt v1.0.0)
The optional certificate module: Salt DNS as an ACME client that obtains
certificates for a zone (the zone and *.zone, the default) or for one host
at any depth inside a zone of the organisation, with or without the wildcard
below it (custom certificates). It answers the DNS-01
challenge in its own zones, watches and renews the certificates and keeps
them, encrypted with a key of its own, in S3-compatible storage. Off unless
SALT_DNS_CERTIFICATES=on; an installation without it is unchanged. See
docs/certificates.md.
For the delivery stage
current_bundle/1- names, serial, validity, chain PEM and key PEM of a certificate's current version (the key is decrypted from the store);subscribe/0- PubSub topic"certificates:current"; a message{:certificate_current_version, info}is broadcast whenever a certificate gets a new current version (infohas:certificate_id,:version_id,:serial,:zone_name,:names,:not_after,:organisation_id; it carries no key).
Structure
SaltDns.Certificates.Runner is the order state machine (run by
SaltDns.Certificates.Worker, an Oban job that is unique per certificate);
SaltDns.Certificates.Watcher is the light process that notices what is due.
The pure rules are in Names, Renewal, Caa and Capabilities.
Summary
Types
What plan_external/2 found out about a request for an external certificate.
What plan_custom/3 found out about a request for a custom certificate.
Functions
Changeset for the provider form.
Orders the certificate FOR a zone: the zone and *.zone, any other list is
refused (:not_wildcard_pair). Custom certificates (one host, with or
without the wildcard) are ordered with create_custom_certificate/2. The
zone must be verified (active). attrs: provider_ids (required, tried in
this order, each visible to the zone's organisation and registered),
profile, publish_caa (default true), names (optional; checked).
Orders a custom certificate: attrs has host, wildcard (boolean; default
false), provider_ids, optional profile and publish_caa. The certificate
belongs to the most specific zone of the organisation that contains the host.
Errors as for plan_custom/3 and create_certificate/2.
Orders an external certificate (plan_external/2 has the attributes and the
refusals). It belongs to the organisation and to the proxy group, which serves
it without being told to. No CAA record is written: Salt does not serve the
host's DNS.
Adds a provider to an organisation (nil for a provider shared by the whole
installation) and reads what its directory supports. Reading can fail (the
address is wrong, the provider is down); the provider is saved anyway with
the error in last_error, and refresh_capabilities/1 tries again.
The current version of a certificate with its key: the names, serial, validity, chain and private key (PEM), decrypted from the store. For the delivery to node agents; nothing else hands out key material, and no API endpoint returns it.
The current version of a certificate, or nil.
Deletes a provider that no certificate lists.
Disables a certificate: nothing is ordered or renewed, its CAA records are
removed. The stored versions stay. A disabled certificate never starts or
continues an order: jobs that are waiting or scheduled are cancelled, open
orders end as cancelled and their challenge records are removed at once, and
a job that is running stops at its next step (SaltDns.Certificates.Runner
reads the certificate again at every step). The metrics of the certificate
disappear with the next measurement.
The names of a certificate for display: [%{name:, unicode:}], the A-label
form that is ordered and stored, and the Unicode form (equal when the name is
plain ASCII).
Enables a disabled certificate again (a zone can have one live certificate).
True when the module is switched on (SALT_DNS_CERTIFICATES=on).
A sentence for an error of the functions that request or change a certificate.
A certificate of the organisation, or nil.
The live (not disabled) certificate FOR the zone (the zone and its wildcard), or nil.
A provider the organisation may use, or nil.
A provider by id, without an organisation check (internal).
The most specific zone of the organisation that contains the host (Unicode accepted): where a custom certificate for it would belong, so a caller can check who may order there before it looks at anything else.
The kind of a certificate: :zone (the zone and its wildcard), :custom (one
host inside a zone, with or without its wildcard) or :external (one host in no
zone of Salt, validated by HTTP-01 through a proxy group).
The certificates of an organisation, by zone name and then by names.
The most recent events of a certificate, newest first.
The most recent orders of a certificate, newest first.
The providers an organisation may use: its own and the shared ones.
Versions of a certificate, newest first.
The label a certificate has in the metrics: its host (the wildcard pair) or host (no wildcard).
The names of a certificate as one line: example.org, *.example.org; a name
that is internationalised shows its Unicode form first and the stored A-label
form in brackets.
Checks a request for a custom certificate without making it: the host (Unicode
is accepted, the A-label form is used) and whether the wildcard below it is
included. Returns the names, the most specific zone of the organisation that
contains the host, and warnings that do not stop the request, or
{:error, {reason, message}} with a message a person understands. Used by the
console to show the result before the request.
Checks a request for an external certificate without making it. attrs: host,
proxy_group_id and optionally provider_ids (when given it must be exactly the
provider the group answers for). Returns the plan with the result of the
pre-check (the host may not point at the group yet: that does not stop the
request, it stops each order until it does) and the DNS record the customer
must create, or {:error, {reason, message}}
Reads the provider's directory again. Returns {:ok | :error, provider}.
Registers the account at the provider (once): a new key, the binding key if
the provider wants one, agreement to its terms of service. The account key
is stored encrypted, the account address in account_url.
Asks for a new version now. It still obeys the daily limit on orders.
Number of certificates per status (every status present).
Subscribes the caller to new-current-version messages.
Changes the provider list (the order of providers), the profile and the CAA
option of a certificate. The checks are those of the request
(create_certificate/2): at least one provider, each visible to the
organisation and registered. A different provider list resets the fall-back
position to the first provider. The change is an event of the certificate; the
CAA records follow at once. attrs keys: provider_ids, profile,
publish_caa; keys that are absent stay as they are.
Changes a provider's name, contact, binding key or preferred profile.
Types
@type external_plan() :: %{ host: String.t(), unicode: String.t(), names: [String.t()], group: SaltDns.Proxy.Group.t(), provider: SaltDns.Certificates.Provider.t(), precheck: {:ok, map()} | {:error, {:precheck, String.t()}}, dns: map() }
What plan_external/2 found out about a request for an external certificate.
@type plan() :: %{ host: String.t(), unicode: String.t(), names: [String.t()], unicode_names: [String.t()], zone: SaltDns.Zones.Zone.t(), warnings: [String.t()] }
What plan_custom/3 found out about a request for a custom certificate.
Functions
@spec change_provider(SaltDns.Certificates.Provider.t(), map()) :: Ecto.Changeset.t()
Changeset for the provider form.
@spec create_certificate(SaltDns.Zones.Zone.t(), map()) :: {:ok, SaltDns.Certificates.Certificate.t()} | {:error, :zone_not_verified | :already_exists | SaltDns.Certificates.Names.error() | {:providers, String.t()} | {:budget, String.t()}}
Orders the certificate FOR a zone: the zone and *.zone, any other list is
refused (:not_wildcard_pair). Custom certificates (one host, with or
without the wildcard) are ordered with create_custom_certificate/2. The
zone must be verified (active). attrs: provider_ids (required, tried in
this order, each visible to the zone's organisation and registered),
profile, publish_caa (default true), names (optional; checked).
@spec create_custom_certificate(SaltDns.Accounts.Organisation.t(), map()) :: {:ok, SaltDns.Certificates.Certificate.t()} | {:error, term()}
Orders a custom certificate: attrs has host, wildcard (boolean; default
false), provider_ids, optional profile and publish_caa. The certificate
belongs to the most specific zone of the organisation that contains the host.
Errors as for plan_custom/3 and create_certificate/2.
@spec create_external_certificate(SaltDns.Accounts.Organisation.t(), map()) :: {:ok, SaltDns.Certificates.Certificate.t()} | {:error, term()}
Orders an external certificate (plan_external/2 has the attributes and the
refusals). It belongs to the organisation and to the proxy group, which serves
it without being told to. No CAA record is written: Salt does not serve the
host's DNS.
@spec create_provider(SaltDns.Accounts.Organisation.t() | nil, map()) :: {:ok, SaltDns.Certificates.Provider.t()} | {:error, Ecto.Changeset.t()}
Adds a provider to an organisation (nil for a provider shared by the whole
installation) and reads what its directory supports. Reading can fail (the
address is wrong, the provider is down); the provider is saved anyway with
the error in last_error, and refresh_capabilities/1 tries again.
@spec current_bundle(integer()) :: {:ok, %{ certificate_id: integer(), version_id: integer(), names: [String.t()], serial: String.t(), not_before: DateTime.t(), not_after: DateTime.t(), chain_pem: String.t(), key_pem: String.t() }} | {:error, :not_found | :no_version | term()}
The current version of a certificate with its key: the names, serial, validity, chain and private key (PEM), decrypted from the store. For the delivery to node agents; nothing else hands out key material, and no API endpoint returns it.
@spec current_version(SaltDns.Certificates.Certificate.t()) :: SaltDns.Certificates.Version.t() | nil
The current version of a certificate, or nil.
@spec delete_provider(SaltDns.Certificates.Provider.t()) :: {:ok, SaltDns.Certificates.Provider.t()} | {:error, :in_use}
Deletes a provider that no certificate lists.
@spec disable_certificate(SaltDns.Certificates.Certificate.t()) :: {:ok, SaltDns.Certificates.Certificate.t()}
Disables a certificate: nothing is ordered or renewed, its CAA records are
removed. The stored versions stay. A disabled certificate never starts or
continues an order: jobs that are waiting or scheduled are cancelled, open
orders end as cancelled and their challenge records are removed at once, and
a job that is running stops at its next step (SaltDns.Certificates.Runner
reads the certificate again at every step). The metrics of the certificate
disappear with the next measurement.
@spec display_names(SaltDns.Certificates.Certificate.t()) :: [ %{name: String.t(), unicode: String.t()} ]
The names of a certificate for display: [%{name:, unicode:}], the A-label
form that is ordered and stored, and the Unicode form (equal when the name is
plain ASCII).
@spec enable_certificate(SaltDns.Certificates.Certificate.t()) :: {:ok, SaltDns.Certificates.Certificate.t()} | {:error, :already_exists}
Enables a disabled certificate again (a zone can have one live certificate).
@spec enabled?() :: boolean()
True when the module is switched on (SALT_DNS_CERTIFICATES=on).
A sentence for an error of the functions that request or change a certificate.
@spec get_certificate(SaltDns.Accounts.Organisation.t(), term()) :: SaltDns.Certificates.Certificate.t() | nil
A certificate of the organisation, or nil.
@spec get_for_zone(SaltDns.Zones.Zone.t()) :: SaltDns.Certificates.Certificate.t() | nil
The live (not disabled) certificate FOR the zone (the zone and its wildcard), or nil.
@spec get_provider(SaltDns.Accounts.Organisation.t(), term()) :: SaltDns.Certificates.Provider.t() | nil
A provider the organisation may use, or nil.
@spec get_provider!(integer()) :: SaltDns.Certificates.Provider.t()
A provider by id, without an organisation check (internal).
@spec host_zone(SaltDns.Accounts.Organisation.t(), term()) :: {:ok, SaltDns.Zones.Zone.t()} | {:error, {atom(), String.t()}}
The most specific zone of the organisation that contains the host (Unicode accepted): where a custom certificate for it would belong, so a caller can check who may order there before it looks at anything else.
@spec kind(SaltDns.Certificates.Certificate.t()) :: :zone | :custom | :external
The kind of a certificate: :zone (the zone and its wildcard), :custom (one
host inside a zone, with or without its wildcard) or :external (one host in no
zone of Salt, validated by HTTP-01 through a proxy group).
@spec list_certificates(SaltDns.Accounts.Organisation.t()) :: [ SaltDns.Certificates.Certificate.t() ]
The certificates of an organisation, by zone name and then by names.
@spec list_events(SaltDns.Certificates.Certificate.t(), pos_integer()) :: [ SaltDns.Certificates.Event.t() ]
The most recent events of a certificate, newest first.
@spec list_orders(SaltDns.Certificates.Certificate.t(), pos_integer()) :: [ SaltDns.Certificates.Order.t() ]
The most recent orders of a certificate, newest first.
@spec list_providers(SaltDns.Accounts.Organisation.t()) :: [ SaltDns.Certificates.Provider.t() ]
The providers an organisation may use: its own and the shared ones.
@spec list_versions(SaltDns.Certificates.Certificate.t()) :: [ SaltDns.Certificates.Version.t() ]
Versions of a certificate, newest first.
@spec metric_label(SaltDns.Certificates.Certificate.t()) :: String.t()
The label a certificate has in the metrics: its host (the wildcard pair) or host (no wildcard).
@spec names_text(SaltDns.Certificates.Certificate.t()) :: String.t()
The names of a certificate as one line: example.org, *.example.org; a name
that is internationalised shows its Unicode form first and the stored A-label
form in brackets.
@spec plan_custom(SaltDns.Accounts.Organisation.t(), term(), term()) :: {:ok, plan()} | {:error, {atom(), String.t()} | :already_exists}
Checks a request for a custom certificate without making it: the host (Unicode
is accepted, the A-label form is used) and whether the wildcard below it is
included. Returns the names, the most specific zone of the organisation that
contains the host, and warnings that do not stop the request, or
{:error, {reason, message}} with a message a person understands. Used by the
console to show the result before the request.
Refused: a host that is not valid (:bad_host), inside no zone of the
organisation (:no_zone), in a zone that is not verified
(:zone_not_verified), under a delegation (:delegated), with a CNAME at
its challenge name (:challenge_cname), the same names as a certificate the
organisation has already (:already_exists), or over the weekly budget of
new certificates for the registered domain (:budget).
@spec plan_external(SaltDns.Accounts.Organisation.t(), map()) :: {:ok, external_plan()} | {:error, {atom(), String.t()} | :already_exists}
Checks a request for an external certificate without making it. attrs: host,
proxy_group_id and optionally provider_ids (when given it must be exactly the
provider the group answers for). Returns the plan with the result of the
pre-check (the host may not point at the group yet: that does not stop the
request, it stops each order until it does) and the DNS record the customer
must create, or {:error, {reason, message}}:
:bad_host; a wildcard (:wildcard) is refused, HTTP-01 cannot prove one;:inside_own_zone,:inside_other_zone: the host lies in an active zone (SaltDns.Certificates.Names.judge_external/3);:group: no such group, or it does not answer HTTP-01 (SaltDns.Certificates.Http01.check_group/2);:providers;:already_exists.
@spec refresh_capabilities(SaltDns.Certificates.Provider.t()) :: {:ok | :error, SaltDns.Certificates.Provider.t()}
Reads the provider's directory again. Returns {:ok | :error, provider}.
@spec register_provider(SaltDns.Certificates.Provider.t()) :: {:ok, SaltDns.Certificates.Provider.t()} | {:error, String.t()}
Registers the account at the provider (once): a new key, the binding key if
the provider wants one, agreement to its terms of service. The account key
is stored encrypted, the account address in account_url.
@spec request_renewal(SaltDns.Certificates.Certificate.t()) :: {:ok, SaltDns.Certificates.Certificate.t()} | {:error, :disabled}
Asks for a new version now. It still obeys the daily limit on orders.
@spec status_counts() :: %{required(atom()) => non_neg_integer()}
Number of certificates per status (every status present).
@spec subscribe() :: :ok | {:error, term()}
Subscribes the caller to new-current-version messages.
@spec update_certificate(SaltDns.Certificates.Certificate.t(), map()) :: {:ok, SaltDns.Certificates.Certificate.t()} | {:error, {:providers, String.t()}}
Changes the provider list (the order of providers), the profile and the CAA
option of a certificate. The checks are those of the request
(create_certificate/2): at least one provider, each visible to the
organisation and registered. A different provider list resets the fall-back
position to the first provider. The change is an event of the certificate; the
CAA records follow at once. attrs keys: provider_ids, profile,
publish_caa; keys that are absent stay as they are.
@spec update_provider(SaltDns.Certificates.Provider.t(), map()) :: {:ok, SaltDns.Certificates.Provider.t()} | {:error, Ecto.Changeset.t()}
Changes a provider's name, contact, binding key or preferred profile.