Table of contents
TOTP (2FA) Enrollment & Reset — Admin Guide
This page explains how TOTP (Time-based One-Time Password) enrollment and reset work in ProxyAuth, and why login takes effect immediately after either action without restarting the service.
Overview
Enrollment and reset both work for either kind of account ProxyAuth supports — a user hand-written into config.json, or one added via db-add-user and living in PostgreSQL/MySQL (see Database-Backed Users) — through the same two routes, /adm/auth/totp/get and /adm/auth/totp/reset. Which storage a given account actually uses is detected automatically: config.json is tried first, and a database lookup only happens if the user isn't found there.
The two storage backends keep the running server in sync with what just got written in two different ways, because they start from two different problems:
| Account type | The problem | How it's solved |
|---|---|---|
| File-based | AppState.config (including users) is loaded once into memory as an immutable snapshot. Writing a new otpkey to config.json on disk doesn't, by itself, change what the already-running server sees. |
An in-memory overlay, AppState.otp_overrides, checked before the snapshot at both login and re-enrollment time. |
| Database-backed | The database itself is always the live source of truth, but ProxyAuth still keeps its own in-memory mirror (db_users) for speed — writing straight to the database wouldn't update that mirror on its own either. |
The mirror is refreshed for that one user immediately after the write (upsert_db_user_now), no overlay needed — unlike the file case, this mirror is supposed to be mutable, so there's no separate bridge to build. |
Either way, without this immediate refresh, every enrollment or reset would only take effect after the next restart (file-based) or the next periodic full sync (database-backed) — both far too slow for a security-relevant change like this.
flowchart TD
A(["Enrollment / reset request"]) --> B{"Found in<br/>config.json?"}
B -->|yes| C["Write config.json,<br/>update otp_overrides"]
B -->|no| D{"Database<br/>configured?"}
D -->|yes| E["Write to the database,<br/>refresh db_users,<br/>patch the LMDB fallback cache"]
D -->|no| F(["Error: user not found anywhere"])
C --> G(["Change is live immediately —<br/>no restart needed"])
E --> G
classDef edge fill:#eef2ff,stroke:#4f46e5,stroke-width:1px,color:#1e1b4b
classDef step fill:#f8fafc,stroke:#64748b,stroke-width:1px,color:#0f172a
classDef decision fill:#fef3c7,stroke:#d97706,stroke-width:1px,color:#78350f
classDef done fill:#dcfce7,stroke:#16a34a,stroke-width:1px,color:#14532d
classDef error fill:#fee2e2,stroke:#dc2626,stroke-width:1px,color:#7f1d1d
class A edge
class C,E step
class B,D decision
class G done
class F error
At login, the same resolve_otpkey function is consulted for both account types — it checks otp_overrides first, and falls back to whatever's on the User record combined_users() returned for this request. For a file-based account, that fallback is the (possibly stale) startup snapshot, which is exactly why the overlay exists. For a database-backed account, combined_users() already reflects the freshly-refreshed db_users mirror directly, so the fallback value is never actually stale in the first place — there's nothing for an overlay entry to override.
Scope note: the overlay only covers the
otpkeyfield for file-based accounts. Any other change made directly toconfig.jsonwhile the service is running (passwords, roles, routes, etc.) still requires a restart to take effect. Database-backed accounts don't have this limitation forotpkeyspecifically, since their in-memory mirror is designed to be refreshed in place.
The LMDB fallback cache (database-backed accounts only)
Database-backed accounts have a third layer behind the two above: a local LMDB cache (see Database-Backed Users § Local cache) that stands in for the real database if it's ever unreachable — most importantly, right at startup. This cache is only a resilience fallback, not part of the normal read path, so it isn't involved in a login at all as long as the database is reachable. But an enrollment or reset does patch it immediately alongside the real database write, specifically so that a database outage occurring shortly afterward can't cause ProxyAuth to fall back to a stale cached secret — the change is reflected there too, not just in the live database and the in-memory mirror.
1. Enrolling a user (first-time setup)
Endpoint: POST /adm/auth/totp/get
Body:
{
"username": "alice",
"password": "alice-current-password"
}
What happens:
- The password is verified.
- If the user has no OTP secret yet, a new one is generated and written wherever the account actually lives —
config.jsonand the in-memory overlay for a file-based account, or the database, its in-memory mirror, and the LMDB fallback cache for a database-backed one (see Overview above). - The response contains the secret and an
otpauth://URI (for a QR code) so the user can add it to their authenticator app.
Response (200 OK):
{
"otpauth_uri": "otpauth://totp/ProxyAuth:alice?secret=...&algorithm=SHA512&digits=6&period=30",
"otpkey": "JBSWY3DPEHPK3PXP..."
}
If the user already has a secret, the endpoint refuses to hand it out again:
Response (409 Conflict):
OTP is already enrolled for this account. Ask an administrator to reset it
if you need to re-provision your authenticator app.
This is intentional: an already-provisioned secret must never be re-disclosed on password alone, or the password would become a way to bypass the second factor. (A specific vhost can opt out of this restriction — see § 4 below — but that's a deliberate, narrow exception, not the default.)
The user can log in with their new TOTP code immediately — no restart needed.
2. Resetting a user's OTP (lost device, suspected compromise, botched enrollment)
Endpoint: POST /adm/auth/totp/reset
Auth: requires the admin token, sent as X-Auth-Token: <token_admin> — same header used by /adm/revoke and /adm/logs.
Body:
{
"username": "alice"
}
What happens:
- The admin token is checked (constant-time comparison).
- The user's
otpkeyis cleared wherever the account actually lives —config.jsonfor a file-based account, or the database (plus its in-memory mirror and the LMDB fallback cache) for a database-backed one — the same file-then-database lookup enrollment itself uses, so this works for either kind of account without needing to know in advance which onealiceis. - Whichever in-memory state applies is updated at the same time, so the old secret stops working immediately — this matters most for the compromise case: if you don't trust the old secret anymore, you need it invalidated right now, not after the next deploy/restart/periodic sync.
Response (200 OK):
OTP key cleared for 'alice'. They can now re-enroll via /adm/auth/totp/get.
Response (404/500 on failure): if alice isn't found in config.json or the database (a typo'd username, or no database is configured at all when the file lookup also comes up empty), the real underlying error is logged server-side and a generic failure is returned — same principle as the rest of ProxyAuth's admin routes, where you get the detail in the logs, not necessarily verbatim in the response.
After a reset, the user goes through enrollment again (step 1) to get a new secret.
3. Quick reference: doing a full reset-and-reenroll
# 1. Admin resets the compromised/lost key
curl -X POST https://proxy.example.com/adm/auth/totp/reset \
-H "X-Auth-Token: $ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '{"username": "alice"}'
# 2. User (or admin on their behalf) re-enrolls
curl -X POST https://proxy.example.com/adm/auth/totp/get \
-H "Content-Type: application/json" \
-d '{"username": "alice", "password": "alice-current-password"}'
# 3. Alice scans the returned otpauth_uri / QR code into her authenticator app,
# and can log in with the new code right away.
No service restart is required at any point in this flow.
4. Skipping the admin step entirely (allow_totp_reenroll)
⚠️ A real security trade-off — read this before using it.
The whole two-step flow above (admin reset, then user re-enrolls) exists because /adm/auth/totp/get normally refuses to hand out a new secret to an account that already has one — even with the correct password — specifically so that a stolen password alone can't be used to silently take over someone's second factor. allow_totp_reenroll: true on a vhosts: entry in routes.yml removes that restriction for that vhost: a user with a working username/password can get a brand-new TOTP secret in one request, no admin involvement, no /adm/auth/totp/reset call needed first.
vhosts:
- vhost: ["internal-tool.example.com"]
allow_totp_reenroll: true
With this on, step 1 above (the admin's curl -X POST .../adm/auth/totp/reset) is skipped — the user just calls /adm/auth/totp/get directly, the same request as first-time enrollment, and gets a fresh secret even though they already had one.
Understand what this costs you: TOTP stops protecting against a stolen or guessed password the way two-factor authentication is meant to, for any account on a vhost where this is on. Whoever currently holds the password also controls the second factor — they can silently re-enroll their own authenticator app, and the legitimate user's old one just stops working with no built-in notification. This is a deliberate, narrow exception meant for specific low-stakes vhosts where the operational cost of admin-mediated resets outweighs the reduced protection — not a general convenience default. See routes.yml Reference § Self-service TOTP re-enrollment for the full field reference.
FAQ
Q: If the service restarts right after an enrollment or reset, is the change lost?
No, for either kind of account. A file-based account's write to config.json on disk happens before touching the in-memory overlay, so the persistent state is always correct — the overlay just bridges the gap until the next restart re-reads the file. A database-backed account's write goes to the database itself first, which was already the persistent source of truth before ProxyAuth's own in-memory mirror gets refreshed to match.
Q: What about a database-backed account — does the same immediacy apply?
Yes. The real database write happens first, then the in-memory mirror (db_users) is refreshed for that one user immediately, and the LMDB fallback cache is patched too — see Overview above for why database-backed accounts need a third layer (the fallback cache) that file-based ones don't.
Q: Does this affect anything other than TOTP secrets?
No. Any other in-place edit to config.json (e.g. manually adding a user, changing a password hash) still requires a service restart to take effect — same for a direct database edit made outside ProxyAuth's own routes, which won't be reflected until the next periodic sync. Only otpkey changes made through /adm/auth/totp/get/reset are hot-reloaded, because those are the only ones currently exposed through an API route with this immediate-refresh behavior built in.
Q: Is /adm/auth/totp/reset rate-limited?
No — it's protected only by the admin token, consistent with /adm/revoke and /adm/logs, which also aren't currently rate-limited. Treat the admin token with the same care as a root credential.
Q: Is /adm/auth/totp/get rate-limited when allow_totp_reenroll is on?
No differently than it already is without it — the username/password check itself is the same constant-time credential verification used everywhere else in ProxyAuth, with the same IP-allow-list check. allow_totp_reenroll only changes what happens after a correct password is supplied to an already-enrolled account; it doesn't loosen anything about verifying the password itself.
📖 Wiki Home · 💻 Source Code · 🐛 Report an Issue · 📜 License
Found an error or something outdated on this page? Open an issue or submit a PR against the wiki repository.