Skip to content

About

Self-service password reset and mailbox admin web UI for the ulaknode mail server, in a small Docker container.

Topics

Resources

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

Ulaknode sidecar web interface

This workspace contains a lightweight Flask app that provides two interfaces for the Ulaknode project:

  • Password reset/change for end users — enter an email, get an emailed reset link (single-use, expires in 30 minutes), set a new password.
  • Admin panel (password-protected) — look up a mailbox by email to see its current settings (maildir, quota), then reset its password to a generated temporary one or set a new quota.

This app holds no local copy of mailbox state — every read and every mutating action goes through ulaknode-agent (see below), since this app only exists to operate on real Ulaknode mailboxes.

Run locally

python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
export HOST=127.0.0.1
export PUBLIC_URL=http://localhost:5000
export SECRET_KEY="$(openssl rand -hex 32)"
export ADMIN_PASSWORD="$(openssl rand -base64 18)"; echo "Admin password: $ADMIN_PASSWORD"
export ULAKNODE_AGENT_TOKEN='<same value as on the ulaknode side>'
python app.py

Then open http://localhost:5000/password/reset or http://localhost:5000/admin — there's no landing page at /.

Settings

All configuration is through environment variables.

Required

The app refuses to start unless all of these are set. Placeholder values such as change-me are rejected.

Variable Requirement
PUBLIC_URL The address users reach the app at, e.g. https://mail.example.com. Reset links are built from it. Must be https://; http:// is accepted for localhost only
SECRET_KEY Session signing key, at least 32 characters (openssl rand -hex 32)
ADMIN_PASSWORD Admin panel password, at least 12 characters
ULAKNODE_AGENT_TOKEN Shared secret, identical to the one on the ulaknode side

Optional

Variable Default Description
HOST 0.0.0.0 Address the web server listens on
PORT 5000 Port the web server listens on
TRUSTED_PROXY (empty) IP address of the reverse proxy whose X-Forwarded-For is trusted
ULAKNODE_AGENT_HOST 127.0.0.1 Where ulaknode-agent is reachable
ULAKNODE_AGENT_PORT 8787 ulaknode-agent port
SMTP_HOST 127.0.0.1 Where ulaknode's Postfix is reachable, for reset emails
SMTP_PORT 25 Postfix port
ULAKNODE_AGENT_TLS no yes connects to ulaknode-agent with TLS (needs ulaknode 2.10.0 or later)
ULAKNODE_AGENT_TLS_NAME (agent host) Name expected on the agent's certificate, if it differs from ULAKNODE_AGENT_HOST
SMTP_STARTTLS no yes requires STARTTLS for reset emails; the certificate must match SMTP_HOST
ULAKNODE_TLS_CA_FILE (system authorities) CA or self-signed certificate file to trust instead, for both connections
MAIL_FROM no-reply@localhost Sender address of reset emails; use one on your mail domain
PASSWORD_RESET_HEADER (empty) Text after "Ulaknode" in the password reset page header
ADMIN_HEADER (empty) Text after "Ulaknode" in the admin page header

docker-compose.yml differs from these defaults: HOST and TRUSTED_PROXY are both 127.0.0.1, and MAIL_FROM is required. It reads HOST, TRUSTED_PROXY, MAIL_FROM, ULAKNODE_AGENT_HOST, SMTP_HOST, the four TLS settings and the required settings from .env; set or change anything else in its environment: section.

HTTPS and reverse proxy

The app serves plain HTTP, so any non-local deployment needs a reverse proxy that terminates TLS in front of it. With an https:// PUBLIC_URL the session cookie is marked Secure, so forms and sign-in don't work over plain HTTP.

Set TRUSTED_PROXY to the proxy's IP address, as the app sees it, and have the proxy send X-Forwarded-For. Without this, all visitors appear to be the proxy and share one rate limit, so anyone could lock you out of the admin login. If the proxy runs on the same host, also set HOST=127.0.0.1 so the app can't be reached around it.

Run with Docker

Images for amd64 and arm64 are published to ghcr.io/itefix/ulaknode-web, tagged with the full version (1.4.0), the minor series (1.4) and latest. They are rebuilt weekly to pick up base-image security updates.

docker-compose.yml uses host networking and expects ulaknode on the same host, also with network_mode: host. The compose file shipped with ulaknode publishes ports on a bridge network instead, which leaves the agent unreachable: in that file, replace the ports: section with network_mode: host, and set ULAKNODE_AGENT_TOKEN there.

Create a .env file next to docker-compose.yml (it's ignored by Git and left out of the image):

PUBLIC_URL=https://mail.example.com
SECRET_KEY=<output of: openssl rand -hex 32>
ADMIN_PASSWORD=<at least 12 characters>
ULAKNODE_AGENT_TOKEN=<same value as on the ulaknode side>
MAIL_FROM=no-reply@example.com

Replace the example domain and every <...> value, then start it with Compose:

docker compose up -d

This runs the published latest image. To update later, run docker compose pull && docker compose up -d. To build from this source tree instead, run docker compose up -d --build.

Without Compose, only the .env file is needed:

docker run -d \
  --name ulaknode-web \
  --restart unless-stopped \
  --network host \
  --env-file .env \
  -e HOST=127.0.0.1 \
  -e TRUSTED_PROXY=127.0.0.1 \
  ghcr.io/itefix/ulaknode-web:latest

Then open /password/reset or /admin under your PUBLIC_URL.

Both examples listen on 127.0.0.1:5000 and trust a reverse proxy on the same host. If your proxy runs elsewhere, set HOST (an address the proxy can reach) and TRUSTED_PROXY (the proxy's IP): in .env for Compose, or in the -e options of docker run. To try the app without a proxy, set PUBLIC_URL=http://localhost:5000 and browse from the host itself.

Versioning

The app's version lives in a single place, VERSION, and every change to it is recorded in CHANGELOG.md. The running app exposes it at GET /version, so the deployed version can be checked directly without shelling into the container.

Build and tag an image so the image tag, the org.opencontainers.image.version label, and /version all agree:

docker build --build-arg APP_VERSION="$(cat VERSION)" -t ghcr.io/itefix/ulaknode-web:"$(cat VERSION)" .

Ulaknode integration

ulaknode-web and ulaknode run as separate containers, so this app doesn't shell out to ulaknode-mailbox locally — it can't; that script (and the doveadm/postmap binaries it depends on) only exists inside the ulaknode image, and there's no shared filesystem between the two containers.

Instead, ulaknode runs a small TCP listener called ulaknode-agent (added in ulaknode/scripts/ulaknode-agent, started by ulaknode/scripts/docker-init via socat) that accepts a one-line request, runs the corresponding ulaknode-mailbox command locally inside the ulaknode container, and returns the result. This app talks to that listener over plain TCP:

  • /password/change sends PASSWD <email> <password>
  • Admin mailbox lookup sends SHOW <email> and parses the Maildir / Quota fields out of the response to render the current-settings panel
  • Admin "Reset password" generates a random temporary password, shows it in the admin panel, and sends PASSWD <email> <temp-password>
  • Admin "Update quota" sends QUOTA-SET <email> <quota>M

If the agent is unreachable or returns an error, the UI shows the failure instead of silently reporting success.

Configuring the connection

ulaknode-agent's protocol has no authentication beyond a shared-secret token — every request must carry it, and ulaknode-agent rejects everything (including revealing which command was even valid) if it's missing or doesn't match. Generate one long random value (e.g. openssl rand -hex 32) and set it identically on both sides.

On this side (ulaknode-web), docker-compose.yml sets these, taking the token from .env:

environment:
  ULAKNODE_AGENT_HOST: 127.0.0.1   # where ulaknode-agent is reachable
  ULAKNODE_AGENT_PORT: 8787
  ULAKNODE_AGENT_TOKEN: <the same long random value as the ulaknode side>

On the ulaknode side, the agent is loopback-only by default (ULAKNODE_AGENT_BIND=127.0.0.1, ULAKNODE_AGENT_ALLOWED_IPS=127.0.0.1/32) — safe and sufficient if both containers run with network_mode: host, since they then share the host's loopback and nothing outside the host can reach the agent at all.

If this app reaches ulaknode any other way (another host, or a bridge network), override on the ulaknode side:

environment:
  ULAKNODE_AGENT_BIND: 0.0.0.0                # or a specific host interface
  ULAKNODE_AGENT_ALLOWED_IPS: 172.20.0.5/32   # this app's real IP/subnet, as ulaknode sees it
  ULAKNODE_AGENT_TLS: "yes"                   # see "Encrypting the connection"

and point ULAKNODE_AGENT_HOST and SMTP_HOST on this side at ulaknode (see Password reset delivery for what Postfix needs). ULAKNODE_AGENT_ALLOWED_IPS takes a single CIDR (socat's range= option) — it's an IP-level ACL, not a substitute for keeping the port off the public internet.

If you also move this app from host to bridge networking, replace network_mode: host in docker-compose.yml with a ports: mapping, set HOST to 0.0.0.0, and set TRUSTED_PROXY to your proxy's address as the container sees it.

Encrypting the connection

By default both connections to ulaknode are unencrypted: mailbox passwords and the agent token go to ulaknode-agent, and reset links go to Postfix, readable by anyone who can capture the traffic (base64 is not encryption). That's fine on one host over 127.0.0.1. Over any network, turn TLS on.

Both use the certificate ulaknode already has for SMTP and IMAP. With ulaknode 2.10.0 or later, set ULAKNODE_AGENT_TLS=yes there, and in this app's .env:

ULAKNODE_AGENT_HOST=mail.example.com
SMTP_HOST=mail.example.com
ULAKNODE_AGENT_TLS=yes
SMTP_STARTTLS=yes
  • Names must match. The certificate is verified, so use hostnames that appear on it. If the agent has to be addressed differently (by IP, say), set ULAKNODE_AGENT_TLS_NAME to the certificate's name. SMTP_HOST has no such override.
  • No fallback. If TLS can't be established, nothing is sent: admin actions and password changes report an error, and unsent reset emails are logged.
  • Private or self-signed certificate. Mount it (or its CA) into the container and point ULAKNODE_TLS_CA_FILE at it, for example with the volume ./mail-ca.pem:/run/mail-ca.pem:ro and ULAKNODE_TLS_CA_FILE=/run/mail-ca.pem.

SMTP_STARTTLS works with earlier ulaknode versions too; only the agent option needs 2.10.0.

Password reset delivery

The reset link is never shown on-screen — it's emailed to the requested address, and carries a random single-use token (secrets.token_urlsafe(32), in-memory, 30-minute expiry) so knowing/guessing someone's email address alone doesn't let you reset their password. The link is built from PUBLIC_URL, and is sent only if ulaknode-agent confirms the mailbox exists. The response to /password/reset is the same generic message regardless of whether the email exists or the send succeeded, to avoid leaking account existence; the lookup and send happen in the background, and failures are only logged server-side.

Requests are limited to 10 per client and 3 per email address per hour. Limits are kept in memory, so they reset on restart.

Email is sent via smtplib directly to ulaknode's Postfix (the same one that serves the mailboxes), configured with SMTP_HOST / SMTP_PORT / MAIL_FROM in docker-compose.yml. This has the identical reachability requirement as ulaknode-agent: Postfix's mynetworks is 127.0.0.0/8 by default, so SMTP_HOST=127.0.0.1 only works under network_mode: host; otherwise, point SMTP_HOST at an address that reaches the ulaknode container, and on that side add this app's IP to mynetworks (/etc/postfix/main.cf) and to the two lists that mirror it, /etc/opendkim/TrustedHosts (so reset emails are DKIM-signed) and /etc/opendmarc/ignore.hosts (so they aren't subjected to inbound DMARC checks), then restart those services.

Because tokens live in an in-memory dict, they don't survive a process restart and won't work if ulaknode-web is ever scaled to multiple workers/replicas.

Admin password

The admin panel is protected by the ADMIN_PASSWORD environment variable, which has no default (see Settings). Each client gets 5 login attempts per 15 minutes; a successful login resets the count.

Styling

Each interface has its own stylesheet under static/ — password-reset.css and admin.css — never both on the same page. Each file starts with a :root { ... } block of CSS custom properties (font family, font size, text/heading/accent/error colors, borders); edit those values to reskin an interface without touching any selectors. To customize without rebuilding the image, bind-mount a replacement over the file, e.g. in docker-compose.yml:

volumes:
  - ./my-admin.css:/app/static/admin.css:ro

Each interface has a header banner above its <h1>, always reading "Ulaknode"; set PASSWORD_RESET_HEADER / ADMIN_HEADER to append interface-specific text after it (e.g. PASSWORD_RESET_HEADER=Mail renders "Ulaknode Mail"). A small footer showing just the version number is shown at the bottom of every page.

Tests

pytest -q

License

BSD 2-Clause. See LICENSE.

About

Self-service password reset and mailbox admin web UI for the ulaknode mail server, in a small Docker container.

Topics

Resources

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Packages

Contributors

Languages