SaltDns.Access.Policy (Salt v1.0.0)

The pure decision behind SaltDns.Access.

A principal is who asks:

  • {:user, roles}: a user, with roles a map of organisation id to role (:owner | :admin | :editor | :viewer), their memberships;
  • {:credential, credential}: any map or struct with organisation_id, grants (a list, or :invalid), revoked_at and expires_at.

A zone is any map or struct with name, organisation_id and status.

Rules, in order; the first that applies decides:

  1. Organisation isolation. A principal only ever acts on zones of its own organisation(s). A user without a role in the zone's organisation, and a credential of another organisation, are denied whatever the role or grants say, including grants with zone :any.
  2. The name must be inside the zone, and neither zone nor name may contain a backslash (escaped labels are not understood here).
  3. A disabled zone allows no :update to anyone.
  4. Users: owner and admin may :read, :update and :manage; editor may :read and :update; viewer may :read.
  5. Credentials: revoked, expired and invalid-grant credentials are denied; otherwise SaltDns.Auth.Grants.allowed?/5 decides.

:manage on the zone itself is asked as (:manage, zone, zone.name, "SOA"). pending zones are editable. Everything else is denied.

Summary

Functions

True when principal may do action on (name, type) of zone at now.

True when principal may use the certificate module in organisation_id.

True when principal may create a zone called name in organisation_id.

True when the user principal is :owner or :admin in organisation_id.

True when principal may manage the organisation's secondary nameservers: owners and admins, and credentials of that organisation with one grant of zone :any and action :manage.

Whether the principal may use routing (SaltDns.Proxy) in the organisation. level is :read or :manage. Users: any member reads, owners and admins manage. Credentials: the organisation matches, the credential is usable and has a grant of zone :any with the action :proxy; no DNS grant and no :certificates grant gives it.

Types

action()

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

principal()

@type principal() :: {:user, %{optional(integer()) => role()}} | {:credential, map()}

role()

@type role() :: :owner | :admin | :editor | :viewer

Functions

allowed?(principal, action, zone, name, type, now \\ DateTime.utc_now())

@spec allowed?(principal(), action(), map(), String.t(), String.t(), DateTime.t()) ::
  boolean()

True when principal may do action on (name, type) of zone at now.

certificates?(principal, organisation_id, level, zone_name \\ nil, now \\ DateTime.utc_now())

@spec certificates?(
  principal(),
  integer(),
  :read | :manage,
  String.t() | nil,
  DateTime.t()
) ::
  boolean()

True when principal may use the certificate module in organisation_id.

level is :read (list and show) or :manage (request, renew, disable). Users: any member may read, owners and admins manage. Credentials: the organisation matches, the credential is usable and has a grant with the action :certificates for the zone (zone_name; nil asks about the organisation as a whole and needs a grant of zone :any). A grant of :read, :update or :manage never gives this, so a DNS token cannot touch certificates.

creates_zones?(principal, organisation_id, name, now \\ DateTime.utc_now())

@spec creates_zones?(principal(), integer(), String.t(), DateTime.t()) :: boolean()

True when principal may create a zone called name in organisation_id.

Users: owner or admin. Credentials: the organisation matches, the credential is usable and one single grant has zone :any and action :manage and covers the apex SOA of name. A grant for one named zone is not enough, so a token cannot create zones it was not given in advance.

manages_credentials?(arg1, organisation_id)

@spec manages_credentials?(principal(), integer()) :: boolean()

True when the user principal is :owner or :admin in organisation_id.

manages_secondaries?(principal, organisation_id, now \\ DateTime.utc_now())

@spec manages_secondaries?(principal(), integer(), DateTime.t()) :: boolean()

True when principal may manage the organisation's secondary nameservers: owners and admins, and credentials of that organisation with one grant of zone :any and action :manage.

proxy?(principal, organisation_id, level, now \\ DateTime.utc_now())

@spec proxy?(principal(), integer(), :read | :manage, DateTime.t()) :: boolean()

Whether the principal may use routing (SaltDns.Proxy) in the organisation. level is :read or :manage. Users: any member reads, owners and admins manage. Credentials: the organisation matches, the credential is usable and has a grant of zone :any with the action :proxy; no DNS grant and no :certificates grant gives it.