Installation
Karta ships as a container image built from the Dockerfile in the
repository: an Elixir release on Debian, run by an unprivileged user from a
read-only root. This page covers what the image needs around it. Every
setting is listed in the Configuration reference.
Version 1.0, no published record of production use
Karta 1.0 has run on one staging deployment of its authors and has not yet carried production mail for third parties. Read Status and roadmap before putting real mail through it.
What you need
- Postgres (the development stack and CI use Postgres 17). The first
migration creates the
citextextension, so the database user needs the right to create it, or create it beforehand. - S3-compatible object storage with one bucket for message bodies (Garage, MinIO or AWS S3; path-style URLs).
- A validating DNS resolver that Karta can reach privately, normally
Unbound on the same host or as a sidecar, and
KARTA_DNS_SERVERset to its IP address (the default,127.0.0.1, is the container itself). See DNS resolver. - A reverse proxy that terminates TLS for the HTTP API and for the tracking host.
- A TLS certificate for the SMTP host name (
KARTA_SMTP_HOSTNAME): for applications that submit mail over SMTP, and for STARTTLS on themxlistener, so that other servers can deliver to you over TLS. Without one themxlistener offers no TLS. - For outbound mail: a sending IP address whose reverse DNS (PTR) name is
KARTA_OUTBOUND_HOSTNAME, with port 25 open outbound. - Outbound HTTPS to
publicsuffix.org: every node fetches the Public Suffix List each night (see Configuration). Where nodes have no such access, pointKARTA_PUBLIC_SUFFIX_URLat a mirror, or set it tooffto keep the list Karta was built with.
Build the image
docker build -t karta .
The build uses hexpm/elixir:1.20.5-erlang-29.1.2-debian-trixie-20261104-slim
and runs the release on debian:trixie-20261104-slim (build arguments
ELIXIR_VERSION, OTP_VERSION and DEBIAN_VERSION). The image:
- runs as uid 10001 (user
karta, no shell); - expects a read-only root with a writable
/tmp(RELEASE_TMP=/tmp); - exposes 4000 (HTTP), 9568 (metrics), 25, 587 and 465 (SMTP);
- starts
/app/bin/server, which starts the release withPHX_SERVER=true.
Run the database migrations
Migrations are not run at start. Run them before the first start and after every upgrade, with the same environment as the server:
docker run --rm --read-only --tmpfs /tmp --env-file karta.env karta /app/bin/migrate
bin/migrate runs Karta.Release.migrate/0, which applies every pending
migration of Karta.Repo.
Start the server
A minimal start, HTTP only:
docker run --rm --read-only --tmpfs /tmp -p 4000:4000 \
-e SECRET_KEY_BASE=... \
-e DATABASE_URL=ecto://karta:...@db.example.com/karta \
-e KARTA_VAULT_KEY=... \
-e PHX_HOST=karta.example.com \
karta
SECRET_KEY_BASE: at least 64 random bytes;mix phx.gen.secretmakes one.KARTA_VAULT_KEY: the base64 of exactly 32 random bytes (openssl rand -base64 32). It encrypts secrets at rest and is the root of the keys of stored messages; losing it loses them. Keep it in your secret store and back it up. See Storage, encryption and retention.
Plain HTTP on port 4000 is redirected to HTTPS except for requests whose
host is localhost (see below), so test it from inside the container or
through the reverse proxy.
Decide how people sign in before the first start: set KARTA_OIDC_ISSUER
and the client settings, or KARTA_LOCAL_LOGIN=true
(Sign-in and access). Neither is on by default,
and then nobody can sign in to the admin pages.
For a useful installation, add the message store (KARTA_S3_*), outbound
settings (KARTA_OUTBOUND_HOSTNAME), and optionally the SMTP listeners
(KARTA_SMTP_*) and the tracking host (KARTA_TRACKING_*). Without
KARTA_S3_BUCKET no message can be stored, and every send fails with a
temporary error.
The SMTP listeners and port 25
With KARTA_SMTP_ENABLED=true Karta binds port 25 and, with a certificate,
587 and 465. As uid 10001 it can bind ports below 1024 only with the
container sysctl net.ipv4.ip_unprivileged_port_start=0 or the capability
NET_BIND_SERVICE (--cap-add NET_BIND_SERVICE); never setcap files in
the image. Alternatively set KARTA_SMTP_MX_PORT,
KARTA_SMTP_SUBMISSION_PORT and KARTA_SMTP_SUBMISSIONS_PORT to high
ports and publish them as 25, 587 and 465.
The listeners need a spool directory (KARTA_SPOOL_DIR) for message data
being received. Mount a writable, disk-backed volume there: a tmpfs would
hold whole messages in memory. The root file system stays read-only.
See SMTP listeners for certificates, PROXY protocol and limits.
The reverse proxy
| Public name | Proxied to | Notes |
|---|---|---|
the API and admin host, PHX_HOST (e.g. karta.example.com) | port 4000 (PORT) | send X-Forwarded-For and X-Forwarded-Proto |
the tracking host, KARTA_TRACKING_URL (e.g. track.example.com) | port 4001 (KARTA_TRACKING_PORT) | only if tracking is used; the same headers |
the tracking hosts of sending domains (e.g. click.example.org) | port 4001 (KARTA_TRACKING_PORT) | certificates on demand or from Karta's Traefik files (Certificates for tracking hosts) |
| none | port 9568 (METRICS_PORT) | keep it on the internal network |
- Set
KARTA_TRUSTED_PROXIESto the proxies' addresses (CIDR ranges, comma-separated, e.g.10.0.1.0/24,fd00:1::/64). Karta believesX-Forwarded-ForandX-Forwarded-Protoonly from them: the client's address is the rightmost one inX-Forwarded-Forthat is not a trusted proxy. Without the setting every request seems to come from the proxy, so all clients share the limits per client.X-Forwarded-Hostis never read. - In production both endpoints redirect plain HTTP to HTTPS and send
Strict-Transport-Security(one year). A request from a trusted proxy withX-Forwarded-Proto: httpscounts as HTTPS. Requests with the hostlocalhostor127.0.0.1are exempt, so a health check inside the container (http://localhost:4000/health) works, and so is the reverse proxy's question/tls/askon the tracking endpoint. PHX_HOSTis the name Karta uses in URLs it writes (for example the paging links of the Mailgun-compatible API). Set it to the public API host name; the default isexample.com.- The raw sends (
POST /api/v2/messages/raw,POST /kantoor/v1/messages/raw) carry a whole message as base64 in JSON, so a request body may have up to 37,049,688 bytes (about 35 MiB); every other API body has at most 8,000,000. Allow that size on the proxy (for example nginxclient_max_body_size 36m, TraefikmaxRequestBodyBytes), and give it a read timeout long enough for a slow upload: Karta reads a body in pieces with Plug's 15 second timeout per read. - Both HTTP endpoints bind all IPv6 and IPv4 addresses (
::). - The admin pages are LiveView: the proxy must pass WebSocket upgrades
(
/live/websocket). The page falls back to long polling when a WebSocket does not connect; with several replicas that needs a proxy that keeps a client on one replica or the replicas in a cluster (KARTA_CLUSTER, see Running several replicas). - Users sign in at
https://<PHX_HOST>/login; see Sign-in and access.
Remote console
Organisations, servers, domains and keys are managed in the admin pages; the same can be done from a remote console on a running node (and the first administrator is made from the command line, see below):
docker exec -it <container> /app/bin/karta remote
See Managing organisations, servers and keys.
Several nodes
Several nodes can run against the same database and bucket. Delivery jobs are spread over all nodes by Oban; retention and the sweep are safe to run on several nodes at once. Things to know:
- Rate limits that guard an account or a credential are counted in the
database (
Karta.Limits), so they hold across all nodes: each API key's requests, each SMTP credential's messages, login attempts per address and per client, TOTP codes, and API key verifications per client. Two nodes do not allow twice the limit. A counter that cannot be read refuses the event rather than letting it through: an API request answers429, an SMTPMAILa temporary failure, and the sign-in form its "too many attempts" answer. The API key cache stays per node: a key verified on one node is verified again on another, and the verification limit is shared. - What is counted per node, and why spreading requests over nodes cannot
evade it:
- Connections: a TCP connection is open on one node, and each listener counts its own clients and protects its own sockets. Spreading connections over nodes uses the operator's own capacity; no node is relieved of its own limit.
- The outbound throttle (
Karta.Outbound.Throttle): a destination counts connections and messages from the sending address it sees. A pool's address is held by one node at a time, so its limits hold wherever it sends from; without a pool each node sends from its own address. More nodes add sending addresses, which is the operator's own pool, not a way round a limit. - Warm-up (
Karta.Outbound.Warmup): an address's count for the day is in the database and locked, so jobs on any number of nodes never pass it together; what a node holds is the reservation of the run it is sending, and the units it did not use are given back.
- Clustering is optional: nothing in Karta needs it for correctness, since
every claim (deliveries, webhook deliveries, report runs, rate limits,
warm-up) is made in the database, and the announcements the admin pages
and the route cache need reach every replica through the database. See
Running several replicas for what each replica keeps, what
happens when one is stopped or killed, and the cluster (
KARTA_CLUSTER). - Behind pgbouncer in transaction mode, set
KARTA_DATABASE_POOLER=pgbouncer: prepared statements become unnamed, and Oban's notifier switches toOban.Notifiers.PG, which needs the nodes clustered (KARTA_CLUSTER, withKARTA_CLUSTER_DATABASE_URLfor a direct connection).
Several replicas
The cluster, node names, the cookie and the ports have their own page:
Running several replicas. Examples for Kubernetes and Docker
Compose are in deploy/examples/.
Check the cluster from any replica's remote console (bin/karta remote):
Node.list() shows the others. A replica that cannot reach them still works
alone; GET /readyz does not depend on the cluster.
Sending addresses are not shared between nodes unless you make them so: give each node its own address, or use an IP pool whose address moves between nodes.
After installing
- Check
GET /readyz(Monitoring). - Make the first administrator, who alone can create organisations
(The first administrator),
for example with local login:
docker exec <container> /app/bin/karta eval 'Karta.Release.local_user("ann@example.com", admin: true)', which prints a password; sign in athttps://<PHX_HOST>/login. - Create the first organisation, server, domain, DKIM key and credentials (Managing organisations, servers and keys).
- Publish the DNS records (Domains and DNS); to receive mail, also the MX record and the settings in Receiving mail.
- Read Security model for hardening notes, and, before you rely on the installation, Upgrades and backups.