Sovite.Core.Tenants (sovite v0.6.0)

Copy Markdown View Source

Tenants ([[tenant]]), for hosting the mail of several customers on one server or cluster, each with its own limits, signing keys, and outbound IP pool.

[[tenant]]
name = "acme"
domains = ["acme.example"]
users = ["relay-user"]
ip_pool = "acme"
messages = "10000/1d"
recipients = "50000/1d"
max_message_size = "10M"
max_recipients = 500

Which tenant a message belongs to

Mail a client submits belongs to a tenant when the client logged in as one of the tenant's users, or with a login in one of its domains (user@acme.example, or a subdomain), or else, for clients that logged in or are in smtp.trusted_networks, when the sender's domain is one of its domains. Mail from anyone else, such as mail arriving from the internet, belongs to no tenant. The tenant is kept with the queued message.

What a tenant gets

  • Limits, on top of the server's: messages and recipients per period for the whole tenant (rate limits, shared by the cluster), and max_message_size and max_recipients per message.
  • DKIM keys: the keys of a tenant's domains ([[dkim.key]]) sign only that tenant's mail, so one customer cannot sign as another.
  • An IP pool (ip_pool, see Sovite.Core.IPPools) to send from, instead of delivery.ip_pool. An address the sender relays table gives for a sender comes first.

Telemetry

  • [:sovite, :tenant, :limited] - %{}, %{tenant, limit}, when a tenant limit refuses a message or recipient: limit is :messages, :recipients, :max_message_size, or :max_recipients.

Summary

Functions

The tenant of a message from a client logged in as identity (or nil), from sender, by a client that is trusted or not.

The tenant named name (from a queued message), if it is still configured.

Counts a message of tenant with size bytes (or nil when not known yet). Returns :ok, or {:limited, limit}.

Tenant options for sessions, or nil without tenants.

The tenant that owns domain or its closest parent domain, if any: the one whose DKIM keys for the domain may sign.

Counts the countth recipient of a message of tenant. Returns :ok or {:limited, limit}.

Whether a message of size bytes is too large for tenant.

Functions

find(arg1, identity, sender, trusted)

@spec find(map() | nil, String.t() | nil, String.t(), boolean()) :: map() | nil

The tenant of a message from a client logged in as identity (or nil), from sender, by a client that is trusted or not.

get(tenants, name)

@spec get([Sovite.Core.Config.tenant()], String.t() | nil) :: map() | nil

The tenant named name (from a queued message), if it is still configured.

message(opts, tenant, size)

@spec message(map() | nil, map() | nil, non_neg_integer() | nil) ::
  :ok | {:limited, :messages | :max_message_size}

Counts a message of tenant with size bytes (or nil when not known yet). Returns :ok, or {:limited, limit}.

opts(config, rate_limit)

@spec opts(Sovite.Core.Config.t(), atom() | nil) :: map() | nil

Tenant options for sessions, or nil without tenants.

owner(tenants, domain)

@spec owner([Sovite.Core.Config.tenant()], String.t()) :: String.t() | nil

The tenant that owns domain or its closest parent domain, if any: the one whose DKIM keys for the domain may sign.

recipient(opts, tenant, count)

@spec recipient(map() | nil, map() | nil, pos_integer()) ::
  :ok | {:limited, :recipients | :max_recipients}

Counts the countth recipient of a message of tenant. Returns :ok or {:limited, limit}.

too_large?(tenant, size)

@spec too_large?(map() | nil, non_neg_integer()) :: boolean()

Whether a message of size bytes is too large for tenant.