Skip to content

fix: Ensure setup dkim generates DKIM keys with ownership matching the parent directory#3783

Merged
georglauterbach merged 2 commits intodocker-mailserver:masterfrom
ap-wtioit:master-fix_dkim_permissions_github
Jan 18, 2024
Merged

fix: Ensure setup dkim generates DKIM keys with ownership matching the parent directory#3783
georglauterbach merged 2 commits intodocker-mailserver:masterfrom
ap-wtioit:master-fix_dkim_permissions_github

Conversation

@ap-wtioit
Copy link
Copy Markdown
Contributor

@ap-wtioit ap-wtioit commented Jan 16, 2024

Description

dkim key directories and files in /tmp/docker-mailserver/opendkim/keys/ are now created (chowned) with the same user / group as /tmp/docker-mailserver/opendkim/keys/. this means invoking ./setup.sh dkim domain example.com no longer creates files as root:root when invoking inside a directory not owned by root.

Fixes #

Type of change

Not 100% sure could also be just an improvement.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (non-breaking change that does improve existing functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

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
  • I have added information about changes made in this PR to CHANGELOG.md

@ap-wtioit ap-wtioit force-pushed the master-fix_dkim_permissions_github branch from ba36995 to 254bfd1 Compare January 16, 2024 14:08
@ap-wtioit
Copy link
Copy Markdown
Contributor Author

Test error seems unrelated:

not ok 71 [setup.sh] show usage when no arguments provided in 131ms
# (from function `assert_success' in file test/test_helper/bats-assert/src/assert_success.bash, line 42,
#  in test file test/tests/parallel/set3/scripts/setup_cli.bats, line 30)
#   `assert_success' failed
#
# -- command failed --
# status : 126
# output : ttrpc: closed: unknown
# --
#
not ok 72 [setup.sh] exit with error when wrong arguments provided in 88ms
# (from function `assert_line' in file test/test_helper/bats-assert/src/assert_line.bash, line 193,
#  in test file test/tests/parallel/set3/scripts/setup_cli.bats, line 37)
#   `assert_line --index 0 --partial "The command 'lol troll' is invalid."' failed
#
# -- line does not contain substring --
# index     : 0
# substring : The command 'lol troll' is invalid.
# line      : Error response from daemon: No such container: dms-test_postconf-helper
# --
#

@georglauterbach
Copy link
Copy Markdown
Member

We have seen the ttrpc in another PR recently as well (@polarathene). I will restart tests.

@georglauterbach georglauterbach self-assigned this Jan 16, 2024
@georglauterbach georglauterbach added kind/improvement Improve an existing feature, configuration file or the documentation service/security/dkim-dmarc-spf labels Jan 16, 2024
@georglauterbach georglauterbach added this to the v14.0.0 milestone Jan 16, 2024
@georglauterbach georglauterbach added the meta/feature freeze On hold due to upcoming release process label Jan 16, 2024
Comment thread target/bin/open-dkim Outdated
polarathene
polarathene previously approved these changes Jan 16, 2024
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'm fine with the change 👍

Note that it's desired in future to unify the DKIM key generation CLI helper for both OpenDKIM and Rspamd, which would also share a common location on the DMS Config volume. This sort of change would need to be carried over to that when that arrives in a future major release.

Comment thread target/bin/open-dkim
fi

# fix permissions to use the same use as /tmp/docker-mailserver/opendkim/keys
chown -R "$(stat -c '%U:%G' /tmp/docker-mailserver/opendkim/keys)" "/tmp/docker-mailserver/opendkim/keys/${DKIM_DOMAIN}"
Copy link
Copy Markdown
Member

@polarathene polarathene Jan 16, 2024

Choose a reason for hiding this comment

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

Just to clarify, earlier in this script at line 134:

mkdir -p "/tmp/docker-mailserver/opendkim/keys/${DKIM_DOMAIN}"

We create this parent location if it doesn't exist yet. So the only difference here with chown is that the user has created this location in advance or adjusted the permissions since?

I am curious about the motivation for this as most content in the DMS config volume will be owned by root:root when it's created by DMS?


Docker hasn't landed official convenience options for the linux kernel mounting API feature (idmapped mounts), but you can use it manually AFAIK, while I think podman implemented the feature for rootful volumes.

For Docker I think it'll need to wait for Containerd 2.0 release, and then some release after Docker upgrades to that and implements the feature (been a long wait since Kernel 5.12 introduced the feature in April 2021).

ID mapped mounts will allow mapping root from the container easily to another user on the host with volume mounts, avoiding the need to chown effectively..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

in the compose.yaml /tmp/docker-mailserver is mapped as a volume (we have an earlier version of the compose.yaml but it behaves the same) so when a user has a directory containing docker-data that belongs to him it is problematic if there is data created for root:root that the user cannot manage outside of the container (e.g. adding the dkim public keys to DNS).

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.

Yes I understand, but this is admin not related to mail users per se. It can happen with other configs too, not just the DKIM keys generated.

The data should still be readable IIRC, and you rarely need to interact with this kind of data manually on the host for writes? Usually it's annoying if you want to move/rename or delete from the host due to the root ownership.

If you have ID mapped mounts however (once they're in a release that makes it easier to configure), this whole issue disappears.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, sorry my "user" is me the mail admin needing to manage the dkim keys ;-)

i wanted to make the smallest fix to fix my/our issue without affecting too much other stuff. ideally i would think DMS should respect the owner of /tmp/docker-mailserver when creating files there but that would be a much bigger change.

And not all data was readable (transfering private keys from the system i'm working on to the real server after testing was not working without using sudo chown locally, cleanup of CI systems failed without sudo chown).

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.

ideally i would think DMS should respect the owner of /tmp/docker-mailserver when creating files there but that would be a much bigger change.

We could probably add ENV similar to the VMAIL_UID + VMAIL_GID actually and chown to that when necessary? Then it could work for all cases when you opt-in, without having to know the folder to create in advance (or manually chown the first time) which this fix relies on?

cleanup of CI systems failed without sudo chown

Our tests have a make clean that is meant to handle that. If it doesn't we can fix that issue.

Our approach is to just run a container as root with the volume mounted and remove as root that way. I definitely remember the annoyance of relying on sudo from the Docker host in the past, while the tests prior did this on the host you'd have to provide your password upfront and I felt uncomfortable about the script removing content on the host system it had full access to vs removing with the restricted volume.

For CI it's less of an issue to just have a sudo step IMO 🤷‍♂️

Anyway this is fine and we can get this into v13.3 :)

@polarathene polarathene changed the title setup/dkim: chown created dkim directories and keys to config user fix: Ensure setup dkim generates DKIM keys with ownership matching the parent directory Jan 16, 2024
@ap-wtioit ap-wtioit dismissed stale reviews from polarathene and georglauterbach via d96605d January 17, 2024 09:34
@ap-wtioit ap-wtioit force-pushed the master-fix_dkim_permissions_github branch from 254bfd1 to d96605d Compare January 17, 2024 09:34
@polarathene
Copy link
Copy Markdown
Member

Oh actually @georglauterbach may not approve of it getting into v13.3 🤔

Is it ok, considering it's not core to DMS container, but rather a helper fix for the setup cli? Any existing users that have a root owned DKIM folder would still keep the root ownership, so it should be harmless to merge?

@georglauterbach
Copy link
Copy Markdown
Member

Oh actually @georglauterbach may not approve of it getting into v13.3 🤔

Is it ok, considering it's not core to DMS container, but rather a helper fix for the setup cli? Any existing users that have a root owned DKIM folder would still keep the root ownership, so it should be harmless to merge?

I'm fine with that, but this should really be the last PR to go into v13.3.0 :)

@georglauterbach georglauterbach merged commit 9cdbef2 into docker-mailserver:master Jan 18, 2024
@polarathene
Copy link
Copy Markdown
Member

polarathene commented Jan 18, 2024

this should really be the last PR to go into v13.3.0 :)

I may try to squeeze in one for OAuth2 improvement to docs / test. Should be submitted within 48 hours, hopefully within 24 👍 (docs + tests are valid to bypass the freeze, so that should be fine).

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

Labels

kind/improvement Improve an existing feature, configuration file or the documentation meta/feature freeze On hold due to upcoming release process service/security/dkim-dmarc-spf

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants