SaltDnsWeb. API. Authenticate
(Salt v1.0.0)
API authentication: Authorization: Bearer <token>.
The token is checked with SaltDns.Credentials.authenticate_token/1 (which
also records last_used_at, at most once a minute). On success the
connection gets :credential, :organisation, :access_actor
({:credential, credential} for SaltDns.Access) and :audit_actor
(SaltDns.Zones.Actor, source api).
A provisioning token (SaltDns.Provisioning) never acts in its own
organisation. On the provisioning routes (provider: true) the connection
gets the provider organisation as :provider and no :access_actor; on every
other route the child organisation named by the X-Salt-Organisation header
becomes :organisation and the token acts there. A missing header is a 400;
an organisation that is not a child of the token's own is a 404, the same as
one that does not exist. Other tokens ignore the header, and a token that is
not a provisioning token is a 403 on the provisioning routes.
The registrar routes (SaltDnsWeb.API.RegistrarController) use the option
registrar: {level, header}: header is :optional or :required for a
provisioning token (see registrar/4 below) and level is the registrar level
the route needs (:read or :purchase). Authentication comes first, as on
every route; SaltDnsWeb.API.RegistrarEnabled then answers 404 while the
module is off, and 403 when the token's level is too low (the same order as
/proxy: switch, then grant).
Every failure (no header, wrong scheme, malformed, unknown, wrong secret, revoked, expired) is the same 401, so a caller learns nothing about which tokens exist. Failed attempts are counted per IP; past the limit the answer is 429 until the window ends, which stops guessing.