Also see the dedicated surgemail.com website with knowledge base and ticketing system

Web Admin Login and Security

SurgeMail's web admin interface (the "manager", /cgi/admin.cgi on the admin port) has a new login system. Admins log in with a form, get a session that times out, can log out, and can protect their login with multifactor authentication (MFA) using an authenticator app. Pages and links carry a security token, so another web site, email or chat message can't make the manager do things on an admin's behalf.

Both the older frames layout and the modern layout work the same way.

What changes for admins

 Old loginNew login
Logging inThe browser's password prompt (HTTP Basic).Always a login form. The browser password prompt is no longer accepted, except for scripts from addresses you list.
Staying logged inThe browser kept sending the password with every request until it was closed.A session that ends after 30 minutes without activity, or 12 hours at most.
Logging outNot possible, short of closing the browser.A Logout button.
MFANot available for the manager.Optional per admin, or compulsory for all admins.
Scripts using admin.cgiWorked from any address with a username and password.Work from the addresses listed in g_admin_relax_ip.

If a site really can't change straight away, the old behaviour can be brought back (see Going back to the old login), but that isn't recommended.

Logging in and out

Open the manager as usual. You get a login page asking for an admin username and password (the same admin accounts as before). After logging in you land on the manager front page.

To log out, use the Logout button:

  • Modern layout: on the front page, under Config Checker, and on the Status page next to Web Sessions.
  • Frames layout: under Manager info in the left-hand panel.

A session ends by itself after a period without activity, or after a fixed maximum time, whichever comes first. It is also tied to the IP address you logged in from, so a stolen session cookie can't be used elsewhere. Sessions are kept in memory, so restarting SurgeMail logs everyone out. In a cluster each server has its own sessions.

g_admin_session_timeMinutes without activity before the session ends (default 30).
g_admin_session_lifeMaximum session length in hours, however active (default 12).
g_admin_session_ip_relaxDon't tie sessions to the login IP address. Only needed if admins' addresses change while they work, e.g. on mobile networks or behind several proxies.

Multifactor authentication (MFA)

MFA adds a second step after the password: a 6 digit code from an authenticator app on the admin's phone (e.g. Google Authenticator, Microsoft Authenticator or Authy). Even if the password is guessed or stolen, nobody can log in without the phone.

Setting it up

Until an admin has MFA, the manager front page shows a red line "Multifactor authentication (MFA) is not set up for your admin login" with two links:

  • Set up MFA sets it up for your own admin login. Scan the QR code with your app (or type in the key shown under it) and enter the code the app shows. The app lists it as SurgeMail Admin: username.
  • Enable for all admins takes you to the setting that makes MFA compulsory (see below).

The same setup page is in the Manage menu (modern layout) and under Value added features (frames layout) as MFA setup. From there an admin can also set MFA up again with a new phone, or turn it off by entering a current code.

From then on, every login asks for a code after the password. Ticking Trust this browser for 30 days skips the code on that browser for 30 days; the password is still needed every time. Setting MFA up again, turning it off or resetting it forgets all browsers that admin trusted.

Requiring MFA for all admins

Set g_admin_mfa_require (Security settings, Management section, or the Config Checker's recommendation). Admins who already have MFA notice no change. An admin without MFA is taken to the setup page right after the password at their next login and can't get in until it is done, so nobody is locked out by turning it on. While it is set, admins can't turn their own MFA off.

Lost phone

Reset the admin's MFA from the server:

   tellmail admin_mfa_reset adminuser

The admin can then log in with just the password and set MFA up again (straight away if g_admin_mfa_require is set). The code page shows this command after a few wrong codes, as a reminder.

Admin MFA is separate from user MFA: users set up their own in SurgeWeb or the user self management pages, controlled by the g_pass_twofactor and g_mfa_* settings.

Scripts and the API

Scripts that call admin.cgi with a username and password (HTTP Basic, e.g. curl -u) keep working only from the addresses listed in g_admin_relax_ip. List just the machines the scripts run on, e.g. 127.0.0.1, and use https where you can. These logins skip the login form and MFA, so keep the list short. A * entry isn't accepted. Each such login is logged for auti trail purposes.

Similar lists exist for other kinds of login. They are separate on purpose, so allowing one doesn't open the others:

SettingForEffect
g_admin_relax_ipScripts using admin.cgiPassword only: no login form, MFA or page token.
g_user_relax_ipScripts using user.cgiNo MFA code for user.cgi logins; the password is still needed.
g_pass_twofactor_bypassIMAP, POP, SMTP and SurgeWebNo MFA code for those logins; the password is still needed.

Links into the manager

Every page the manager sends carries a security token that is unique to your session, and the manager only runs a command if the request carries it. The manager's own pages, links and forms always do, so normal use isn't affected.

A link that comes from anywhere else, such as an email, a chat message, a bookmark or another web site, doesn't have the current token. If it would run a command, you get a Please confirm page that names the command instead. Choose Continue only if you meant to do it. Plain pages (the front page, or the manager with no command) open without asking. A form posted from outside the manager is refused.

The manager also refuses commands that the browser reports as coming from another web site. If you run the manager behind a reverse proxy under a different host name, list that name in g_csrf_allow.

Who can reach the manager

g_admin_ip limits which IP addresses can use the manager at all. It now applies to every kind of admin login, form and script alike.

After repeated wrong passwords or MFA codes from one address (7 by default, set with g_admin_guesses), that address is blocked for some hours after its last failed attempt. Restarting SurgeMail clears the block.

g_admin_localhost_unsafe (formerly g_admin_localhost) gives full admin access with no login at all to any connection from the server itself. That includes every program and user on the machine, and anything that forwards connections from it, such as a reverse proxy or SSH tunnel. The old setting no longer works and new installs no longer turn it on. We don't recommend using it.

Custom templates

The login and MFA pages are built into SurgeMail, so they work whatever templates you use. To customise them, the templates are manager_login.htm, manager_mfa.htm, manager_mfa_setup.htm and manager_mfa_done.htm, with shared styling in manager_login_style.htm. They are used only when manager_login.htm contains its version marker line, so an outdated copy can't break logins.

The older admin_login.htm template is only used with g_admin_login_revert.

Going back to the old login

g_admin_login_revert brings back the old behaviour for the whole manager: the browser password prompt is accepted from any address, without MFA. The settings g_admin_login and g_admin_login_ip then work as they used to, and a site's own admin_login.htm is used if there is one.

This is meant only for a site that is stuck. While it is on, SurgeMail logs a warning at startup and shows one on the manager front page. For scripts, list their addresses in g_admin_relax_ip instead: that keeps the rest of the manager protected.

Quick reference

To…Use
Require MFA for all adminsg_admin_mfa_require
Reset an admin's lost MFAtellmail admin_mfa_reset adminuser
Change session timeoutsg_admin_session_time, g_admin_session_life
Allow changing admin IP addresses during a sessiong_admin_session_ip_relax
Let scripts use admin.cgig_admin_relax_ip
Let scripts use user.cgi without MFA codesg_user_relax_ip
Limit which addresses can use the managerg_admin_ip
Change the failed login limitg_admin_guesses
Use the manager behind a reverse proxyg_csrf_allow
Go back to the old login (not recommended)g_admin_login_revert