# Hardening checklist

> A checklist for people who run a Postern Hub - network exposure, proxies, accounts, keys, systemd and container hardening, firewall, updates and backups.

Source: https://docs.posternmail.app/security/hardening/

This page is for the person who runs a Hub. Work through it after the
[setup](https://docs.posternmail.app/setup/), and again whenever you change how the Hub is reached. Each item says
what to do, why, and how to check it. The background is in the [Security overview](https://docs.posternmail.app/security/).

The short list:

- [ ] Reach the Hub only over HTTPS or your tailnet; never expose plain HTTP.
- [ ] Turn on `POSTERN_TRUST_PROXY` only behind your own proxy, and narrow
      `POSTERN_TRUSTED_PROXIES`.
- [ ] Never run with `POSTERN_DEV`.
- [ ] Every account uses a passkey or TOTP, admins first.
- [ ] Keep registration **By invite** or **Closed**; think before enabling OIDC auto-register
      or link-by-email.
- [ ] Back up the key file apart from the data; consider sealing it.
- [ ] Keep the shipped systemd or container hardening in place.
- [ ] Open only the ports you need.
- [ ] Update regularly.
- [ ] Copy backups off the machine, encrypt the disk, and remember backups when deleting users.
- [ ] Public Hub? Add Cloudflare Access as a second lock. Avoid Tailscale Funnel.
- [ ] Run `postern-hub doctor` after every change.

**Desktop app (built-in Hub):**
> [!NOTE]
> The desktop app's built-in Hub listens only on `127.0.0.1` and can only be used from that
> computer. Most of this list does not apply to it. What does: use a strong account password
> and two-step verification, keep the app up to date, and turn on disk encryption
> (FileVault, BitLocker, LUKS) and a screen lock, because the built-in Hub keeps a plain key
> file next to its data.
**Docker Compose, Debian and Ubuntu, Fedora and RHEL and Raspberry Pi OS:**
The commands below are for your install method. Run CLI commands as shown in the setup guide.

## Reach the Hub only over HTTPS

Session cookies, passwords and mail travel between your apps and the Hub. Over plain HTTP,
anyone on the path can read them. Passkeys and Web Push also need HTTPS.

- Best: keep the Hub off the internet and reach it through Tailscale (see
  [Tailscale](https://docs.posternmail.app/reach/tailscale/)).
- If it must be public: put it behind a reverse proxy with TLS
  ([Reverse proxy](https://docs.posternmail.app/reach/reverse-proxy/)), use Cloudflare Tunnel
  ([Cloudflare Tunnel](https://docs.posternmail.app/reach/cloudflare/)), or let the Hub get its own certificate
  ([HTTPS](https://docs.posternmail.app/reach/https/)).
- Never forward port 8080 from your router to the Hub.
- Set `POSTERN_PUBLIC_URL` to the `https://` address. Without it, invite and pairing links use
  whatever address a browser used.

Check that the Hub itself only listens on the local machine:

**Docker Compose:**
```sh
cd ~/postern && docker compose port hub 8080
```

```text
127.0.0.1:8080
```

If you see `0.0.0.0:8080`, `POSTERN_BIND` in `.env` opens it to the network. Only do that
for LAN use, and see [LAN](https://docs.posternmail.app/reach/lan/).
**Debian and Ubuntu, Fedora and RHEL and Raspberry Pi OS:**
```sh
sudo ss -tlnp | grep postern-hub
```

```text
LISTEN 0  4096  127.0.0.1:8080  0.0.0.0:*  users:(("postern-hub",pid=812,fd=7))
```

If you see `0.0.0.0:8080` or `*:8080`, `POSTERN_LISTEN` in `/etc/postern/hub.env` opens it to
the network. Only do that for LAN use, and see [LAN](https://docs.posternmail.app/reach/lan/).
**Desktop app (built-in Hub):**
Nothing to do: the built-in Hub always listens on `127.0.0.1`.

> **Check:** `postern-hub doctor` shows no warning `POSTERN_PUBLIC_URL is not HTTPS` and
> reports the TLS certificate as valid.

## Trust only your own proxy

Behind a reverse proxy, the Hub sees every connection coming from the proxy. With
`POSTERN_TRUST_PROXY=true`, it reads the real client address from `X-Forwarded-For` (and the
scheme and host from `X-Forwarded-Proto` and `X-Forwarded-Host`), which it needs for correct
rate limits, the security activity log and HTTPS detection.

Those headers are only believed when the connection comes from an address in
`POSTERN_TRUSTED_PROXIES`. The default is loopback plus all private networks
(`127.0.0.0/8, ::1/128, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7`). On a home
network that means any device on your LAN that can reach the Hub could claim to be any
address. Narrow it to the proxy you actually use.

- Without a proxy in front, leave `POSTERN_TRUST_PROXY` off.
- Behind Cloudflare Tunnel, also set `POSTERN_CLIENT_IP_HEADER=CF-Connecting-IP`, so the Hub
  takes the client address from the header `cloudflared` sets.

**Docker Compose:**
`POSTERN_TRUST_PROXY` goes in `~/postern/.env`. `POSTERN_TRUSTED_PROXIES` is not passed
through by compose.yaml, so set it in `~/postern/compose.override.yaml`. A proxy reaches the
container through Compose's network, whose range you can look up:

```sh
docker network inspect postern_default --format '{{(index .IPAM.Config 0).Subnet}}'
```

```text
172.18.0.0/16
```

```yaml
services:
  hub:
    environment:
      POSTERN_TRUSTED_PROXIES: 172.18.0.0/16
```

```sh
cd ~/postern && docker compose up -d
```
**Debian and Ubuntu, Fedora and RHEL and Raspberry Pi OS:**
With the proxy on the same machine, trust only loopback. In `/etc/postern/hub.env`:

```ini
POSTERN_TRUST_PROXY=true
POSTERN_TRUSTED_PROXIES=127.0.0.1/32,::1/128
```

With the proxy on another machine, put its address instead (for example `192.168.1.10`).
Then restart:

```sh
sudo systemctl restart postern-hub
```
**Desktop app (built-in Hub):**
Not applicable. The app sets `POSTERN_TRUST_PROXY=false` for the built-in Hub.

> **Check:** Sign in from another device, then look at **Settings → Security → Recent
> security activity**. The sign-in shows that device's address, not the proxy's.

> **If it did not work:** If every entry shows the proxy's address, trust is off or the
> proxy's address is not in `POSTERN_TRUSTED_PROXIES`. If the Hub keeps redirecting or says
> the connection is not secure, the proxy does not send `X-Forwarded-Proto`.

## Never run in development mode

`POSTERN_DEV` relaxes security checks: outgoing requests may reach private and loopback
addresses, push endpoints may use plain HTTP, and logging becomes verbose. It is for working
on Postern only. Make sure it appears nowhere in your configuration (`.env`,
`compose.override.yaml`, `hub.env`).

## Protect every account

- **Two-step verification for everyone**, admins first: a passkey, or TOTP with recovery
  codes, under **Settings → Security**. Postern has no setting that forces it, so check with
  your users. A passkey is the strongest choice: it cannot be phished.
- **Passwords** are at least 10 characters. Longer and unique is better.
- **New accounts:** keep **Settings → Admin → Your Hub → New accounts** on **By invite** (the
  default) or **Closed**. There is no open sign-up.
- **Admins:** give the admin role only to people who need it. Remember that anyone with
  shell access to the Hub's machine can also run `postern-hub admin disable-2fa` or
  `reset-password`.
- **Remove what is unused:** disable or delete accounts of people who left, and revoke old
  devices in **Settings → Devices**.

### Single sign-on (OIDC)

If you use OIDC (see [Sign-in methods](https://docs.posternmail.app/admin/sign-in/)), two options deserve care:

| Option | Default | Risk |
|---|---|---|
| `POSTERN_OIDC_AUTO_REGISTER` | off | Every user your identity provider lets through gets a member account on the Hub. Only turn it on if the provider's own access policy restricts who can sign in to Postern. |
| `POSTERN_OIDC_LINK_BY_EMAIL` | off | On the first SSO sign-in, an existing Postern account with the same email is linked to that SSO identity. Whoever controls that email address at the identity provider then gets into the account. |

The Hub only links or creates accounts for emails the provider marks as verified
(`email_verified`). It never links an account that is already linked to another identity,
and refuses to link by email for 7 days after an account's sign-in email changed. Still,
only turn on linking if your identity provider does not let users set their own email
address.

## Keep the key file safe

- **Separate from the data.** The key file stays outside the data folder by default. Keep it
  that way.
- **Backed up separately.** Postern's backups never include it. Keep a copy somewhere else,
  for example in a password manager.
- **Readable only by the Hub.** `postern-hub doctor` fails if other users can read it and
  tells you the `chmod` to run.
- **Sealed, if you can type a passphrase on every start.** A sealed key file needs
  `POSTERN_KEY_PASSPHRASE` to start, which protects a stolen copy of the key. See
  [Seal the key file with a passphrase](https://docs.posternmail.app/security/encryption/#seal-the-key-file-with-a-passphrase).
- **Rotate after a suspected leak** with `postern-hub rotate-key`, then remove the old
  `hub.key.bak` from the server. See [Rotate the master key](https://docs.posternmail.app/security/encryption/#rotate-the-master-key).

## Keep the service hardening in place

**Docker Compose:**
`deploy/docker/compose.yaml` already runs the Hub locked down. Keep these settings when you
customize it:

| Setting | Effect |
|---|---|
| `ports: 127.0.0.1:8080:8080` | Published on localhost only (unless you change `POSTERN_BIND`). |
| `read_only: true` | The container's file system is read-only. Only the volumes `/data` and `/key` and the `tmpfs` at `/tmp` are writable. |
| `tmpfs: /tmp` | Temporary files stay in memory. |
| `security_opt: no-new-privileges:true` | No process in the container can gain privileges (for example through setuid). |
| `cap_drop: ALL` | All Linux capabilities are dropped. |
| `USER 10001:10001` (in the image) | The Hub runs as an unprivileged user, not root. |
| Separate volumes for `/data` and `/key` | A copy of the data volume alone cannot be decrypted. |

The Docker daemon itself runs as root, and anyone in the `docker` group can read every
volume. Keep that group small.
**Debian and Ubuntu, Fedora and RHEL and Raspberry Pi OS:**
The unit file `postern-hub.service` already contains these directives. Do not remove them
with `systemctl edit`:

| Directive | Effect |
|---|---|
| `User=postern`, `Group=postern` | Runs as an unprivileged user. |
| `StateDirectory=postern postern-key`, `StateDirectoryMode=0700` | Creates `/var/lib/postern` and `/var/lib/postern-key`, readable only by the Hub. |
| `UMask=0077` | New files are private to the Hub. |
| `NoNewPrivileges=yes` | No privilege gain through setuid and similar. |
| `CapabilityBoundingSet=`, `AmbientCapabilities=` | No Linux capabilities at all. |
| `ProtectSystem=strict` | The whole file system is read-only except the state directories. |
| `ProtectHome=yes` | `/home`, `/root` and `/run/user` are inaccessible. |
| `PrivateTmp=yes`, `PrivateDevices=yes` | Own `/tmp`; no access to hardware devices. |
| `ProtectKernelTunables=yes`, `ProtectKernelModules=yes`, `ProtectKernelLogs=yes` | No changes to kernel settings or modules, no kernel log. |
| `ProtectControlGroups=yes`, `ProtectClock=yes`, `ProtectHostname=yes` | Cannot change cgroups, the clock or the host name. |
| `ProtectProc=invisible` | Other users' processes are hidden. |
| `RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK` | Only the network socket types it needs. |
| `RestrictNamespaces=yes`, `LockPersonality=yes`, `RestrictRealtime=yes`, `RestrictSUIDSGID=yes` | No namespaces, no personality changes, no realtime scheduling, no setuid files. |
| `MemoryDenyWriteExecute=yes` | No memory that is both writable and executable. |
| `RemoveIPC=yes`, `KeyringMode=private` | IPC objects are removed when it stops; private kernel keyring. |
| `SystemCallArchitectures=native`, `SystemCallFilter=@system-service`, `SystemCallFilter=~@privileged`, `SystemCallErrorNumber=EPERM` | Only ordinary service system calls are allowed. |

Two changes are expected and safe:

- Built-in TLS (`POSTERN_TLS_DOMAIN`) binds ports 443 and 80, so it needs
  `CapabilityBoundingSet=CAP_NET_BIND_SERVICE` and `AmbientCapabilities=CAP_NET_BIND_SERVICE`
  (the unit has them as comments).
- A backup folder outside `/var/lib/postern` (`POSTERN_BACKUP_DIR`) needs
  `ReadWritePaths=` for that folder.

Make both with `sudo systemctl edit postern-hub`, so the original unit stays untouched. To
see how systemd rates the result:

```sh
systemd-analyze security postern-hub
```
**Desktop app (built-in Hub):**
Not applicable. The built-in Hub runs as your user, with the app.

## Open only the ports you need

| How the Hub is reached | Open to the internet |
|---|---|
| Tailscale (`tailscale serve`) or Cloudflare Tunnel | Nothing. Both connect outward. |
| Reverse proxy or built-in TLS | 443/tcp, and 80/tcp if the certificate comes from Let's Encrypt over HTTP. Caddy also uses 443/udp for HTTP/3. |
| LAN only | Nothing on the router. 8080/tcp only from your LAN. |

**Docker Compose:**
Ports that Docker publishes bypass `ufw` and `firewalld` rules on many systems, because
Docker writes its own firewall rules. That is why compose.yaml publishes the Hub on
`127.0.0.1` only. The `caddy` profile publishes 80 and 443 on all interfaces; that is
intended. Check what is published:

```sh
cd ~/postern && docker compose ps --format '{{.Service}} {{.Ports}}'
```
**Debian and Ubuntu and Raspberry Pi OS:**
With `ufw` (install it with `sudo apt install ufw` if needed), for a Hub behind a reverse
proxy on the same machine. Allow SSH first so you do not lock yourself out:

```sh
sudo ufw allow OpenSSH
sudo ufw allow 443/tcp
sudo ufw allow 80/tcp
sudo ufw enable
sudo ufw status
```

Leave out 80 and 443 if you use Tailscale or Cloudflare Tunnel.
**Fedora and RHEL:**
With `firewalld` (on by default), for a Hub behind a reverse proxy on the same machine:

```sh
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
sudo firewall-cmd --list-services
```

Leave out `http` and `https` if you use Tailscale or Cloudflare Tunnel.
**Desktop app (built-in Hub):**
Nothing to open. Do not forward any port to the built-in Hub.

## Update regularly

Security fixes only help once they run on your Hub. Postern does not notify you about new
versions yet: watch the [repository](https://github.com/TheOriUHD/postern) (**Watch →
Custom → Releases** and **Security alerts**) and update when something comes out. No
release has been published yet, so for now updating means pulling the source and building
again. See [Upgrades](https://docs.posternmail.app/admin/upgrades/).

Also keep the operating system, Docker and your reverse proxy updated.

## Back up, and protect the backups

- The Hub makes a backup every 24 hours and keeps the last 7 (`POSTERN_BACKUP_INTERVAL`,
  `POSTERN_BACKUP_KEEP`). They are written to `backups/` inside the data folder by default,
  which is on the same disk. Copy them to another machine or service regularly and test a
  restore once. See [Backups](https://docs.posternmail.app/admin/backups/).
- A backup contains `hub.db` with all metadata in clear text (senders, subjects, the search
  index) and the encrypted message files. Store backups where only you can read them.
- Keep the key file out of the backup location, or the separation is lost.
- **Deleting a user** removes their data and their key from the Hub, but older backups still
  hold both. For a complete erasure, for example a GDPR request, delete or let expire every
  backup made before the deletion, including your off-site copies.
- **Disk encryption:** subjects, addresses and the search index are not encrypted by the
  Hub. On a machine that could be stolen (a laptop, a NAS in a shared space, a Raspberry Pi),
  encrypt the disk.

## Add a second lock for a public Hub

### Cloudflare Access

If your Hub is public through Cloudflare Tunnel, put **Cloudflare Access** in front of it.
Then nobody reaches the Hub's sign-in page at all without first passing Cloudflare's check
(an email code or your identity provider for browsers, a service token for the apps). The Hub
hands the service token only to apps that signed in, and a blocked request never signs a
device out. Set it up as described in [Cloudflare Tunnel](https://docs.posternmail.app/reach/cloudflare/), with
`POSTERN_ACCESS_CLIENT_ID` and `POSTERN_ACCESS_CLIENT_SECRET` on the Hub.

`postern-hub doctor` then reports whether the public address is reachable with the apps'
service token.

### Tailscale Funnel: use with care

`tailscale funnel` makes the Hub reachable from the **public internet**, without any lock in
front of it. Prefer `tailscale serve`, which keeps it inside your tailnet. Only use Funnel if
you need public access, every account uses two-step verification, and you keep the Hub up
to date. See [Tailscale](https://docs.posternmail.app/reach/tailscale/).

## Check with the doctor

Run the doctor after every change. It checks file permissions of the data folder and key
file, the database, the key, the public address and its certificate, the clock, the push
relay and single sign-on.

**Docker Compose:**
```sh
cd ~/postern && docker compose exec hub postern-hub doctor
```
**Debian and Ubuntu, Fedora and RHEL and Raspberry Pi OS:**
```sh
sudo -u postern sh -c 'set -a; . /etc/postern/hub.env; exec postern-hub doctor'
```
**Desktop app (built-in Hub):**
Not available from the desktop app. See [Desktop app](https://docs.posternmail.app/apps/desktop/).

> **Check:** No line is marked as a failure, and the warnings that remain are ones you
> understand and accept. See [Doctor](https://docs.posternmail.app/admin/doctor/) for every message.

## If you run a push relay

- Close registration once your Hubs have registered: `RELAY_REGISTRATION=closed`.
- Keep the APNs key and the Firebase service account readable only by the relay.
- Put the relay behind HTTPS.

See [Run your own relay](https://docs.posternmail.app/relay/run-your-own/).
