Automates the task of rotating OpenDKIM keys.
Automates the task of rotating OpenDKIM keys by generating new keys for the
existing domains in a temporary location, creating new DNS entries in Linode,
and installing the keys to production.
It will perform the following tasks:
Note that this script was initially created to automate this rather simple but
error prone set of tasks that make up the OpenDKIM key rotation
responsibility that needs to occur at most every few months. It was created
specifically for a certain mail system that runs Ubuntu, Postfix, and OpenDKIM
from Apt sources although modifications to handle other configurations are
certainly welcome.
Script makes several assumptions about the system it’s being run on.
Specifically:
KeyTable /etc/dkimkeys/key.table
SigningTable refile:/etc/dkimkeys/signing.table
/etc/opendkim.conf
Script must be run as root.
Add the Linode API key as an environment variable LINODE_API_KEY
prior to
running.
$ sudo rotate_opendkim_keys.py
It will generate private and public keys for each domain listed in OpenDKIM’s
config, displaying the domain and steps taken along the way.
At this point the script will pause before continuing. This is intended as a
way to let DNS propegate as the OpenDKIM testing process will use DNS to
verify the keys.
After some amount of time press any key to continue. For reference, Linode
typically takes at least 15 minutes.
The
OpenDKIM filter installation test
will then test each of the new keys. If they all succeed then the new keys
will be installed and the Postfix and OpenDKIM daemons are restarted.