Karta. Kantoor. Attach
(Karta v1.0.0)
Attaching a mailbox to a domain through /kantoor/v1: registering its
HTTP endpoint (POST /endpoints, contract operation 1/10) and creating
the route that sends an address or a whole domain to it (POST /routes,
contract operation 10).
Authorisation. Everything is scoped to the key's server. A route's
domain must be a verified domain of that server's organisation, and the
address must be one the key's restrictions allow
(Karta.Kantoor.Restrictions); a route to a whole domain (*) needs a
restriction that matches a * local part. A route may point only at an
HTTP endpoint of the same server that is marked for Kantoor (made through
this interface, or marked by an operator), never at an operator's SMTP or
forwarding endpoint. An endpoint's URL must be https: and its host must
be one Karta may connect to (Karta.NetGuard), checked when it is
registered and again at every delivery.
Ownership. The key that registers an endpoint owns it
(credential_id), and only that key, or an unrestricted key of the same
server (one with neither allowed_domains nor allowed_mailboxes), may
register it again, change it or point a route at it. A restricted key
may never touch an endpoint it does not own, and never one whose owner is
gone (credential_id is nil: an operator's endpoint, or one whose key
was deleted). An unrestricted key that registers such an endpoint adopts
it: the endpoint becomes that key's. This is how a rotated or replaced
key re-adopts its endpoints. A refusal is 403 forbidden_endpoint and
says nothing about the other endpoint, not even its URL.
Registering again. An endpoint is found by its name on the server: a
second registration of the same name returns that endpoint (and updates
its URL and notify_only), so a request repeated after a lost answer
makes nothing twice. Two registrations at once are settled by a unique
index on the name of a mailbox endpoint: the loser answers as the second
request would have a moment later. A route that already matches the
request is returned as it is. A route that differs is a conflict, unless
the request says "takeover": true and the route already points at the
endpoint the request names; even then it never moves to another endpoint.
Two route creations at once are settled the same way: the loser answers
as the second request would have.
The routes and endpoints are made through Karta.Inbound, as an
operator's are, so the server's pages are told of each change
(Karta.Changes).
Summary
Functions
Registers the mailbox's HTTP endpoint (format: karta, https: only,
optionally notify-only) on the key's server, or returns the endpoint of
the same name that is already there.
Creates the route local_part@domain to the endpoint (contract
operation 10), or returns the route that is already there.
Functions
@spec endpoint(map(), map()) :: {:ok, Karta.Inbound.Endpoint.t(), String.t() | nil, :created | :existing} | {:error, :changeset, Ecto.Changeset.t()} | {:error, :invalid, String.t(), String.t()} | {:error, :forbidden, String.t(), String.t(), [map()]} | {:error, :conflict, String.t(), String.t(), [map()]}
Registers the mailbox's HTTP endpoint (format: karta, https: only,
optionally notify-only) on the key's server, or returns the endpoint of
the same name that is already there.
Returns {:ok, endpoint, secret | nil, :created | :existing} (the
secret only when it is made), {:error, :changeset, changeset},
{:error, :invalid, field, message}, {:error, :forbidden, code, message, details} (another key's endpoint) or {:error, :conflict, code, message, details}.
@spec route(map(), map()) :: {:ok, Karta.Inbound.Route.t(), :created | :existing | :taken_over} | {:error, :changeset, Ecto.Changeset.t()} | {:error, :invalid, String.t(), String.t()} | {:error, :forbidden, String.t(), String.t(), [map()]} | {:error, :conflict, String.t(), String.t(), [map()]}
Creates the route local_part@domain to the endpoint (contract
operation 10), or returns the route that is already there.
Returns {:ok, route, :created | :existing | :taken_over},
{:error, :changeset, changeset}, {:error, :invalid, field, message},
{:error, :forbidden, code, message, details} or
{:error, :conflict, code, message, details}.