test / test (push) Canceled after 0s
The runtime base is debian:trixie-slim, the build stage golang:1.26-trixie:
Postfix 3.10.13 with upstream's 2026 security fixes up to the August
batch, libmilter 8.18.1, OpenSSL 3.5. Every citation of another program in
code, scripts and documents was re-read against the trixie sources
(dev/upstream; bookworm's kept in dev/upstream-bookworm) and updated;
development.md's cited-package table holds the trixie versions.
What the re-reading changed in behaviour:
- logtail: reject lines with sasl_method/sasl_username/sasl_sender
(smtpd_check.c:1019-1026); cleanup's "removed (canceled)" forgets a
port-25 id (cleanup_api.c:363-364).
- internal/postfix/retry.go reads postconf's stdout only: since 3.9 a
deprecated-parameter warning on stderr made one value too many and the
panel fell back to the compiled-in retry policy.
- logrotate-loop.sh: logrotate 3.22 exits 1 when it ignores a config;
the loop refuses on that output whatever the status.
- postfix-config.sh: cyrus_sasl_config_path set explicitly (bookworm's
07_sasl_config.diff is gone); maillog_file_permissions=0640; mynetworks
explicit; Dockerfile: SYNC_CHROOT= in /etc/default/postfix,
opendkim-tools dropped, openssl named, systemd-standalone-sysusers so
cron does not bring the whole of systemd.
- The selfpost group is 10998, outside the system range 100-999: in
trixie a package took 998 and the build failed (owner's decision:
a conflict-free id, the distribution's own ids untouched). The
entrypoint hands /data back by name when the user or the group differs.
Guide, backup refusal text, help (design commit 68ec8b2), e2e.
- smtpd_hide_client_session=yes on smtps and submission (owner's
decision): Received: names no client, TLS, login or protocol; port 25
keeps the full header. e2e checks both.
- test/upstream/opendkim-probe.sh makes keys with openssl genrsa.
Tests: on the server, make e2e exit 0 (674 s, the image built on trixie),
go vet + go test 27 packages ok. CHANGELOG [Unreleased], guide,
architecture.md, security.md, roadmap.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
109 lines
3.9 KiB
Go
109 lines
3.9 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/mixeme/selfpost/internal/dmarc"
|
|
"github.com/mixeme/selfpost/internal/store"
|
|
)
|
|
|
|
func runDMARCIngestMode() error {
|
|
cfg := loadConfig()
|
|
if !cfg.dmarcEnabled {
|
|
return fmt.Errorf("dmarc ingest invoked but DMARC_REPORTS_ENABLE is not true")
|
|
}
|
|
st, err := store.Open(cfg.dbPath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer st.Close()
|
|
|
|
recipient := ingestRecipient(os.Args[1:])
|
|
if err := dmarc.IngestMessage(st, os.Stdin, recipient, time.Now().UTC()); err != nil {
|
|
if !errors.Is(err, dmarc.ErrRejected) {
|
|
return err
|
|
}
|
|
// Not a report this relay keeps. It is dropped: deferring would have
|
|
// Postfix try it again for days, and a bounce would go to an envelope
|
|
// sender anyone can write - the report addresses are public. Postfix
|
|
// 3.10.13: exit 0 is PIPE_STAT_OK, logged "status=sent (delivered via
|
|
// ... service ...)" (src/global/pipe_command.c, pipe_command();
|
|
// src/pipe/pipe.c, eval_command_status()); a 4.x.x status defers until
|
|
// maximal_queue_lifetime and a 5.x.x one bounces, either way a notice
|
|
// to the sender (src/qmgr/qmgr_active.c, src/global/bounce.c).
|
|
if incrErr := st.IncrDMARCParseFailures(); incrErr != nil {
|
|
log.Printf("dmarc ingest: record failure: %v", incrErr)
|
|
}
|
|
logRejected(err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// logRejected leaves the reason in the mail log. Postfix puts the start of
|
|
// what a delivery command wrote - about a hundred bytes - into its own line
|
|
// for the message ("status=sent (delivered via dmarc-ingest service (...))"),
|
|
// so the reason goes out first and bare: no prefix, no date, no recipient,
|
|
// all of which that line already has. Postfix 3.10.13, src/pipe/pipe.c,
|
|
// eval_command_status(): " (%.100s)" of the output, which
|
|
// src/global/pipe_command.c takes from stdout and stderr together. postlog is
|
|
// no use here: pipe(8) starts the command without the group that may write to
|
|
// Postfix's log socket (src/util/set_ugid.c, set_ugid(): setgroups() to the
|
|
// user's one group). Nor does postlog bring the group with it: upstream
|
|
// installs it set-gid, Debian's package does not - measured in the image,
|
|
// 2026-10-15: /usr/sbin/postlog is -rwxr-xr-x root:root (postfix
|
|
// 3.7.11-0+deb12u1), and dpkg-statoverride lists only postdrop and
|
|
// postqueue (assumptions A-43). postfix 3.10.13-0+deb13u1 is the same by its
|
|
// source: debian/postfix.postinst adds statoverrides for /usr/sbin/postdrop
|
|
// and /usr/sbin/postqueue alone, and nothing in debian/ makes postlog set-gid.
|
|
func logRejected(reason error) {
|
|
fmt.Fprintln(os.Stderr, "dropped: "+logSafe(strings.TrimPrefix(reason.Error(), dmarc.ErrRejected.Error()+": ")))
|
|
}
|
|
|
|
// logSafe makes a reason fit for a log line. Parts of it are the sender's own
|
|
// bytes - a header line, a file name inside an archive, a piece of XML - so it
|
|
// is cut short and anything that is not printable ASCII becomes "?", whatever
|
|
// Postfix would have done with it.
|
|
func logSafe(s string) string {
|
|
const max = 200
|
|
if len(s) > max {
|
|
s = s[:max]
|
|
}
|
|
return strings.Map(func(r rune) rune {
|
|
if r < 0x20 || r > 0x7e {
|
|
return '?'
|
|
}
|
|
return r
|
|
}, s)
|
|
}
|
|
|
|
// ingestRecipient is the report address the message was delivered to. Postfix's
|
|
// pipe(8) hands it over as an argument (${recipient} in the service's argv,
|
|
// build/postfix-config.sh) - it sets no RECIPIENT variable, that is local(8).
|
|
// Postfix 3.10.13, src/pipe/pipe.c, deliver_message(): pipe_command() gets only
|
|
// CA_PIPE_CMD_EXPORT(export_environment), no extra environment;
|
|
// src/local/command.c sets "RECIPIENT".
|
|
// Without it the check that a report came to its own domain's address is
|
|
// skipped.
|
|
func ingestRecipient(args []string) string {
|
|
for _, a := range args {
|
|
if a == "-dmarc-ingest" {
|
|
continue
|
|
}
|
|
return strings.ToLower(strings.TrimSpace(a))
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func isDMARCIngestInvocation() bool {
|
|
if len(os.Args) > 1 && os.Args[1] == "-dmarc-ingest" {
|
|
return true
|
|
}
|
|
return filepath.Base(os.Args[0]) == "dmarc-ingest"
|
|
}
|