Skip to content

rspamd: add feature for adjusting options with a file parsed by DMS#3059

Merged
georglauterbach merged 29 commits intomasterfrom
rspamd/5
Feb 19, 2023
Merged

rspamd: add feature for adjusting options with a file parsed by DMS#3059
georglauterbach merged 29 commits intomasterfrom
rspamd/5

Conversation

@georglauterbach
Copy link
Copy Markdown
Member

@georglauterbach georglauterbach commented Feb 4, 2023

Description

Users should be able to do some easy adjustments with our help. With this addition, they can mount a file rspamd-modules.conf and our setup will evaluate it. You can read the documentation for this when looking at the docs preview for this PR :)

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own 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

@georglauterbach georglauterbach added kind/new feature A new feature is requested in this issue or implemeted with this PR area/scripts area/configuration (file) service/security/rspamd labels Feb 4, 2023
@georglauterbach georglauterbach added this to the v12.0.0 milestone Feb 4, 2023
@georglauterbach georglauterbach self-assigned this Feb 4, 2023
This was referenced Feb 4, 2023
Copy link
Copy Markdown
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.

Looks fine :)

The docs could probably do with some revision, but I lack the time to go through that. They're good enough.

I'm not sure about rspamd-commands as the config file name. Is it just for managing modules? Why not something like rspamd.mod, rspamd-modules.conf (potentially gets syntax highlighting for comments in an editor), or something else that looks more like a text file rather than a binary or folder at a glance? 😅

Likewise, config/override-configs was for a specific test to use. With the intent of having a cleaner separation of what files belong to what tests. I haven't given that too much thought, so it might make sense for some tests to share other config files that aren't in the common default config in tests.

Comment thread target/scripts/startup/setup-stack.sh Outdated
@georglauterbach
Copy link
Copy Markdown
Member Author

georglauterbach commented Feb 6, 2023

Had some trouble with arm64 vs amd64 but this should be properly resolved now. Also applied PR feedback.

UPDATE: And corrected a stupid typo.

Comment thread test/helper/sending.bash
MAIL_ID=$(_exec_in_container tac /var/log/mail.log \
| grep -E -m 1 'postfix/smtpd.*: [A-Z0-9]+: client=localhost' \
| grep -E -o '[A-Z0-9]{11}')
| grep -E -o '[A-Z0-9]{9,12}' || true)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Forgot to mention this (FYI): On aarch64, the ID postfix uses might not be 11 characters long, so I provide a bit of range here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add an inline comment about that just above line 57 then please? That sort of information is probably going to be hard to remember 😅

Do you know why that might be btw? Sounds a bit odd 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't have the slightest idea.. but this is what I saw today on my arm64 machine.

polarathene
polarathene previously approved these changes Feb 6, 2023
Copy link
Copy Markdown
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 :)

Comment thread test/helper/sending.bash
MAIL_ID=$(_exec_in_container tac /var/log/mail.log \
| grep -E -m 1 'postfix/smtpd.*: [A-Z0-9]+: client=localhost' \
| grep -E -o '[A-Z0-9]{11}')
| grep -E -o '[A-Z0-9]{9,12}' || true)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add an inline comment about that just above line 57 then please? That sort of information is probably going to be hard to remember 😅

Do you know why that might be btw? Sounds a bit odd 🤔

Comment on lines +138 to +144
# We try getting the most recent version of Rspamd for aarch64 (from an official source, which
# is the backports repository). The version for aarch64 is 3.2; the most recent version for amd64
# that we get with the official PPA is 3.4.
#
# Not removing it later is fine as you have to explicitly opt into installing a backports package
# which is not something you could be doing by accident.
if [[ $(uname --machine) == 'aarch64' ]]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not a big fan of this due to version difference, and the official rspamd advice is to not use the debian packages 😅

Hopefully the version disparity doesn't cause issues going forward if we take the approach you've chosen to support ARM64.


I had a browse of the rspamd download docs, and noticed they have support for Fedora (and OpenSUSE via OBS, but TW isn't a good idea, and Leap releases are slow - not that Debian is any better).

At one point I wanted to consider Alpine as a base image offering, especially for the regular releases and newer packages, but I'm more reluctant now with all the musl compatibility and performance issues I've seen with it 😅

Fedora might be interesting, they have a minimal base image (slightly bigger than Debian), but hard to say if it's worthwhile or a smooth transition to change to. Those rspamd docs made it seem like it was supported but it's been broken for a while.

Maybe OpenSUSE Leap image base would be worth looking into. It's fairly small at a glance, but I understand there is more familiarity with Debian 😅 (Leap is not likely to stay around either AFAIK as they're working towards a new container focused distro/spin)


One other option is building rspamd ourselves with a multi-stage build, but that has it's own drawbacks (maintenance + build time + CI cache?).

Copy link
Copy Markdown
Member Author

@georglauterbach georglauterbach Feb 6, 2023

Choose a reason for hiding this comment

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

I agree, it's not very nice, but as of now, ARM64 users would have to use v2.7. With this change, they can use v3.2 which is only 2 minor versions behind the official PPA. I will rework this as soon as a better emerges :) The current (hopefully temporary solution) just makes the version disparity smaller.


About the base image change: we should put this into our backlog for now I think :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

About the base image change: we should put this into our backlog for now I think :)

I am in no rush, that's not a fun change to tackle and really needs to be worthwhile to bother with 😅

My main motivations were attempting to reduce image weight and switch to something with more frequent release cadence for us to not rely on all these external builds for newer versions, as reliance on that seems to be growing.


Debian Bookworm release should bump up the rspamd package release at least? :)

I raised a request to get official ARM64 builds supported, but given the history of maintainer stances on that, I'm not sure if it'll be approved on their end.

I've also further investigated the Fedora situation further and no fedora release going back 5 years has support to install rspamd based on their instructions 😕 Their docs are terribly out of date for that support it seems.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is going to be a tough one indeed. Ubuntu probably wont help here either as it's basically Debian.. We should discuss about this first on a maintainers discussion board or with discussions for this repository so users can post too.

I thought Fedora was actually quite nice, while I don't have a great experience with OpenSUSE, but I'm open to listening to all proposals.

Copy link
Copy Markdown
Member

@polarathene polarathene Feb 7, 2023

Choose a reason for hiding this comment

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

No rush, we'll likely update to Bookworm before we'd consider properly discussing to change distro :)

@georglauterbach
Copy link
Copy Markdown
Member Author

Added a comment about the mail ID in e5ab05f.

polarathene
polarathene previously approved these changes Feb 7, 2023
This addition allows users to mount a single file with commands to
adjust Rspamd modules. The commands are pretty easy and meant for simple
adjustments.
For Rspamd, the test showed an error which stated that Bash could not
write to `/etc/opendkim/trustedHosts`. The directory is not created as
the test disables OpenDKIM & OpenDMARC. Rspamd setup can run without
them as Rspamd can do DKIM/DMARC itself.

I added a proper guard before the `echo` lines that were causing the
error to appear.
During some tests I did on an aarch64 machine, I noticed weird
behaviour. After investigating, I found that the PPA I added initially
only supports amd64. I was looking for a good alternative and the
Debinan packports seemed like a good choice. I added comments explaining
the whole process in the `packages.sh` script.

Now, aarch64 users can enjoy v3.2 too instead of running v2.7 ..
This was coming from PR feedback, and I think the feedback was pretty
good so I went ahead and changed the file's name.
@georglauterbach
Copy link
Copy Markdown
Member Author

Merged current master and resolved merge conflicts in 4a570ab. Added one more command (to adjust options.inc) in 96baf86.

I will take care of resolving the conflicts that will arise when #3082 is merged. Then the PR is ready for review again :)

So, because commands like `set-option-for-controller` only usually take
2 arguments, previously the value (argument 2) was broken in case it
contained a space (as the `while read` loop splits at whitespaces). The
other part of value after the space would go into argument 3. I
corrected this behaviour. Now, we pass in argument 3 as well and cut off
the last whitespace if it exists.
@georglauterbach
Copy link
Copy Markdown
Member Author

georglauterbach commented Feb 11, 2023

1056876 goes to show what I added to the docs a short while ago: "Program testing can be used to show the presence of bugs, but never to show their absence!" -- Dijkstra

polarathene
polarathene previously approved these changes Feb 12, 2023
Copy link
Copy Markdown
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.

Praise be 96baf86 ! 🤣

1056876 goes to show what I added to the docs a short while ago

Ha! I remember that quote from about a decade ago when I trained to be a software tester 😅 There was some terrifying bugs in medical equipment 😬

@georglauterbach
Copy link
Copy Markdown
Member Author

Praise be 96baf86 ! 🤣

😉

1056876 goes to show what I added to the docs a short while ago

Ha! I remember that quote from about a decade ago when I trained to be a software tester 😅 There was some terrifying bugs in medical equipment 😬

Interesting! Never thought about hearing something linke this though.. actually a bit scary 🙈

I resolved the conflicts and after looking at the code, I decided
against the proposed solution of using an array/string that is appended
to Postfix's milters at the end due to unnecessarry complexity it would
add IMO. The current solution is absolutely fine when proper comments
are in place (which I also added).

Moreover, I added a warning to the log that enabling OpenDMARC but
disabling OpenDKIM is not compliant with RFC 7489 (see
#3082 (comment)).
I extended the docs a bit (corrected minor issues) and added a section
about the current state of AMD64 vs ARM64. I also adjusted the tests a
bit (dropping the `|| exit 1` for example, since I adjusted the
`_send_mail_and_get_id` function to abort the setup if it fails).

I also noticed issues when running Rspamd tests on ARM64, which lead me
to disabling the DKIM signing module (specific for ARM64) and the RBL
module (not specific to ARM64; in general we do not want users to also
require a proper DNS setup for DNSBLs when testing DMS). I was seeing
segfaults though with DKIM signing, very very strange (only on ARM64..).

The setup script has only seen doc updates or very minor improvements
(better regex, etc.).
@georglauterbach
Copy link
Copy Markdown
Member Author

Alright, after dismissing @polarathene's review for the one millionth time, I promise to not do it again (unless required by resolving another conflict - I do hope I don't need to..). I added proper commit messages to the last two commits to make the final review as easy as possible.

polarathene
polarathene previously approved these changes Feb 14, 2023
Copy link
Copy Markdown
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.

I decided against the proposed solution of using an array/string that is appended to Postfix's milters at the end due to unnecessarry complexity it would add IMO.

I'm guessing the complication was with expanding the array values within the sed command? Here's two different ways that it could work:

local DKIM_DMARC=()
# In conditionals:
DKIM_DMARC+='$dkim_milter'
DKIM_DMARC+='$dmarc_milter'

# After conditionals retrieve setting value and expand array into it
# (Note querying settings will probably delay without calling our utility method to avoid that):
postconf "smtpd_milters = $(postconf -h smtpd_milters) ${DKIM_DMARC[@]}"
# Alternatively, create a custom setting to use as an interpolated variable (by Postfix):
postconf "dms_dkim_dmarc = ${DKIM_DMARC[@]}"
sed -i -E 's|^(smtpd_milters =.*)|\1 \$dms_dkim_dmarc|g' /etc/postfix/main.cf

# If you ever need to retrieve the value
# Query the custom setting for value (-h) directly:
postfix -h dms_dkim_dmarc
# Or expand (-x) to the interpolated value where it's used:
postfix -hx smtpd_milters

I won't block on it, but it seemed a bit more DRY, in that the related logic between the two ENV conditions handled that shared setting together in one place afterwards 😅

Comment thread target/scripts/startup/setup-stack.sh Outdated
1. adjusted a comment (wording)
2. adding milter variables to Postfix's config is now done with `postconf`
   instead of uncommenting them (they are also removed from `main.cf`
   too)
3. The command that displays keys was adjusted as well
   1. The global option `maxdepth` belongs before local options (like
      `type`
   2. The files will now be printed properly in one line and without the
      whole path prefix
4. simplified some parts (creating of files, etc.9
5. removed a warning that is not valid yet (but will be when SPF is
   configurable); added a note (TODO)

For a discussion on why no array is currently used for the milters, see
#3059.
@georglauterbach
Copy link
Copy Markdown
Member Author

I decided against the proposed solution of using an array/string that is appended to Postfix's milters at the end due to unnecessarry complexity it would add IMO.

I'm guessing the complication was with expanding the array values within the sed command?

Actually, no :) I think your solution adds lines of code that are not necessary, since in your example you don't account for the extra calls to _adjust_mtime_for_postfix_maincf or the shellcheck comments. I implemented your solution, just to see what it looks like, but the extra complexity was not really worth it IMO. Moreover, there is no code handling the case in which DKIM_DMARC is empty, which adds another if..

Here's two different ways that it could work: [...]

I do like some of the parts; especially adding things via popstconf. I have apllied some of this in the last PR feedback commit (9756028) :)

I won't block on it, but it seemed a bit more DRY, in that the related logic between the two ENV conditions handled that shared setting together in one place afterwards 😅

I actually think it is really DRY now, and the current setup is easy to understand.

polarathene
polarathene previously approved these changes Feb 15, 2023
Co-authored-by: Brennan Kinney <[email protected]>
@georglauterbach
Copy link
Copy Markdown
Member Author

@polarathene this is a rather big PR, but I actually want to have this merged anyway. Do you think this PR is fine to merge with 1 review?

@github-actions
Copy link
Copy Markdown
Contributor

Documentation preview for this PR is ready! 🎉

Built with commit: fff5d16

@polarathene
Copy link
Copy Markdown
Member

Do you think this PR is fine to merge with 1 review?

I have been reasonably thorough with reviews. I know I sometimes miss things though. Pretty much our only other reviewer is Casper and he seems rather busy lately, probably swamped with notifications from this project to wade through too.

I don't see any harm in merging it, no release has been made, so there is still time to review even after a merge and provide feedback that can be addressed via a follow-up PR.

@georglauterbach
Copy link
Copy Markdown
Member Author

georglauterbach commented Feb 19, 2023

Alright, then I will go ahead :D

@casperklein
Copy link
Copy Markdown
Member

probably swamped with notifications from this project to wade through too.

Absolutely! lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/configuration (file) area/scripts kind/new feature A new feature is requested in this issue or implemeted with this PR service/security/rspamd

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants