As per previous poster, seems best to have an answer here as the most relevant result that turns up on <enter preferred search engine here>.
Following steps as above fails initially on rspamadm dkim_keygen with error "Too many options". While rspamdadm documentation (at time of writing) states the comamnd will produce two files, as indicated above, actually it produces only the the key file, outputting the txt (DNS entry) content to stdout. To get it to a shell add a redirect into the example command before the email.txt path. There are also typos in the previously posted instructions, and it doesn't cover the scenario of sending from subdomains, so will reproduce tested working version (OPNsense 26.1) below.
1. Install os-rspamd via web UI (if you already have it installed, disable it for now)
2. enable ssh and sudo as needed, access csh with root powers
3. Create folder for DKIM key
4. Generate key
6. Disable clamav module (not sure this is required, but getting it working took so much trouble shooting that we made this change (and clamav should be called by postfix anyway?)
7. Enable DKIM signing by creating the override file with the necessary settings
8. Test syntax and restart rspamd
9. In web UI enable rspamd plugin and enable antispam in postfix
10. Test DKIM signing from CLI
Create a simple test email where the from address domain part has to match whatever you've used in the steps above
Then run
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sub.yourdomain.tld;
s=email; t=1784209642; h=from:from:reply-to:subject:subject:to:to:cc;
bh=RYXvt0hMSt1DiETNsCX712grsTrzBedJQa3fPCnNtAO4=;
b=bjKtJoFa31oH8afOzkrN+0Thoh84RyvokrSMdr+hcjtJ+aRdDlxR9ZoA
If at this stage you don't get DKIM signing, you can enable rspamd debug logs on a per module basis
11. With a successful local test move to add the DNS TXT record for the appropriate (sub.) domain, using the content of the email.txt file you created earlier
12. Now send a real email using your OPNsense mail relay, the key will be added and the mail should be delivered (to even that big mail provider who tries not to accept emails from small mail providers).
NB this was done on a server going into production so we may have done some steps during troubleshooting that we've overlooked in this write-up. Should get to test it on another project soon and will amend as needed.
Hope it helps someone, be nice to get added to rspamd plugin...
Following steps as above fails initially on rspamadm dkim_keygen with error "Too many options". While rspamdadm documentation (at time of writing) states the comamnd will produce two files, as indicated above, actually it produces only the the key file, outputting the txt (DNS entry) content to stdout. To get it to a shell add a redirect into the example command before the email.txt path. There are also typos in the previously posted instructions, and it doesn't cover the scenario of sending from subdomains, so will reproduce tested working version (OPNsense 26.1) below.
1. Install os-rspamd via web UI (if you already have it installed, disable it for now)
2. enable ssh and sudo as needed, access csh with root powers
3. Create folder for DKIM key
Code Select
mkdir usr/local/etc/rspamd/dkim4. Generate key
Code Select
rspamadm dkim_keygen -d sub.yourdomain.tld -s email -k /usr/local/etc/rspamd/dkim/email.key -b 2048 > /usr/local/etc/rspamd/dkim/email.txt
5. Set proper owner and ACL for key fileCode Select
chown rspamd:rspamd /usr/local/etc/rspamd/dkim/email.key
chmod 600 /usr/local/etc/rspamd/dkim/email.key6. Disable clamav module (not sure this is required, but getting it working took so much trouble shooting that we made this change (and clamav should be called by postfix anyway?)
Code Select
vi /usr/local/etc/rspamd/override.d/antivirus.confCode Select
enabled = false;7. Enable DKIM signing by creating the override file with the necessary settings
Code Select
vi /usr/local/etc/rspamd/override.d/dkim_signing.confCode Select
enabled = true;
sign_local = true; #send from known hosts and networks
auth_only = false; #send only from authenticated users
use_domain = envelope; #setting to from also worked for us but left at envelope in production
allow_hdrfrom_mismatch = false;
allow_username_mismatch = false;
use_esld = false; #needed if you are using a subdomain to send mail direct from a service e.g. nextcloud.example.com - esld will assume only the latter 2 parts are relevant and look for a domain that matches example.com and fail
use_redis = false; #in our case the keys were not loading to redis but rspamd dkim_signing module was treating it as the "source of truth" and failing to find the key
domain {
sub.yourdomain.tld {
selector = "email";
path = "/usr/local/etc/rspamd/dkim/email.key";
}
}8. Test syntax and restart rspamd
Code Select
rspamadm configtestCode Select
service rspamd restart9. In web UI enable rspamd plugin and enable antispam in postfix
10. Test DKIM signing from CLI
Create a simple test email where the from address domain part has to match whatever you've used in the steps above
Code Select
vi testmail.eml with contentCode Select
From: john.doe@sub.yourdomain.tld
To: jim.doe@example.com
Subject: Test DKIM Signing
This is a test email for DKIM signing.Then run
Code Select
rspamc --pass-all -vvvv -i 10.0.3.10 -d jim.doe@example.com -F john.doe@sub.yourdomain.tld < testmail.emlIf signing is working properly then the response should include something likeDKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sub.yourdomain.tld;
s=email; t=1784209642; h=from:from:reply-to:subject:subject:to:to:cc;
bh=RYXvt0hMSt1DiETNsCX712grsTrzBedJQa3fPCnNtAO4=;
b=bjKtJoFa31oH8afOzkrN+0Thoh84RyvokrSMdr+hcjtJ+aRdDlxR9ZoA
If at this stage you don't get DKIM signing, you can enable rspamd debug logs on a per module basis
Code Select
vi /usr/local/etc/rspamd/logging.inc appending the lineCode Select
debug_modules = ["dkim_signing"]; then restart rspamd and try the test again. Log is in /var/logs/rspamd/rspamd.log.11. With a successful local test move to add the DNS TXT record for the appropriate (sub.) domain, using the content of the email.txt file you created earlier
Code Select
cat /usr/local/etc/rspamd/dkim/email.txt. Some DNS services will require you to remove some or all of the " "'s used to split the record before letting you add it.12. Now send a real email using your OPNsense mail relay, the key will be added and the mail should be delivered (to even that big mail provider who tries not to accept emails from small mail providers).
NB this was done on a server going into production so we may have done some steps during troubleshooting that we've overlooked in this write-up. Should get to test it on another project soon and will amend as needed.
Hope it helps someone, be nice to get added to rspamd plugin...
"