Skip to main content

Condense SPF records to network blocks to avoid DNS Lookup Limits

Project description

sender policy flattener

We had a problem in our organisation that caused our SPF records to become invalid:

When customers computers were querying our SPF records, there were more than 10 lookups required after following all of the include: remarks.

Solution? Query them ourselves, and create a much more condense list of SPF records.

But wait... What if the downstream records change?

Part of what the script does is that it creates a JSON file that keeps track of the last list of IP Addresses that your combination of SPF records had.

When the hashsum of your IP Addresses changes, it will send out an email (or just dump HTML if it can't find an email server) with a handy diff & BIND format for viewing what has changed, and promptly updating it.

You could theoretically extract the flat IP records from the resulting JSON file and automatically update your DNS configuration with it.

Installation

via git clone

Clone this repo and run

pip install poetry
poetry install

via pip

pip install sender_policy_flattener

Usage

usage: spflat [-h] [-c CONFIG] [-r RESOLVERS] [-e MAILSERVER] [-t TOADDR]
              [-f FROMADDR] [-s SUBJECT] [-D SENDING_DOMAIN] [-d DOMAINS]
              [-o OUTPUT]

A script that crawls and compacts SPF records into IP networks. This helps to
avoid exceeding the DNS lookup limit of the Sender Policy Framework (SPF)
https://tools.ietf.org/html/rfc7208#section-4.6.4

optional arguments:
  -h, --help            show this help message and exit
  -c CONFIG, --config CONFIG
                        Name/path of JSON configuration file
  -r RESOLVERS, --resolvers RESOLVERS
                        Comma separated DNS servers to be used
  -e MAILSERVER, -mailserver MAILSERVER
                        Server to use for mailing alerts
  -t TOADDR, -to TOADDR
                        Recipient address for email alert
  -f FROMADDR, -from FROMADDR
                        Sending address for email alert
  -s SUBJECT, -subject SUBJECT
                        Subject string, must contain {zone}
  -D SENDING_DOMAIN, --sending-domain SENDING_DOMAIN
                        The domain which emails are being sent from
  -d DOMAINS, --domains DOMAINS
                        Comma separated domain:rrtype to flatten to IP
                        addresses. Imagine these are your SPF include
                        statements.
  -o OUTPUT, --output OUTPUT
                        Name/path of output file

Example

spflat --resolvers 8.8.8.8,8.8.4.4 \
    --to me@mydomain.com \
    --from admin@mydomain.com \
    --subject 'SPF for {zone} has changed!' \
    --domains gmail.com:txt,sendgrid.com:txt,yahoo.com:a \
    --sending-domain mydomain.com

or

spflat --config spf.json

You can specify a config file, or you can specify all of the optional arguments from the command line.

I've provided a settings.json file with an example configuration file.

Supported Python versions

See the latest result of the build: https://github.com/cetanu/sender_policy_flattener/actions

3rd party dependencies

  • netaddr
  • dnspython

Example email format

example screenshot

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sender_policy_flattener-0.3.2.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

sender_policy_flattener-0.3.2-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file sender_policy_flattener-0.3.2.tar.gz.

File metadata

  • Download URL: sender_policy_flattener-0.3.2.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.9.13 Linux/5.15.0-1014-azure

File hashes

Hashes for sender_policy_flattener-0.3.2.tar.gz
Algorithm Hash digest
SHA256 f885eaff390080a25c8e506f3e2d73d5fc3cf9518d79e989055d379078f33a9e
MD5 c6a42d2227379e34b9c20b6ca22a9df1
BLAKE2b-256 d584bf217851e2d3cf1c7a8384b55c1708fb3c15026e8c1cd2c21d6a651bb33c

See more details on using hashes here.

File details

Details for the file sender_policy_flattener-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for sender_policy_flattener-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 aa9180a8f689a9bfa3b025219f16132af61f8c57026ce18e153df69ca3a4624d
MD5 57c61c63f184e178ffdbf3d815bf4177
BLAKE2b-256 896271f3d2e244315fa7e4fafc9bc4f9e217789330fc870aaca36d1778a24297

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page