Password reset and per-vhost SMTP: from the command to the new password
Was this useful?
0 unique visitors
One ProxyAuth instance can protect grafana.company.com and
portal.customer.tld side by side — different teams, sometimes
different companies. A password-reset email is one of the few places
that separation shows up in what a person actually receives: the sender,
the mail server, the credentials behind the send, and the page the link
opens.
Two flows, one destination
Both end on page_change_password with a single-use token appended.
Admin-initiated:
proxyauth reset-password --username alice --vhost portal.customer.tld
A link is generated and emailed. Alice’s current password keeps working until she follows the link and sets a new one. This does not lock her out; it gives her a way back in without the old password.
Forced on first login: an account with must_change_password: true
— typically right after an admin set a temporary password — is sent to
the reset page on its next successful login instead of receiving a
session. In cookie mode that is a redirect; in API mode /auth returns
{"must_change_password", "reset_link"}. The flag clears as soon as a
new password is set.
proxyauth db-add-user --username bob --must-change-password \
--email bob@customer.tld --primary-email bob@customer.tld
Resolution per vhost
smtp and page_change_password are two of the nine per-vhost
overrides. Resolution: the route’s value, then its vhosts: group, then
config.json.
vhosts:
- vhost: ["portal.customer.tld"]
page_change_password: "https://portal.customer.tld/new-password.html"
smtp:
host: "smtp.customer.tld"
port: 587
username: "noreply@customer.tld"
password: "..."
from: "Portal <noreply@customer.tld>"
timeout_secs: 10
smtp is a whole-object replacement, not a field-by-field merge. A
vhost that sets it must set host, port, username, password,
from and timeout_secs together. Partially inheriting an object that
contains credentials is exactly how mail ends up going out through the
wrong account.
Why –vhost must be named
A live request carries a Host header, and that is how everything else
resolves “which vhost”. A command in a terminal has no request to read.
So reset-password uses the named vhost’s smtp and
page_change_password, or the global ones if --vhost is omitted.
Everything is checked before anything is sent
The command verifies, up front and together:
smtpis configured for the resolved scope;page_change_passwordis configured;- the account exists;
- it has an email on file — the primary address is the recipient.
Every problem found is reported in one run, not one per attempt.
Transport: the port decides
| Port | Mode |
|---|---|
465 | implicit TLS from the first byte (SMTPS) |
| anything else | STARTTLS after the greeting — the path 587 takes |
There is no separate encryption setting. Credentials are always sent;
username and password are not optional. timeout_secs bounds the
whole exchange.
The template
/etc/proxyauth/mail/templates/reset_password.txt
The path is fixed. proxyauth prepare creates it with default content
only if it does not already exist — an edited template is never
overwritten, including by a later prepare or an upgrade. It is read
once when the SMTP client is built, so an edit applies to the next run
of the command. Format is text/plain; there is no HTML variant.
Subject = "Reset your Portal password"
Hello {{ username }},
A password reset was requested for your Portal account.
Set a new password here:
{{ reset_link }}
This link works once and expires in one hour.
If you did not ask for this, ignore this message — your current
password keeps working.
— Customer Portal
Two parser rules:
- Line one is the subject, exactly
Subject = "…"with double quotes. It is stripped from the body. Anything else fails with the reason named, and nothing is sent. - Placeholders are matched only in their spaced form.
{{ username }}is substituted;{{username}}stays literal. This differs from HTML tags, which accept both.
{{ reset_link }} is page_change_password with token=<token>
appended — joined with ?, or & if the URL already has a query
string. Keep it in the body, or the recipient has nowhere to go.
The template is global today, even though the transport is per vhost.
The directory is organised per purpose, so per-vhost templates fit the
layout later; for now, write wording that suits every tenant, or name
the product through the from display name.
After editing, send yourself one:
proxyauth reset-password --username you --vhost portal.customer.tld
The page behind the link
page_change_password is your page. It receives ?token=… and must
post back to ProxyAuth:
<form method="POST" action="/reset-password">
<input type="hidden" name="token" id="token">
<input type="password" name="password" autocomplete="new-password">
<input type="password" name="verif_password" autocomplete="new-password">
<button type="submit">Set password</button>
</form>
<script>
document.getElementById('token').value =
new URLSearchParams(location.search).get('token') || '';
</script>
POST /reset-password is authenticated by that token, not by the admin
token — public by necessity.
What the link is worth
| Property | Value |
|---|---|
| lifetime | one hour, identical for both flows |
| use | single — validated and deleted in one LMDB read-write transaction, so two simultaneous submissions cannot both succeed |
| storage | its own LMDB environment at /opt/proxyauth/db/password_reset, forced to 0700 |
| purge | hourly sweep; expired tokens are refused on lookup anyway |
The atomic consume exists because a real race was found there: two concurrent submissions of the same token could both pass. The same fix was later applied to OIDC authorization codes.
What does not exist yet
There is no self-service “forgot password” button that triggers an
email from a login page. Resets are started by an administrator, or
forced by must_change_password.
Different domains, different senders, different mail servers — resolved like every other per-vhost setting, checked in full before anything leaves, and backed by a one-hour, single-use link stored apart from everything else.