Skip to content

Securing the archive#

This documentation applies to Piler enterprise edition 2.0.0

Revision #2

Publication date: 2026-NOV-12

Single node layout#

The piler node should be accessed on port 443 from the Internet. Port 25 should be limited to your mail servers, also see the SMTP ACL feature below.

Multiple nodes layout#

UI node ports accessibility:

  • tcp/443: from the Internet
  • tcp/3306: from the worker nodes

The worker nodes ports accessibility:

  • tcp/25: only the MX server
  • tcp/80,443: only the UI node
  • tcp/9312: only the UI node

MX server ports accessibility:

  • tcp/25: only from your mail servers

It's also possible to use an internal network where the worker nodes' ports and the UI node mysql port are available.

STARTTLS support#

By default the installer creates a key and a self-signed certificate (/etc/piler/piler.pem) to support STARTTLS providing encrypted message transfer between the smtp client and the Piler smtp server. You are free to fix piler.pem to use your signed CA.

SMTP ACL lists#

Piler supports an smtp acl list similar to postscreen. See https://mailpiler.com/blog/smtp-acl-list for more.

Two-factor authentication (TOTP)#

A user may protect the local login with a TOTP code of an authenticator app (Settings > Authenticator settings: Refresh QR code, scan it in the app, then Enabled; ENABLE_AUTHENTICATOR, on by default). The login also accepts one of the user's backup codes, each of them once.

The TOTP setting belongs to the account, not to an address: a user with more addresses (e.g. alice@ and a.smith@) is asked for the same code whichever of them is typed at the login. The same goes for the profile assigned to the user and the other personal settings. Up to 2.3.2 they were stored per address, so a login with another address skipped the TOTP; the 2.3.3 migration (035) merges them into one row per account, keeping the one with TOTP, and deletes the backup codes of the others.

From 2.3.3 the REST login (POST /auth/login) asks a TOTP user for the code too: it answers 401 {"error": "totp required"} to the password alone (only after a correct password), and issues the tokens when the request has the code as totp_code. See REST API.

The password is a session too: a POST /auth/login with the password of an admin without TOTP returns an access token, and the admin API takes it like any admin's: it can add and change users and set their passwords. The rules of the personal API tokens don't apply to it. So for an admin account, TOTP is what keeps a leaked password from managing users: turn it on for every admin account.

Brute force protection: a code is accepted once, and 5 codes without a success lock the TOTP of the user, on the web login and the REST login alike. While it's locked every code is refused, a valid one too, with the same answer as a wrong code. The lock ends when 15 minutes pass without an attempt. The first refusal is in the audit log as totp_locked, the wrong codes as failed logins.

The trade-offs:

  • The lock is per user (all of their addresses), not per IP: more IPs or addresses don't help an attacker, but the attempts of anyone count for the user.
  • Each attempt restarts the 15 minutes, so somebody who keeps trying keeps the user locked out. Only somebody who has the password gets to the TOTP step: a totp_locked event in the audit log means the password is known, so change it.

Lost authenticator: a user who lost the phone and the backup codes asks an admin. From 2.3.3 Users has a Reset TOTP button for the users with TOTP (or POST /api/v1/admin/user/totp-reset with the uid; not with a personal API token). It turns TOTP off, removes the secret and the backup codes, and lifts the lock: the user signs in with the password, then turns TOTP on again with a new QR code. The reset is in the audit log as totp_reset. Before resetting, make sure the request comes from the user (e.g. a call back on a known number): whoever has the password and gets the TOTP reset can sign in. - The attempts are counted in Redis. If Redis is down, no TOTP code is accepted (the login fails closed). - Scripts can't type a TOTP code: from 2.3.3 they use a personal API token (below); up to 2.3.2, run them as a user without TOTP, with a strong password and the least role they need.

Personal API tokens#

From 2.3.3 scripts use personal API tokens instead of a password, see REST API. A token stands for its user, so treat it like a password:

  • Give the least scope and the shortest expiry that work: a read only token can't change anything or reach the admin API.
  • Restrict where it's used from: the tokens of the admin, auditor and data officer roles must have allowed addresses (at most a /16, IPv6 /48 each), and a regular user may add them too. A request from elsewhere is refused and logged as api token refused in the audit log, the sign of a leaked token: revoke it. Behind a reverse proxy, set TRUSTED_PROXIES or every request comes from the proxy's address.
  • A leaked admin token is a leaked admin account, less the users it can add: a full-scope admin token can still use the admin API, but it can't add a user, set a user's password or role, reset a TOTP or create tokens, and it can't add a passkey. From 2.4.0, the admin UI makes those changes; a token can't, so a leaked one can't provision a user who signs in without TOTP. Give admin tokens the read scope unless a script must change something, and the narrowest allowed addresses (the script's host, not a /16). If one leaks, revoke it at once in Users > API tokens and check the audit log: every admin API change made with it is an admin api entry with the token in the details, next to the user_create or user_update entry of the change. Before 2.4.0 a full-scope admin token could add users and set their passwords: for a token that was used on an older version, remove the users it added and reset the passwords it set.
  • Revoke the tokens of a leaving user, and of a user whose role or groups change. Removing a local user, or setting their new password, revokes their tokens, and a local user's token stops at once when their role changes. A user who logs in through LDAP, IMAP, POP3 or SSO (Entra ID, Google, SAML, ...) is different: their token keeps the role and groups of the login that created it, and keeps working after the account is disabled in the directory or moved to another group there, until it expires. A new login doesn't revoke it either: piler doesn't ask the directory between logins. Revoke the tokens of such a user in Users > API tokens when they leave or when their role or groups change, and keep the expiry short with PERSONAL_API_TOKEN_MAX_DAYS.
  • Turn them off where no scripts are needed: PERSONAL_API_TOKENS=false for the tenant.

Managing users#

With a directory (LDAP, AD, Entra ID, Google, SAML or OAuth), create, change and remove the users in the directory. piler takes a user from the directory at their login, and the local user table has no row for them. Scripts that manage users belong in the directory's own tooling.

Local accounts are created and changed in the UI. A personal API token can't add a user, set a password or set the admin role from 2.4.0. A script can still do it with an access token from POST /auth/login: for an admin without TOTP, with the password alone; for an admin with TOTP, only if the script sends the totp_code, which means the script holds the authenticator secret or the backup codes. Either way the script holds a credential that can manage users, so store it as carefully as a token and accept that risk knowingly. Keep the installer's admin account (admin@local) for emergencies, with a strong password and TOTP.

Antivirus and antispam support#

Piler expects clean emails only. Spam and other malware occupy valuable disk space and other resources on the piler host, not to mention that it might pose other problems. So you should do the heavy lifting of scanning and filtering of any spam and malware on your MX servers.

However, Piler is able to use the result of any antispam application, provided that it sets a specific email header to mark spam emails. If you used SpamAssassin, then you may use the following setting in /var/piler/.env, then piler can recognize when it receives a spam:

SPAM_HEADER_LINE=X-Spam-Flag: YES

If piler recognizes a spam, then you may set an exlusion rule to discard it (preventing from getting to the archive) or archive it for a shorter time, eg. 30 days or so.

Note that piler supports a single spam header line, ie. you cannot specify the anti-spam headers of several anti-spam products. However, by using an SMTP it’s possible to rewrite several kind of antispam headers to a unified value. See consolidating several anti spam message headers on the smtp gateway for more.