Skip to content

Overview

A mapping associates an account identifier with the destination that holds the account. Mappings are how the proxy knows where each account lives. When a client authenticates, the proxy derives an identifier from its credentials, looks it up in the mapping store, and sends the session to the destination that the lookup returns. An account without a mapping goes to the default destination.

In a migration, this gives a simple progression. Every account starts on the default destination, the existing server, and an account receives a mapping to the new destination when it moves.

Without a [mapping] table, every account goes to the default destination, and the mapping views of the web interface and the API report that no store is configured. The store is selected with the source key of [mapping]. This page describes what applies to every store; each store has a page of its own:

  • File: a text file read into memory, with no external dependency, suited to mappings maintained by configuration management or generated by a migration script.
  • Redis: a Redis database, suited to mappings that change often or are shared by several proxies.
  • SQL: a query against PostgreSQL, MySQL or SQLite, suited to deployments where the record of which account lives on which backend already exists in a database.

The general settings are in [mapping], and the connection details of the selected store are in a table of its own:

[mapping]
source = "file"
normalize = "lowercase"
negative_ttl = "30s"
positive_ttl = "10m"
[mapping.file]
path = "/etc/proxy/mappings/mappings.tsv"
KeyDefaultDescription
sourcerequiredfile, redis or sql.
normalizenoneNormalisation of identifiers before lookup: none or lowercase.
positive_ttl600sHow long a lookup that found a mapping is cached.
negative_ttl30sHow long a lookup that found no mapping is cached.
cache_max_entries1000000Maximum number of cached lookups.
cache_max_bytesunsetApproximate memory budget of the cache in bytes; when set, it replaces cache_max_entries as the bound.
lookup_timeout5sTime limit for one lookup in the store.

The destination for accounts without a mapping is routing.default_destination, set in [routing], which a [mapping] table requires:

[routing]
default_destination = "legacy"

The store may return a destination that is not declared in the configuration. The proxy then logs a warning and uses the default destination, so that a stale or mistyped entry cannot send traffic to a backend that does not exist.

Clients present addresses and login names with varying case. With normalize = "lowercase", every identifier is lowercased before it is looked up, and before it is written through the management API. [email protected] and [email protected] then resolve to the same entry. With the default, none, identifiers are compared exactly as presented. Lowercase normalisation is recommended for accounts identified by address.

The stores treat their own contents differently. The file store applies the same normalisation to the identifiers in the file as it reads them. The Redis and SQL stores, however, are queried with the normalised identifier, so with normalize = "lowercase" entries written to them directly must already be lowercase. The normalisation applies to every protocol alike, including the user name of HTTP Basic authentication.

The comparison is exact after normalisation. The proxy relates no bare name to an address, so alice and [email protected] are separate entries.

Lookups are served from an in-memory cache. The store is consulted for an account only on its first connection, and then at most once per cache lifetime. Three kinds of result are cached, each for a different time:

  • A lookup that found a mapping is cached for positive_ttl, 10 minutes by default.
  • A lookup that found no mapping, and therefore uses the default destination, is cached for negative_ttl, 30 seconds by default, so that a newly added mapping takes effect quickly.
  • A lookup that failed, because the store was unreachable or did not answer within lookup_timeout, uses the default destination and is cached for 5 seconds or negative_ttl, whichever is shorter, so that the store is asked again soon after it recovers.

cache_max_entries bounds the memory used, and the cache evicts entries when the limit is reached. Identifiers can be up to 320 bytes long, so a cache full of long identifiers uses more memory than one of short addresses. To bound memory directly, set cache_max_bytes: each entry then counts as the length of its identifier plus 192 bytes of overhead, an upper bound of the memory an entry takes, and entries are evicted when the total reaches the budget. Expired entries count toward either bound until they are evicted. With cache_max_bytes set, cache_max_entries is ignored. A change to either, like any change to [mapping], replaces the cache with an empty one when it is applied.

When several connections for the same account arrive while its entry is missing or expired, the store is asked once and the other connections wait for that answer. If the connection that asked goes away before the store answers, one of the waiting connections asks again.

Caching means that a change in the store is not seen at once. The management API changes mappings and invalidates their cache entries, and the cache invalidation page describes when to clear the cache.

Some servers let an administrator open another user’s mailbox by appending a separator and the administrator’s name to the login. This is known as a master user login. The proxy recognises this form, so that the session is routed by the mailbox being opened rather than by the administrator. master_user_separators in [routing] lists the separators, by default ["%"]:

[routing]
default_destination = "legacy"
master_user_separators = ["%", "*"]

For the login [email protected]%admin, the proxy cuts the identifier at the first occurrence of any listed separator, and routes by [email protected]. The full login, including the suffix, is still passed to the backend for authentication. The suffix is also removed from identifiers extracted from HTTP requests.

At startup, the proxy stops when the mapping file cannot be read, or when the Redis or SQL store cannot be reached.

How far the destinations are checked depends on the store. For the file source, every destination in the file is checked against the configuration at startup and on a configuration reload, while a mapping reload and a mapping written through the interface or the API check only that the destination is declared. The destinations of the Redis and SQL stores are not known in advance. For them, the check that a destination offers the protocol of a connection happens when the connection resolves to it. A mapping that sends an account to a destination without that protocol therefore fails at connection time for that account, not at startup.