SaltDns.Auth.Grants (Salt v1.0.0)

Decides whether a credential may do something. Pure, default deny.

A grant is a map:

%{zone: "example.com" | :any,
  names: ["@", "www", "*.dev", "_acme-challenge.www"],
  types: ["TXT", "A"] | :any,
  actions: [:read | :update | :manage | :certificates | :proxy]}

Zone names are absolute, lower-case A-labels without a trailing dot. Types are upper-case mnemonics. Run grants through validate/1 before storing them; the matching functions also lower-case what they compare, so they stay safe on unvalidated input.

Name patterns

Patterns are relative to the zone and compared case-insensitively.

  • "@" is the apex only.
  • "*" is every name in the zone, the apex included.
  • "*.<rel>" is the strict subdomains of <rel> at any depth, not <rel> itself ("*.dev" matches a.dev and a.b.dev, not dev).
  • anything else is that exact relative name ("www", "_acme-challenge.www").

Names are matched label by label, never as text. A record whose owner has the literal single label @ (@.example.com) is therefore NOT the apex.

Actions

  • :read reads records.
  • :update writes records; it implies :read of every type at the same names (a CNAME there forbids other data and other data forbids a CNAME, RFC 1034 §3.6.2, so a writer must see what is at the name).
  • :manage is for zone-level operations (create or delete the zone, change zone settings). By convention it is checked against the zone apex and the SOA type: allowed?(grants, :manage, zone, zone, "SOA"). A manage grant must therefore cover "@" and SOA (or :any). :manage implies neither :update nor :read of records.
  • :certificates is for the certificate module (SaltDns.Certificates, /api/v1/certificates): list and request certificates of the zone the grant names (or of every zone with zone :any), renew and disable them. It is separate on purpose: it implies nothing about records, and no DNS grant gives it. No grant gives access to a private key; there is no API that returns one.
  • :proxy is for routing (SaltDns.Proxy, /api/v1/proxy): proxy groups, backends, routes and nodes of the organisation. It needs a grant of zone :any (routing is not about one zone), implies nothing about records, and no DNS grant, nor :certificates, gives it.

name is an absolute name; a name outside zone is always denied, and so is any zone or name containing a backslash (an escaped label). A single trailing dot on zone or name is ignored.

Summary

Functions

True when any grant allows action on the RRset (name, type) of zone.

The types the grants allow reading at name: :any, or a set (possibly empty). Consistent with allowed?/5: allowed?(g, :read, z, n, t) is true exactly when t is in the result. Used to answer signed ANY queries with only the permitted RRsets.

Validates and normalises a grant: lower-cases zone and names, upper-cases types, drops duplicates. Rejects unknown keys, empty lists, bad patterns and unknown actions.

Types

action()

@type action() :: :read | :update | :manage | :certificates | :proxy

grant()

@type grant() :: %{
  zone: String.t() | :any,
  names: [String.t()],
  types: [String.t()] | :any,
  actions: [action()]
}

Functions

allowed?(grants, action, zone, name, type)

@spec allowed?([grant()], action(), String.t(), String.t(), String.t()) :: boolean()

True when any grant allows action on the RRset (name, type) of zone.

readable_types(grants, zone, name)

@spec readable_types([grant()], String.t(), String.t()) :: :any | MapSet.t(String.t())

The types the grants allow reading at name: :any, or a set (possibly empty). Consistent with allowed?/5: allowed?(g, :read, z, n, t) is true exactly when t is in the result. Used to answer signed ANY queries with only the permitted RRsets.

validate(grant)

@spec validate(map()) :: {:ok, grant()} | {:error, term()}

Validates and normalises a grant: lower-cases zone and names, upper-cases types, drops duplicates. Rejects unknown keys, empty lists, bad patterns and unknown actions.