SaltDns.Certificates.Http01 (Salt v1.0.0)

Certificates for a host whose DNS Salt does not serve (kind external), validated by the HTTP-01 challenge through a proxy group.

The customer keeps the DNS of their domain elsewhere and points the host at the group's load balancers with a CNAME (or A and AAAA records). The group answers the challenge itself: with http01_enabled the generated HAProxy configuration holds one rule in the port 80 frontend that answers /.well-known/acme-challenge/<token> with <token>.<thumbprint>, where the thumbprint is that of the group's ACME account (SaltDns.Certificates.Thumbprint). The load balancers are told no tokens; Shaker is not involved.

This module holds the checks around an order:

  • check_group/2: the group has HTTP-01 on, for the provider of the certificate;
  • precheck/2: the host resolves to the group's load balancers. Done before an order is placed and before every renewal, because a provider limits failed validations. The lookup is SaltDns.Edges.resolve/1, the one the Name servers page uses. A CNAME is followed to its addresses, so the check reads where the name ends up: either the addresses of the group's nodes, or those of its address names, and every address of the host must be one of them;
  • self_check/1: Salt asks for the challenge over plain HTTP itself before it tells the provider to validate, so a failure is found here and says what came back.

Who may order for a host: only the organisation whose proxy group routes that host (before_order/2 checks the route, the group's organisation, the provider and that the host lies in no zone of any organisation, before every order and every renewal). A host can be routed by one group only (SaltDns.Proxy). The provider must belong to the group's organisation: a provider shared by the whole installation has one account and so one thumbprint for every organisation, which would let one organisation obtain a certificate for a host served by another organisation's load balancers. It is refused unless the operator sets SALT_DNS_CERT_HTTP01_SHARED_PROVIDERS=on.

CAA is not read: the resolver of Salt looks up addresses only. A CAA record that leaves the provider out makes the provider refuse the order, and the refusal is shown.

Summary

Types

What a pre-check found: what the host resolves to, and what is allowed.

Functions

The names a customer can point a CNAME at: the group's extra address names, then the hosts of its routes (exact names, with an address published) that lie in an active zone of the organisation. These are the names Salt keeps the load balancers' addresses at.

The addresses the group's load balancers are known by, as text and normalised: the addresses typed in for its nodes that reported recently, minus those another organisation keeps (SaltDns.Certificates.Http01.Claims has the precedence: an operator assignment, then the oldest claim corroborated by the address Salt saw the node connect from, and an address only uncorroborated claims dispute is nobody's). The address Salt saw a node connect from is not a claim by itself. Names the organisation controls (extra names, route hosts) are not evidence either. Before the provider is told to validate, the self-check proves that the address answers with this group's key authorisation.

Assigns a disputed address to one group (the operator's decision, for a node whose connection address cannot corroborate its public address, or any dispute). Audited in the change history of the group it goes to and, when it was assigned to another group before, of that group too; the entry names the operator (operator, a name the caller gives, for the release task whoever ran it), both groups and the address. The actor of the entry is the system, so the name is in the detail. The group still needs a reporting node with the address typed in.

The checks before an order of an external certificate and before each renewal

Checks that the group answers HTTP-01 for provider: the setting is on and the group's provider is this one. Returns :ok or {:error, {:http01, message}}.

Every address claimed by reporting nodes of more than one organisation, for the operator: [%{address:, kept_by: group_id | nil, refused: [group_id], disputed?: boolean}]. Prints nothing and changes nothing.

The record the customer creates at their own DNS host, as text, or nil when the group has no address name (then A and AAAA records at the addresses).

Refuses a new HTTP-01 order when the organisation already had max_failed_orders_per_day/0 failed ones in the last 24 hours (a provider limits failed validations, and one customer must not use them up for everyone). The message says when it is allowed again.

The addresses typed in for the group's reporting nodes that another organisation keeps, or that are disputed: the group lost them. Empty when there is no collision.

The most failed HTTP-01 orders an organisation may have in 24 hours.

Looks up the host and compares it with the group's load balancers. Returns {:ok, found} when the host resolves to addresses that are all the group's, or {:error, {:precheck, message}} that says what the host resolves to and what it should resolve to. Nothing is ordered on an error.

Whether provider may answer HTTP-01 challenges for group: it belongs to the group's organisation, or it belongs to none (shared) and the operator allowed that (SALT_DNS_CERT_HTTP01_SHARED_PROVIDERS=on).

Asks for each challenge over plain HTTP, at the host's load balancer, before the provider is told to validate. The host is resolved once: every address it resolves to must be one of the group's confirmed addresses (allowed_addresses/1) and, unless the test-only option config :salt_dns, :http01_allow_private, true is set, a public address (SaltDns.AddressFilter: no loopback, private, link-local, unique-local, CGNAT or multicast address, even if a group claims it). The request goes to exactly one of those addresses with the host name in the Host header, follows no redirect, has short time limits and reads a few hundred bytes at most. The caller is told whether the answer matched and the status, never the body.

True when the operator allowed shared providers for HTTP-01 (default: no).

The thumbprint the group's rule answers with, or nil when HTTP-01 is off or the provider has no usable account key.

Removes an operator assignment: the precedence of the claims decides again. Audited in the group that had it, with the operator.

Judges the host of an external certificate against every active zone of the installation (SaltDns.Certificates.Names.judge_external/3).

Types

found()

@type found() :: %{
  host: String.t(),
  resolved: [String.t()],
  allowed: [String.t()],
  target: String.t() | nil
}

What a pre-check found: what the host resolves to, and what is allowed.

Functions

address_names(group)

@spec address_names(SaltDns.Proxy.Group.t()) :: [String.t()]

The names a customer can point a CNAME at: the group's extra address names, then the hosts of its routes (exact names, with an address published) that lie in an active zone of the organisation. These are the names Salt keeps the load balancers' addresses at.

allowed_addresses(group)

@spec allowed_addresses(SaltDns.Proxy.Group.t()) :: [String.t()]

The addresses the group's load balancers are known by, as text and normalised: the addresses typed in for its nodes that reported recently, minus those another organisation keeps (SaltDns.Certificates.Http01.Claims has the precedence: an operator assignment, then the oldest claim corroborated by the address Salt saw the node connect from, and an address only uncorroborated claims dispute is nobody's). The address Salt saw a node connect from is not a claim by itself. Names the organisation controls (extra names, route hosts) are not evidence either. Before the provider is told to validate, the self-check proves that the address answers with this group's key authorisation.

assign_address(address, group_id, operator \\ "operator")

@spec assign_address(String.t(), integer(), String.t()) ::
  :ok | {:error, :unknown_group | :invalid_address}

Assigns a disputed address to one group (the operator's decision, for a node whose connection address cannot corroborate its public address, or any dispute). Audited in the change history of the group it goes to and, when it was assigned to another group before, of that group too; the entry names the operator (operator, a name the caller gives, for the release task whoever ran it), both groups and the address. The actor of the entry is the system, so the name is in the detail. The group still needs a reporting node with the address typed in.

before_order(cert, provider)

@spec before_order(
  SaltDns.Certificates.Certificate.t(),
  SaltDns.Certificates.Provider.t()
) ::
  {:ok, found()} | {:error, {:gone | :http01 | :limit | :precheck, String.t()}}

The checks before an order of an external certificate and before each renewal:

  1. the group still exists and belongs to the certificate's organisation;
  2. the group still has a route for the host (the route is what ties the host to this group; a host is routed by one group only);
  3. the host is still inside no active zone of any organisation;
  4. the group answers HTTP-01 for this provider, and the provider is allowed;
  5. the organisation is under its limit of failed HTTP-01 orders;
  6. the host points at the group's load balancers (precheck/2).

{:ok, found} or {:error, {kind, message}}. kind is :gone when the certificate can never be ordered again (no group, no route, a zone covers the host: the runner disables the certificate), :http01, :limit or :precheck (try again later).

check_group(group, provider)

@spec check_group(SaltDns.Proxy.Group.t() | nil, SaltDns.Certificates.Provider.t()) ::
  :ok | {:error, {:http01, String.t()}}

Checks that the group answers HTTP-01 for provider: the setting is on and the group's provider is this one. Returns :ok or {:error, {:http01, message}}.

collisions()

@spec collisions() :: [map()]

Every address claimed by reporting nodes of more than one organisation, for the operator: [%{address:, kept_by: group_id | nil, refused: [group_id], disputed?: boolean}]. Prints nothing and changes nothing.

dns_instruction(group, host)

@spec dns_instruction(SaltDns.Proxy.Group.t(), String.t()) :: %{
  cname: String.t() | nil,
  addresses: [String.t()],
  bare_domain_note: String.t()
}

The record the customer creates at their own DNS host, as text, or nil when the group has no address name (then A and AAAA records at the addresses).

failed_limit(organisation_id)

@spec failed_limit(integer()) :: :ok | {:error, {:limit, String.t()}}

Refuses a new HTTP-01 order when the organisation already had max_failed_orders_per_day/0 failed ones in the last 24 hours (a provider limits failed validations, and one customer must not use them up for everyone). The message says when it is allowed again.

lost_addresses(group)

@spec lost_addresses(SaltDns.Proxy.Group.t()) :: [String.t()]

The addresses typed in for the group's reporting nodes that another organisation keeps, or that are disputed: the group lost them. Empty when there is no collision.

max_failed_orders_per_day()

@spec max_failed_orders_per_day() :: pos_integer()

The most failed HTTP-01 orders an organisation may have in 24 hours.

precheck(group, host)

@spec precheck(SaltDns.Proxy.Group.t(), String.t()) ::
  {:ok, found()} | {:error, {:precheck, String.t()}}

Looks up the host and compares it with the group's load balancers. Returns {:ok, found} when the host resolves to addresses that are all the group's, or {:error, {:precheck, message}} that says what the host resolves to and what it should resolve to. Nothing is ordered on an error.

provider_ok?(provider, group)

Whether provider may answer HTTP-01 challenges for group: it belongs to the group's organisation, or it belongs to none (shared) and the operator allowed that (SALT_DNS_CERT_HTTP01_SHARED_PROVIDERS=on).

self_check(group, challenges)

@spec self_check(SaltDns.Proxy.Group.t() | nil, [map()]) ::
  :ok | {:error, {:self_check, String.t()}}

Asks for each challenge over plain HTTP, at the host's load balancer, before the provider is told to validate. The host is resolved once: every address it resolves to must be one of the group's confirmed addresses (allowed_addresses/1) and, unless the test-only option config :salt_dns, :http01_allow_private, true is set, a public address (SaltDns.AddressFilter: no loopback, private, link-local, unique-local, CGNAT or multicast address, even if a group claims it). The request goes to exactly one of those addresses with the host name in the Host header, follows no redirect, has short time limits and reads a few hundred bytes at most. The caller is told whether the answer matched and the status, never the body.

challenges are maps with domain, token and key_authorization. Returns :ok or {:error, {:self_check, message}}.

shared_providers_allowed?()

@spec shared_providers_allowed?() :: boolean()

True when the operator allowed shared providers for HTTP-01 (default: no).

thumbprint(group)

@spec thumbprint(SaltDns.Proxy.Group.t()) :: String.t() | nil

The thumbprint the group's rule answers with, or nil when HTTP-01 is off or the provider has no usable account key.

unassign_address(address, operator \\ "operator")

@spec unassign_address(String.t(), String.t()) :: :ok

Removes an operator assignment: the precedence of the claims decides again. Audited in the group that had it, with the operator.

zone_check(host, organisation_id)

@spec zone_check(String.t(), integer()) :: :ok | {:error, {atom(), String.t()}}

Judges the host of an external certificate against every active zone of the installation (SaltDns.Certificates.Names.judge_external/3).