KartaWeb. APIAuth
(Karta v1.0.0)
Authenticates a request to a sending API with an API key of a mail
server (Karta.Credentials) and assigns the credential, with its server,
as :credential.
- The key is read from the
X-Server-API-Keyheader (token: :postal, the Postal-compatible API), from theX-Postmark-Server-Tokenheader (token: :postmark, the Postmark-compatible API), fromAuthorization: Bearer(token: :bearer), or fromAuthorization: Basicwith the user nameapiand the key as the password (token: :basic, as Mailgun's clients send it). Never from the query string. - A key verified in the last minutes is recognised from
Karta.Credentials.KeyCache(the credential is still read from the database); any other key is verified with Argon2id. Verifications are limited per client address (verifications_per_minute, default 60, orconfig :karta, KartaWeb.APIAuth, verifications_per_minute:), so that nobody can make Karta hash without limit; keys found in the cache do not count. A client is an IPv4 address or an IPv6 /64 (Karta.CIDR.client_key/1), afterKartaWeb.ClientIPhas found the address behind trusted proxies. - A suspended server's key is refused.
- A Kantoor key (
Karta.Kantoor) is accepted only where the plug is givenkantoor: true(the/kantoor/v1scope), and every other key only where it is not: elsewhere it is "not valid" (401), as an unknown key is. - Each credential's requests are counted (
Karta.Limits, the credential'sKarta.Credentials.rate_limit/1per minute). The count is a row in the database, so every node counts against the same limit: two nodes do not allow twice the requests. A counter that cannot be read refuses the request rather than letting it through.
Failures halt the request with a reply from the errors module
(KartaWeb.APIErrors): :missing_key, :invalid_key,
:server_suspended, or {:rate_limited, seconds}. KartaWeb.APIScope
then checks each action's scope.