[1.3.0] Security and quality after 1.2.5: domain-admin send-log authorization, fail-closed sign-in and application delete, level-2 rate-limit race fix, restore Resync, expanded tests, operator docs, release CI, and OFL for IBM Plex. Upgrading from 1.2.x is a tag bump; no migration. Added: - licence: the SIL Open Font License 1.1 text now travels with the IBM Plex - docs: agreed roadmap item **queue-retries** — show this Postfix's retry Security: - The independent security review of the send-log authorization and Fixed: - test (e2e): send-log status scrapers follow the badge markup in - security (panel): the Deliveries list is scoped to a domain administrator's - mail (level-2 rate limit): the ceiling is no longer overshot by messages that - panel (sign-in): a session that cannot be written to the database no longer - panel (applications): deleting an application removes its SASL credentials … (2 more in CHANGELOG) Changed: - docs: operator and as-built docs aligned with the code after a full - docs: [guide.md](docs/guide.md) reorganised into **Installation**, **Instance - docs: the 2026-08-13 full-tree review plan is complete — every phase (P0–P7) - licence: [NOTICE](NOTICE) tells modifiers to update `SourceURL` in - ci: the release image is published only for a **published** GitHub Release … (9 more in CHANGELOG) [1.3.1] Retry policy in the panel, persistent Postfix queue, and self-contained full backups. Mail queue and delivery history show this Postfix's first retry, backoff cap, and queue lifetime. Deferred mail survives container recreate. Full backups now archive `data/`, compose, `.env`, and `certs/`; the archive layout breaks 1.3.0 flat backups (unpack those with `tar xzf backup.tar.gz -C ./data` as before). Upgrading from 1.3.0 is a tag bump; no schema migration. Added: - Mail queue and a delivery's history show this Postfix's retry policy - docs: **Plan checklists** in [development.md](docs/development.md) — format, - docs: **Implementation checklists** with model routing in - docs: roadmap candidates **send-log-retention** (panel Settings for delivery - Postfix queue under `/data/postfix/queue` — deferred and active mail survive … (1 more in CHANGELOG) Changed: - **Breaking:** full-backup archive layout — paths are prefixed with `data/`; - docs: operator guide, architecture, security, and backup UI updated for - docs: HTML mockups for a full panel UI refresh Changed: - docs: panel UI mockups after review — Status restored to live readings - docs: panel UI design system and mockups rebuilt as separate pages - docs: panel UI mockups — add-domain sits in the list card (Domains and Fixed: - ci (GHCR): per-arch package tags (`X.Y.Z-amd64`, `X.Y.Z-arm64`) are dropped Squashed CHANGELOG sections: [1.3.0], [1.3.1]. Full detail: CHANGELOG.md (1.3.0, 1.3.1).
165 lines
4.8 KiB
Go
165 lines
4.8 KiB
Go
package main
|
|
|
|
import (
|
|
"archive/tar"
|
|
"compress/gzip"
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/mixeme/selfpost/internal/backup"
|
|
"github.com/mixeme/selfpost/internal/store"
|
|
)
|
|
|
|
// seedProject builds the minimum operator project tree a backup can be taken from.
|
|
func seedProject(t *testing.T) (deployRoot, dataDir string) {
|
|
t.Helper()
|
|
deployRoot = t.TempDir()
|
|
dataDir = filepath.Join(deployRoot, "data")
|
|
if err := os.MkdirAll(dataDir, 0o750); err != nil {
|
|
t.Fatalf("mkdir data: %v", err)
|
|
}
|
|
st, err := store.Open(filepath.Join(dataDir, "selfpost.db"))
|
|
if err != nil {
|
|
t.Fatalf("open store: %v", err)
|
|
}
|
|
if _, err := st.AddDomain("example.com", "selfpost"); err != nil {
|
|
t.Fatalf("add domain: %v", err)
|
|
}
|
|
if err := st.Close(); err != nil {
|
|
t.Fatalf("close store: %v", err)
|
|
}
|
|
writeFile(t, filepath.Join(deployRoot, backup.ComposeFileName), "services:\n selfpost:\n image: test\n")
|
|
writeFile(t, filepath.Join(deployRoot, backup.EnvFileName), "SELFPOST_HOSTNAME=mail.example.com\n")
|
|
writeFile(t, filepath.Join(deployRoot, backup.CertsDirName, "fullchain.pem"), "CERT")
|
|
writeFile(t, filepath.Join(deployRoot, backup.CertsDirName, "privkey.pem"), "KEY")
|
|
t.Setenv("SELFPOST_DATA_DIR", dataDir)
|
|
t.Setenv("SELFPOST_DB_PATH", filepath.Join(dataDir, "selfpost.db"))
|
|
t.Setenv("SELFPOST_DEPLOY_ROOT", deployRoot)
|
|
return deployRoot, dataDir
|
|
}
|
|
|
|
func writeFile(t *testing.T, path, content string) {
|
|
t.Helper()
|
|
if err := os.MkdirAll(filepath.Dir(path), 0o750); err != nil {
|
|
t.Fatalf("mkdir %s: %v", path, err)
|
|
}
|
|
if err := os.WriteFile(path, []byte(content), 0o640); err != nil {
|
|
t.Fatalf("write %s: %v", path, err)
|
|
}
|
|
}
|
|
|
|
// An encrypted backup is only worth having if the container it came from can
|
|
// hand it back as an ordinary archive during a restore, so the two halves of
|
|
// the CLI are tested as the one round trip an operator actually performs.
|
|
func TestEncryptedBackupRoundTrip(t *testing.T) {
|
|
seedProject(t)
|
|
dir := t.TempDir()
|
|
encrypted := filepath.Join(dir, "backup.spbk")
|
|
plain := filepath.Join(dir, "backup.tar.gz")
|
|
const password = "a long enough password"
|
|
|
|
if err := run(encrypted, password); err != nil {
|
|
t.Fatalf("create encrypted backup: %v", err)
|
|
}
|
|
head, err := os.ReadFile(encrypted)
|
|
if err != nil {
|
|
t.Fatalf("read backup: %v", err)
|
|
}
|
|
if !strings.HasPrefix(string(head), "SELFPOST") {
|
|
t.Fatalf("encrypted backup does not start with the envelope magic")
|
|
}
|
|
|
|
if err := runDecrypt(encrypted, plain, "the wrong password"); err == nil {
|
|
t.Fatal("decryption with the wrong password succeeded")
|
|
}
|
|
if err := runDecrypt(encrypted, plain, password); err != nil {
|
|
t.Fatalf("decrypt: %v", err)
|
|
}
|
|
|
|
// What comes out must be the same gzip tar the plain path produces.
|
|
f, err := os.Open(plain)
|
|
if err != nil {
|
|
t.Fatalf("open decrypted archive: %v", err)
|
|
}
|
|
defer f.Close()
|
|
gz, err := gzip.NewReader(f)
|
|
if err != nil {
|
|
t.Fatalf("gzip: %v", err)
|
|
}
|
|
names := map[string]bool{}
|
|
tr := tar.NewReader(gz)
|
|
for {
|
|
hdr, err := tr.Next()
|
|
if err == io.EOF {
|
|
break
|
|
}
|
|
if err != nil {
|
|
t.Fatalf("tar: %v", err)
|
|
}
|
|
names[hdr.Name] = true
|
|
}
|
|
for _, want := range []string{
|
|
backup.DataArchivePrefix + backup.ManifestName,
|
|
backup.DataArchivePrefix + "selfpost.db",
|
|
backup.ComposeFileName,
|
|
backup.EnvFileName,
|
|
} {
|
|
if !names[want] {
|
|
t.Errorf("decrypted archive has no %s (entries: %v)", want, names)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Without a password the CLI keeps producing the plain archive that existing
|
|
// backup scripts consume.
|
|
func TestUnencryptedBackupStaysPlain(t *testing.T) {
|
|
seedProject(t)
|
|
out := filepath.Join(t.TempDir(), "backup.tar.gz")
|
|
if err := run(out, ""); err != nil {
|
|
t.Fatalf("create backup: %v", err)
|
|
}
|
|
f, err := os.Open(out)
|
|
if err != nil {
|
|
t.Fatalf("open archive: %v", err)
|
|
}
|
|
defer f.Close()
|
|
if _, err := gzip.NewReader(f); err != nil {
|
|
t.Fatalf("plain backup is not a gzip archive: %v", err)
|
|
}
|
|
}
|
|
|
|
// Decrypting needs a password, and it must come from a file or the environment
|
|
// — never an argument, which the process list would expose.
|
|
func TestReadPassword(t *testing.T) {
|
|
dir := t.TempDir()
|
|
pwFile := filepath.Join(dir, "pw")
|
|
if err := os.WriteFile(pwFile, []byte("from the file\nignored second line\n"), 0o600); err != nil {
|
|
t.Fatalf("write password file: %v", err)
|
|
}
|
|
|
|
t.Setenv(passwordEnv, "from the environment")
|
|
got, err := readPassword("")
|
|
if err != nil || got != "from the environment" {
|
|
t.Errorf("readPassword(\"\") = %q, %v", got, err)
|
|
}
|
|
got, err = readPassword(pwFile)
|
|
if err != nil || got != "from the file" {
|
|
t.Errorf("readPassword(file) = %q, %v", got, err)
|
|
}
|
|
|
|
if err := os.WriteFile(pwFile, nil, 0o600); err != nil {
|
|
t.Fatalf("truncate password file: %v", err)
|
|
}
|
|
if _, err := readPassword(pwFile); err == nil {
|
|
t.Error("an empty password file was accepted")
|
|
}
|
|
|
|
os.Unsetenv(passwordEnv)
|
|
if err := runDecrypt("", "", ""); err == nil {
|
|
t.Error("-decrypt without a password was accepted")
|
|
}
|
|
}
|