GoAdmio

installspf

Install the Postfix SPF policy daemon, create its service user, and register the policy service and SMTP ports 26, 465, and 587 in Postfix's master.cf

On this page: Overview · Quick start · Syntax · Options · Output · Examples · Troubleshooting · Details · See also


Overview

/go/installspf prepares Postfix to check the SPF record of incoming mail. It:

[!NOTE] This command makes the policy service available to Postfix. It does not edit main.cf or restart Postfix, so incoming mail is not checked until you add the policy check and reload Postfix. See Finish the setup.

[!NOTE] Don't confuse this command with spf. spf publishes your domain's outgoing SPF record in DNS through Cloudflare. installspf sets up the server to verify the SPF records of incoming mail.


Quick start

# Install the SPF policy daemon and register it in Postfix
/go/installspf

Then finish the setup in main.cf and reload Postfix.


Syntax

/go/installspf

Run it as root. The command uses sudo for most steps, but useradd runs without it.


Options

None. Any arguments you pass are written to the log file and otherwise ignored.


Output

The command prints one progress line, Installing SPF, followed by the output of the package manager. It does not print a success message and does not stop on errors: each step runs even if an earlier one failed. The exit status is that of the last command.

Every run adds a line to /var/log/go/installspf.log:

[Nov 20 14:03:11]# installspf

Examples

# Run the installer
/go/installspf
# Check that the daemon user exists
id policyd-spf
# Check the entries added to master.cf
grep -nE '^(26|submission|smtps|policyd-spf)\b' /etc/postfix/master.cf
# Check that Postfix accepts the configuration
postfix check
# After reloading Postfix, check that ports 26, 465, and 587 are listening
ss -ltnp | grep -E ':(26|465|587)\b'
# Review past runs
tail /var/log/go/installspf.log

Troubleshooting

Symptom Likely cause Fix
Only Installing SPF is shown, or nothing is installed The value in /usr/local/goadmio/linux/os.db is not an exact match for a supported system. Check the file. It must contain exactly one of the names in Supported systems.
dnf can't find pypolicyd-spf The package isn't in your enabled repositories. Enable the EPEL repository, then run the command again.
useradd: user 'policyd-spf' already exists The package or an earlier run already created the user. Nothing. The message is harmless.
postfix check reports duplicate or conflicting entries The command was run more than once, or master.cf already had submission or smtps lines. Remove the duplicate lines from /etc/postfix/master.cf. See Running it again.
Ports 26, 465, or 587 aren't listening Postfix wasn't reloaded, or the firewall blocks them. Reload Postfix, then open the ports with allow.
SPF results don't appear in mail headers main.cf has no policy check yet. Follow Finish the setup.
Port 587 or 465 clients can't log in SASL and TLS settings in main.cf are missing. Run installmail or mailssl, then test with checksmtp.

Details

Supported systems

The command reads the operating system name from /usr/local/goadmio/linux/os.db and requires an exact match.

Family Names matched Package installed Policy program
RHEL family AlmaLinux, Rocky, CentOS, Red Hat, Fedora pypolicyd-spf (with dnf) /usr/libexec/postfix/policyd-spf
Debian family Debian, Ubuntu postfix-policyd-spf-python (with apt) /usr/bin/policyd-spf

On any other value, nothing is installed and no policyd-spf service entry is written. The command still tries to create the user and still adds the port 26, 587, and 465 entries to master.cf.

What it changes

Item Change
Package Installs the SPF policy daemon for your OS (see above).
System user policyd-spf, with home directory /etc/python-policyd-spf and shell /sbin/nologin. Postfix can't run the daemon as root or postfix, so it needs its own user.
Port 26 Adds 26 inet n - n - - smtpd to master.cf. Any existing line starting with 26 is removed first, so this entry is never duplicated.
Port 587 Adds a submission listener with TLS set to may and SASL authentication on.
Port 465 Adds an smtps listener with TLS wrapper mode and SASL authentication on.
Policy service Adds a policyd-spf entry to master.cf that spawns the daemon as the policyd-spf user.
Log Appends the command and a timestamp to /var/log/go/installspf.log.

Each addition to master.cf is preceded by a comment line, such as # Allow SMTP Port 587.

flowchart TD
    A["installspf"] --> B["Log the run"]
    B --> C{"OS in os.db"}
    C -- "RHEL family" --> D["dnf install pypolicyd-spf"]
    C -- "Debian family" --> E["apt install postfix-policyd-spf-python"]
    C -- "Other" --> F["Skip install"]
    D --> G["Create policyd-spf user"]
    E --> G
    F --> G
    G --> H["Add ports 26, 587, 465 to master.cf"]
    H --> I["Add policyd-spf service to master.cf"]

Finish the setup

The command does not change /etc/postfix/main.cf. To make Postfix check SPF on incoming mail, add the following, then reload Postfix. Put check_policy_service after reject_unauth_destination, and keep your existing restrictions in the list.

policyd-spf_time_limit = 3600
smtpd_recipient_restrictions =
    permit_mynetworks,
    permit_sasl_authenticated,
    reject_unauth_destination,
    check_policy_service unix:private/policyd-spf
postfix check && systemctl reload postfix

The daemon's own settings, such as the SPF failure policy, are typically in /etc/python-policyd-spf/policyd-spf.conf.

Limitations

Running it again

The command isn't idempotent. Only the port 26 line is de-duplicated. Each further run appends another copy of the comment lines, the submission and smtps entries, and the policyd-spf service entry. Duplicate service entries can make Postfix report errors or fail to start the listeners. If you have to run it again, remove the earlier entries from master.cf first.

Firewall

The command doesn't open any port. Open 26, 465, and 587 with allow or firewall if you want to use them from outside.

Postfix isn't restarted

Changes to master.cf take effect after Postfix is reloaded or restarted.


See also

Command Description
spf Add or refresh the SPF TXT record via Cloudflare
installdkim Install OpenDKIM and create a domain's DKIM key
installdmarc Install OpenDMARC and set its AuthservID
installmail Install and configure webmail services (Postfix and Dovecot)
mailssl Install SSL certificates for SMTP and IMAP
smtp Manage the SMTP port: block, unblock, and change it
checksmtp Check that SMTP accepts a login on port 587
checkmail Test outbound port 25 and the SMTP and IMAP SSL certificates
allow Open a TCP port in the server firewall
troubleshoot Troubleshoot email problems in GoAdmio