test / test (push) Canceled after 0s
All 2026-10-15; each written beside the code or text it settles. - A-43: /usr/sbin/postlog is -rwxr-xr-x root:root in the image (postfix 3.7.11-0+deb12u1; dpkg-statoverride lists postdrop and postqueue only): Debian does not install it set-gid, so it is no use to dmarc-ingest (cmd/panel/dmarc_ingest.go). - C-X1: OpenSSL 3.0.22 in the image prints the same public key from `x509 -pubkey` and `pkey -pubout` for RSA-2048, P-256, P-384 and a SEC1 P-256 key - cert-reload's same_pair holds for certbot's ECDSA keys. - C-K5, D-guide:933/:233: on the live server (Docker 29.6.1, userland proxy on 0.0.0.0 and ::, no IPv6 on the network) an outside IPv4 client and the host's own public IPv4 address are logged as themselves; the host's IPv6 address and 127.0.0.1 arrive as 172.18.0.1. Over IPv6 every client is the gateway: one level-1 budget, an application IP list cannot name them, rspamd sees the gateway. Guide paragraph under level 1, notes at the milter and allow-list, comments at the anvil setup and authip.go, and a Security entry in the CHANGELOG (an allow-list naming the gateway would admit every IPv6 client). - D-guide:61: a published port nothing listens on (a throwaway container, -p 20999:25) is refused from outside over IPv4 and from the host's public IPv4, accepted and closed through 127.0.0.1 - Docker's proxy, which IPv6 goes through too (not probed over IPv6 for this). - C-M8: the live installation has received one DMARC report, of one record: nothing to set maxReportRecords by yet - said at the constant. - D-S7, D-arch:516, D-arch:532: a new database filled through the store to 120 days at 1 900 messages a day (228 000 messages, 1.37 million lines, 464 MB) on the test server (2 cores): the longest write is the line prune after a 30-day gap, 1.9 s for 342 000 lines (0.4 s with nothing to delete); the send-log delete 0.6 s; 2 000 lines of a tailer pass 18 ms; VACUUM INTO 1.7 s; a second connection writing every 50 ms waited 1.8 s at most, no SQLITE_BUSY - inside busy_timeout's 5 s. architecture.md's "about a second per million lines" was five times too fast; its "six to ten lines of 200 bytes" is 6.0 lines of 146 bytes on the live data. - D-B16: which favicon is fetched, by the probe server's log: Edge 155 the SVG, the desktop app's embedded Chromium 152 the PNG, with or without sizes="any" - layout.html's "vector wins where supported, raster catches the rest" holds; Firefox and Safari not measured. - D-arch:121: the allow/deny trial again, in rspamd/rspamd:3.11.1-3 with today's multimap.conf: every mix of allow and deny entries matching one message ended reject; a changed map was used about 10 s later. - D-sec:424: rspamd runs as _rspamd, uid 11333; the panel is uid 999. Stand: go vet and go test ./... pass on the server (24 packages); make e2e exit 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
110 lines
3.8 KiB
Go
110 lines
3.8 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/mixeme/selfpost/internal/dmarc"
|
|
"github.com/mixeme/selfpost/internal/store"
|
|
)
|
|
|
|
const maxIngestStdin = 10 << 20 // 10 MiB
|
|
|
|
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, io.LimitReader(os.Stdin, maxIngestStdin), 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.7.11: 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.7.11, 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).
|
|
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.7.11, 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"
|
|
}
|