SaltDns.Certificates.Http01.Claims (Salt v1.0.0)

Who keeps an address that more than one organisation claims, for the pre-check of an external certificate (SaltDns.Certificates.Http01). Pure: the caller reads the nodes, this module decides.

A claim is a node of a proxy group that has reported recently and has the address typed in. It is corroborated when Salt itself saw that node connect from that very address, recently: the signed status proves the node holds its enrolment key, not where it is, so a typed address alone is only a statement.

Precedence for one address:

  1. an address the operator assigned to a group goes to that group's organisation;
  2. otherwise, if any claim is corroborated, the oldest corroborated claim wins (two corroborated claims from one egress address behind NAT fall back to older-first; the age is when the address was first typed in for that node, ties by node id). A corroborated claim always beats an uncorroborated one;
  3. otherwise (only uncorroborated claims): one organisation alone keeps the address; with two or more organisations it is disputed and nobody keeps it, until a claim is corroborated or the operator assigns it.

A node behind NAT, whose connection address differs from its public service address, can never corroborate; it keeps an address nobody else claims, and in a dispute the operator's assignment is the remedy.

Summary

Functions

When the address was first typed in for the node, in microseconds, from the node's address_claims (ISO 8601 by address). An address with no recorded time counts as made last of all: never the enrolment time, which says nothing about when an address was typed in.

The addresses claimed by more than one organisation, for the operator: [%{address:, kept_by: group_id | nil, refused: [group_id], disputed?: boolean}].

True when the address Salt saw the node connect from is address, and it was seen within max seconds of now.

The claims of nodes, as {node, group_id, organisation_id, status_max_age}: those that reported within status_max_age of now, one claim per typed-in address.

The text of an IP address in one form (::ffff:1.2.3.4 stays as it is); anything else unchanged.

The organisation that keeps each claimed address, %{address => org_id | :disputed}. assigned is %{address => org_id} of the operator's assignments.

True when last_ok_status_at is within max seconds of now.

Splits the addresses an organisation's reporting nodes have typed in into {kept, lost}: an address is lost when another organisation keeps it, or when it is disputed.

Types

claim()

@type claim() :: %{
  address: String.t(),
  org: integer(),
  group: integer(),
  node_id: integer(),
  at: integer(),
  corroborated?: boolean()
}

Functions

claim_time(claims, address)

@spec claim_time(map() | nil, String.t()) :: integer()

When the address was first typed in for the node, in microseconds, from the node's address_claims (ISO 8601 by address). An address with no recorded time counts as made last of all: never the enrolment time, which says nothing about when an address was typed in.

collisions(claims, assigned \\ %{})

@spec collisions([claim()], %{required(String.t()) => integer()}) :: [map()]

The addresses claimed by more than one organisation, for the operator: [%{address:, kept_by: group_id | nil, refused: [group_id], disputed?: boolean}].

corroborated?(seen, at, address, max, now)

@spec corroborated?(
  String.t() | nil,
  DateTime.t() | nil,
  String.t(),
  integer(),
  DateTime.t()
) ::
  boolean()

True when the address Salt saw the node connect from is address, and it was seen within max seconds of now.

from_nodes(rows, now)

@spec from_nodes([{map(), integer(), integer(), integer()}], DateTime.t()) :: [
  claim()
]

The claims of nodes, as {node, group_id, organisation_id, status_max_age}: those that reported within status_max_age of now, one claim per typed-in address.

normalise(text)

@spec normalise(String.t()) :: String.t()

The text of an IP address in one form (::ffff:1.2.3.4 stays as it is); anything else unchanged.

precedence(claims, assigned \\ %{})

@spec precedence([claim()], %{required(String.t()) => integer()}) :: %{
  required(String.t()) => integer() | :disputed
}

The organisation that keeps each claimed address, %{address => org_id | :disputed}. assigned is %{address => org_id} of the operator's assignments.

reported?(at, max, now)

@spec reported?(DateTime.t() | nil, integer(), DateTime.t()) :: boolean()

True when last_ok_status_at is within max seconds of now.

split(own, org, precedence)

@spec split([String.t()], integer(), %{required(String.t()) => integer() | :disputed}) ::
  {[String.t()], [String.t()]}

Splits the addresses an organisation's reporting nodes have typed in into {kept, lost}: an address is lost when another organisation keeps it, or when it is disputed.