Restrictive SPF policy¶
SPF rules and included dependencies must match your legitimate sending infrastructure.
Setup¶
Prepare your values and Debian packages. Replace the example domain and IP.
Use the SPF recipe. Avoid +all, ?all, unnecessary includes and redirect loops. With multiple sending providers, inspect every included policy: checking only the top-level string is insufficient.
. /root/mailserver.env
printf 'Minimal SPF TXT record: v=spf1 ip4:%s -all\n' "$PUBLIC_IPV4"
Test¶
set -euo pipefail
. /root/mailserver.env
python3 - <<'PY'
import dns.resolver, os
values = ["".join(p.decode() for p in r.strings) for r in dns.resolver.resolve(os.environ["DOMAIN"], "TXT")]
records = [r for r in values if r.startswith("v=spf1")]
assert len(records) == 1
expected = ["v=spf1", "ip4:" + os.environ["PUBLIC_IPV4"], "-all"]
assert records[0].split() == expected, "Different policy: fully evaluate includes/redirects separately"
print("PASS: the published minimal policy has no permissive rules or DNS dependencies.")
PY
This minimal test intentionally fails for more complex SPF policies. It does not replace a complete SPF evaluator or an inventory of all legitimate sending sources.