Add mailbox self-service ManageSieve script editor #2

Open
opened 2026-11-19 11:19:19 +01:00 by André Keller · 0 comments
Owner

Goal

Add an optional, minimal public ManageSieve self-service interface to Postoffice, analogous to the existing mailbox password-change page. A mailbox user logs in with their email address and mail password, views remote Sieve scripts, edits or replaces a script as plain text, validates it where supported, uploads it, and selects the active script. Dovecot/ManageSieve remains the source of truth; Postoffice must not store scripts in its database.

This is a future enhancement, not part of the current mail infrastructure rollout. Keep the first version intentionally small; no graphical rule builder or vacation form.

User experience

  • Add a public route such as /sieve/, linked from the existing public page, with email/password login.
  • After login, display the remote script names and indicate which script is active.
  • Allow viewing/editing script source in a plain textarea, server-side validation, saving/updating, and explicitly activating a script.
  • Support creating a script and optionally deleting an explicitly selected script, with confirmation and safeguards for the active script.
  • Provide logout, clear error messages, and a short inactivity timeout (suggested default: 30 minutes).
  • Preserve the existing strict public-page CSP, noindex behavior, translations, and styling.

Authentication and session security

  • Authenticate the mailbox using Postoffice's existing Mailbox.check_password() approach. Keep mailbox self-service sessions logically separate from Django admin authentication and privileges.
  • Use the existing server-side Django database session to retain mailbox identity and a short-lived encrypted copy of the mailbox password, needed to authenticate each ManageSieve connection. Never store the plaintext password in the Django session or expose it to the browser after login.
  • Use authenticated encryption (for example Fernet, available through the existing python3-cryptography dependency). Derive a dedicated encryption subkey from Django SECRET_KEY using HKDF and a stable, application-specific context; do not treat Django session signing as encryption. Reuse existing secret management rather than adding a separate encryption secret.
  • Rotate the session identifier on login, expire the mailbox session after inactivity, clear the credential on logout, and handle changed passwords, invalid credentials, and key rotation by requiring reauthentication. Avoid logging credentials or protocol authentication messages.
  • Ensure secure/HttpOnly/SameSite session cookies, CSRF protection, no-store responses where sensitive, and that the new session state cannot confer admin access. Avoid mixing mailbox credentials into existing admin sessions; explicitly review session isolation.
  • Consider session database exposure and expiry cleanup: encrypted passwords remain in stored expired session rows until Django session cleanup runs. Document that limitation and ensure cleanup is scheduled.

ManageSieve integration

  • Keep all ManageSieve operations behind a small, testable client adapter (prefer assessing sievelib.managesieve / Ubuntu's python3-sievelib; confirm actual packaged version and API before implementation).
  • Select the destination exclusively from the authenticated mailbox's configured backend, not from user input. Use ManageSieve port 4190 with STARTTLS and strictly verified CA chain and hostname; never send mailbox passwords over plaintext or silently downgrade. Explicitly test the TLS behavior of the Ubuntu-packaged library.
  • Implement LISTSCRIPTS, GETSCRIPT, PUTSCRIPT, SETACTIVE; support CHECKSCRIPT if advertised by the server. PUTSCRIPT must surface server validation errors even where CHECKSCRIPT is absent. If implemented, deletion must be explicit and safe.
  • Display supported Sieve capabilities, actionable syntax errors and protocol failures. Set connection timeouts and request/script size limits. Consider stale-edit protection so two browser sessions cannot silently overwrite one another.
  • Do not store or synchronize Sieve scripts in PostgreSQL; keep external ManageSieve clients compatible. No new mail database views or migrations are expected.

Packaging, tests and documentation

  • Confirm python3-sievelib availability on Ubuntu 26.04 and add the package to the Debian build/runtime dependencies if selected. python3-cryptography is already present.
  • Add tests for mailbox login/session expiry/logout, cross-account isolation, unauthorized access, backend selection, TLS verification and downgrade failure, list/edit/save/activate/validate flows, server errors, and concurrent changes. Mock the ManageSieve client; no live Dovecot required for unit tests.
  • Update the Postoffice documentation and translations. Document that Postoffice needs restricted access to ManageSieve on the assigned backend; the backend remains operational independently of Postoffice.

Out of scope

  • Visual filter/vacation rule builders; Sieve parsing or generating rules in Postoffice.
  • SQL-backed script storage, version history, Git synchronization, or integration with sievectl.
  • Dovecot master-user impersonation or administrative access to users' scripts.
  • A new general-purpose mailbox login system beyond the isolated Sieve self-service flow.
## Goal Add an optional, minimal public ManageSieve self-service interface to Postoffice, analogous to the existing mailbox password-change page. A mailbox user logs in with their email address and mail password, views remote Sieve scripts, edits or replaces a script as plain text, validates it where supported, uploads it, and selects the active script. Dovecot/ManageSieve remains the source of truth; Postoffice must not store scripts in its database. This is a **future enhancement**, not part of the current mail infrastructure rollout. Keep the first version intentionally small; no graphical rule builder or vacation form. ## User experience - Add a public route such as `/sieve/`, linked from the existing public page, with email/password login. - After login, display the remote script names and indicate which script is active. - Allow viewing/editing script source in a plain textarea, server-side validation, saving/updating, and explicitly activating a script. - Support creating a script and optionally deleting an explicitly selected script, with confirmation and safeguards for the active script. - Provide logout, clear error messages, and a short inactivity timeout (suggested default: 30 minutes). - Preserve the existing strict public-page CSP, noindex behavior, translations, and styling. ## Authentication and session security - Authenticate the mailbox using Postoffice's existing `Mailbox.check_password()` approach. Keep mailbox self-service sessions logically separate from Django admin authentication and privileges. - Use the existing **server-side Django database session** to retain mailbox identity and a **short-lived encrypted copy of the mailbox password**, needed to authenticate each ManageSieve connection. Never store the plaintext password in the Django session or expose it to the browser after login. - Use authenticated encryption (for example Fernet, available through the existing `python3-cryptography` dependency). Derive a dedicated encryption subkey from Django `SECRET_KEY` using HKDF and a stable, application-specific context; do not treat Django session signing as encryption. Reuse existing secret management rather than adding a separate encryption secret. - Rotate the session identifier on login, expire the mailbox session after inactivity, clear the credential on logout, and handle changed passwords, invalid credentials, and key rotation by requiring reauthentication. Avoid logging credentials or protocol authentication messages. - Ensure secure/HttpOnly/SameSite session cookies, CSRF protection, no-store responses where sensitive, and that the new session state cannot confer admin access. Avoid mixing mailbox credentials into existing admin sessions; explicitly review session isolation. - Consider session database exposure and expiry cleanup: encrypted passwords remain in stored expired session rows until Django session cleanup runs. Document that limitation and ensure cleanup is scheduled. ## ManageSieve integration - Keep all ManageSieve operations behind a small, testable client adapter (prefer assessing `sievelib.managesieve` / Ubuntu's `python3-sievelib`; confirm actual packaged version and API before implementation). - Select the destination exclusively from the authenticated mailbox's configured backend, not from user input. Use ManageSieve port 4190 with STARTTLS and strictly verified CA chain and hostname; never send mailbox passwords over plaintext or silently downgrade. Explicitly test the TLS behavior of the Ubuntu-packaged library. - Implement LISTSCRIPTS, GETSCRIPT, PUTSCRIPT, SETACTIVE; support CHECKSCRIPT if advertised by the server. PUTSCRIPT must surface server validation errors even where CHECKSCRIPT is absent. If implemented, deletion must be explicit and safe. - Display supported Sieve capabilities, actionable syntax errors and protocol failures. Set connection timeouts and request/script size limits. Consider stale-edit protection so two browser sessions cannot silently overwrite one another. - Do not store or synchronize Sieve scripts in PostgreSQL; keep external ManageSieve clients compatible. No new mail database views or migrations are expected. ## Packaging, tests and documentation - Confirm `python3-sievelib` availability on Ubuntu 26.04 and add the package to the Debian build/runtime dependencies if selected. `python3-cryptography` is already present. - Add tests for mailbox login/session expiry/logout, cross-account isolation, unauthorized access, backend selection, TLS verification and downgrade failure, list/edit/save/activate/validate flows, server errors, and concurrent changes. Mock the ManageSieve client; no live Dovecot required for unit tests. - Update the Postoffice documentation and translations. Document that Postoffice needs restricted access to ManageSieve on the assigned backend; the backend remains operational independently of Postoffice. ## Out of scope - Visual filter/vacation rule builders; Sieve parsing or generating rules in Postoffice. - SQL-backed script storage, version history, Git synchronization, or integration with `sievectl`. - Dovecot master-user impersonation or administrative access to users' scripts. - A new general-purpose mailbox login system beyond the isolated Sieve self-service flow.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
tools/postoffice#2
No description provided.