Skip to content

Commit 48bda15

Browse files
committed
llow a custom dkim selector
1 parent 3acd5fe commit 48bda15

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

management/dns_update.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def has_rec(qname, rtype, prefix=None):
291291

292292
# Append the DKIM TXT record to the zone as generated by OpenDKIM.
293293
# Skip if the user has set a DKIM record already.
294-
opendkim_record_file = os.path.join(env['STORAGE_ROOT'], 'mail/dkim/mail.txt')
294+
opendkim_record_file = os.path.join(env['STORAGE_ROOT'], 'mail/dkim/' + env['DKIM_SELECTOR'] + '.txt')
295295
with open(opendkim_record_file, encoding="utf-8") as orf:
296296
m = re.match(r'(\S+)\s+IN\s+TXT\s+\( ((?:"[^"]+"\s+)+)\)', orf.read(), re.S)
297297
val = "".join(re.findall(r'"([^"]+)"', m.group(2)))
@@ -752,12 +752,13 @@ def write_opendkim_tables(domains, env):
752752
# Append a record to OpenDKIM's KeyTable and SigningTable for each domain
753753
# that we send mail from (zones and all subdomains).
754754

755-
opendkim_key_file = os.path.join(env['STORAGE_ROOT'], 'mail/dkim/mail.private')
755+
opendkim_key_file = os.path.join(env['STORAGE_ROOT'], 'mail/dkim/' + env['DKIM_SELECTOR'] + '.private')
756756

757757
if not os.path.exists(opendkim_key_file):
758758
# Looks like OpenDKIM is not installed.
759759
return False
760760

761+
selector=env['DKIM_SELECTOR']
761762
config = {
762763
# The SigningTable maps email addresses to a key in the KeyTable that
763764
# specifies signing information for matching email addresses. Here we
@@ -777,7 +778,7 @@ def write_opendkim_tables(domains, env):
777778
# signing domain must match the sender's From: domain.
778779
"KeyTable":
779780
"".join(
780-
f"{domain} {domain}:mail:{opendkim_key_file}\n"
781+
f"{domain} {domain}:{selector}:{opendkim_key_file}\n"
781782
for domain in domains
782783
),
783784
}

setup/dkim.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ fi
5252
# A 1024-bit key is seen as a minimum standard by several providers
5353
# such as Google. But they and others use a 2048 bit key, so we'll
5454
# do the same. Keys beyond 2048 bits may exceed DNS record limits.
55-
if [ ! -f "$STORAGE_ROOT/mail/dkim/mail.private" ]; then
56-
opendkim-genkey -b 2048 -r -s mail -D "$STORAGE_ROOT/mail/dkim"
55+
if [ ! -f "$STORAGE_ROOT/mail/dkim/$DKIM_SELECTOR.private" ]; then
56+
opendkim-genkey -b 2048 -r -s $DKIM_SELECTOR -D $STORAGE_ROOT/mail/dkim
5757
fi
5858

5959
# Ensure files are owned by the opendkim user and are private otherwise.

setup/start.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ PUBLIC_IPV6=$PUBLIC_IPV6
111111
PRIVATE_IP=$PRIVATE_IP
112112
PRIVATE_IPV6=$PRIVATE_IPV6
113113
MTA_STS_MODE=${DEFAULT_MTA_STS_MODE:-enforce}
114+
DKIM_SELECTOR=${DEFAULT_DKIM_SELECTOR:-mail}
114115
EOF
115116

116117
# Start service configuration.

0 commit comments

Comments
 (0)