Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@georglauterbach
Copy link
Member

@georglauterbach georglauterbach commented Sep 28, 2024

Description

This PR improves the algorithm to scan for DKIM paths in Rspamd'd configuration. Moreover, it fixes a small inconvenience: cp would output "Nothing to copy" because the directory contained no contents; this has been fixed as well.

Fixes #4172

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (README.md or the documentation under docs/)
  • If necessary, I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have added information about changes made in this PR to CHANGELOG.md

The new version uses `rspamadm configdump` to more efficiently scan the
`dkim_signing` section for paths. We strip paths that contain "$" and
only print the key path by using "awk".
@georglauterbach georglauterbach added area/scripts kind/bug/fix A fix (PR) for a confirmed bug labels Sep 28, 2024
@georglauterbach georglauterbach added this to the v15.0.0 milestone Sep 28, 2024
@georglauterbach georglauterbach self-assigned this Sep 28, 2024
@polarathene
Copy link
Member

polarathene commented Sep 28, 2024

I'm happy to approve the change, but I do recall suggesting an alternative back in Dec 2023: #3702 (comment)

I've not refreshed myself on the subject, but I did document a way forward here: #3778

If you have the time to have a quick look over that and let me know if that's potentially a better approach, and if it's acceptable for v15 or should be delayed, that'd be good. It may be a bit of a breaking change / inconvenience, but might be worth considering before switching rspamd to the default (which I assume may also be blocked on adopting Valkey to minimize the wider impact of anyone that has been relying on the internal Redis service?).


EDIT: Looks like I added another revision in the related unified DKIM key generation task, that mentions the current rspamd logic extracting path from dkim_signing.conf and how it would differ with the suggested selector_map + path approach (no need to mess with path in scripts like is done presently, so our logic/maintenance should be simpler): #3630 (comment)

Copy link
Member

@polarathene polarathene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Go with this fix for now πŸš€

I'd still appreciate your opinion on adopting selector_map in future before rspamd becomes default. That'll probably need some doc changes and migration advice in changelog for existing users, which I know is a hassle πŸ˜… (but getting it in before the release that defaults to rspamd would be good for testing/feedback)

Comment on lines +343 to +344
if find "$(realpath -L "${KEY_FILE}")" \( -user _rspamd -or -group _rspamd -or -perm -o=r \) \
-exec false {} +; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for the line split? Was it just width?

The concern handled here would be a non-issue if the keys were copied to an internal path right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for the line split? Was it just width?

Yes :)

The concern handled here would be a non-issue if the keys were copied to an internal path right?

Indeed!

__rspamd__log 'warn' "Rspamd DKIM private key file '${KEY_FILE}' is configured for usage, but does not appear to exist"
fi
done
done < <(rspamadm configdump dkim_signing | grep 'path =' | grep -v -F '$' | awk '{print $3}' | tr -d ';"')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the config has multiple path values to extract and check. It seems with the mentioned selector_map config, none of that would be necessary. All keys would stored with predictable hierarchy:

selector = "mail";
# These paths should technically be internal locations instead,
# with data sourced from the users config volume (/tmp/docker-mailserver):
path = "/tmp/docker-mailserver/rspamd/dkim/keys/$domain/$selector.private";
selector_map = "/tmp/docker-mailserver/rspamd/dkim/selector_map";

The selector_map file then maps domain with a selector:

example.com dkim-example
another-domain.com another-selector

So I think the selector_map config approach would make all of this logic redundant πŸ€”

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would need to have another look at your proposed, in-depth, but I guess you are right, your approach would simplify and unify our setup.

@georglauterbach
Copy link
Member Author

LGTM. Go with this fix for now πŸš€

Just a reminder: this PR is a fix for #4172 only, not a rewrite of the DKIM functionality :)

I'd still appreciate your opinion on adopting selector_map in future before rspamd becomes default. That'll probably need some doc changes and migration advice in changelog for existing users, which I know is a hassle πŸ˜… (but getting it in before the release that defaults to rspamd would be good for testing/feedback)

I think you are absolutely right; when I got some time in the future, I will tackle your proposals.

@georglauterbach georglauterbach merged commit 3937e1e into master Sep 29, 2024
@georglauterbach georglauterbach deleted the rspamd-dkim-path-scanning branch September 29, 2024 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/scripts kind/bug/fix A fix (PR) for a confirmed bug

Projects

3 participants