Skip to content

Don't change owners in /var/mail recursively#2256

Closed
MohammedNoureldin wants to merge 8 commits intodocker-mailserver:masterfrom
MohammedNoureldin:patch-1
Closed

Don't change owners in /var/mail recursively#2256
MohammedNoureldin wants to merge 8 commits intodocker-mailserver:masterfrom
MohammedNoureldin:patch-1

Conversation

@MohammedNoureldin
Copy link
Copy Markdown
Contributor

@MohammedNoureldin MohammedNoureldin commented Oct 19, 2021

Description

Changing the whole owners of folders inside /var/mail ruins the whole LDAP users permissions on their own mail folders. Thus, only /var/mail owner should be fixed if necessary (not recursively).

Fixes: #2238

Type of change

  • 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

Changing the whole owners of folders inside */var/mail* ruins the whole LDAP users permissions on their own mail folders. Thus, only */var/mail* owner should be fixed if necessary (not recursively).
polarathene
polarathene previously approved these changes Oct 20, 2021
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.

Glanced over history for this logic, and I do not see any strong justification for keeping the original.

If tests pass then it's fine by me. Should any issues actually surface, then we have new tests to add :)


While unrelated to this PR, I want to make mention of a permissions addition in the past for reference:

  • March 2017 PR that added various chown -R for services and Postfix config to resolve issues.
  • Issue comment that advised chown -R for /var/mail-state.

Comment thread target/scripts/startup/fixes-stack.sh Outdated
if [[ $mail_owner_user -ne 5000 || $mail_owner_group -ne 5000 ]]; then
_notify 'inf' 'Fixing /var/mail permissions'
chown -R 5000:5000 /var/mail || _shutdown 'Failed to fix /var/mail permissions'
chown 5000:5000 /var/mail || _shutdown 'Failed to fix /var/mail permissions'
Copy link
Copy Markdown
Member

@polarathene polarathene Oct 19, 2021

Choose a reason for hiding this comment

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

When originally introduced this chown -R line was not explained beyond the associated line "Fixing permisions".

That line has been present since the very first commit of the project (March 2015).


In Dec 2016 an issue regarding permissions on /var/mail was raised, the related code is brought up, the original project author responds and doesn't explain the need for chown -R, they don't appear to be aware of it's requirement.


Related issue, but focused on the GID instead of UID for file access on host storage for multiple users under a different GID: #1611

Related issue, user migrates existing IMAP mailboxes by copying over files on the host from a source not previously handled by docker-mailserver. There issue with permissions was that they could not move/delete directories via their MUA (Thunderbird): #2208

Comment thread target/scripts/startup/fixes-stack.sh Outdated
Comment on lines -20 to -22
# fix permissions, but skip this if 3 levels deep the user id is already set
if find /var/mail -maxdepth 3 -a \( \! -user 5000 -o \! -group 5000 \) | read -r
then
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.

This appears to have been added to reduce startup overhead of redundantly applying the permissions to contents of multiple GB in size.


Related, this code snippet has been copied into check-for-changes.sh, which will also apply chown -R 5000:5000, as identified here.

You will want to apply your changes to this too:

if find /var/mail -maxdepth 3 -a \( \! -user 5000 -o \! -group 5000 \) | read -r
then
chown -R 5000:5000 /var/mail
fi

Comment thread target/scripts/startup/fixes-stack.sh Outdated
@polarathene
Copy link
Copy Markdown
Member

9 tests fail. They must be compatible with this PR if you want to get it merged. Investigate why it's an issue for them and resolve it if possible.


Test failures all with trouble accessing /var/mail content as a result of this change:

# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory

#   grep: /var/mail/localhost.localdomain/user1/.Junk/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/new/: No such file or directory

# Timed out on command: docker exec mail_lmtp_ip /bin/sh -c grep 'postfix/lmtp' /var/log/mail/mail.log | grep 'status=sent' | grep ' Saved)'
`mail_hostname.bats`: 52 checking configuration: hostname/domainname override: check headers of received mail
not ok 52 checking configuration: hostname/domainname override: check headers of received mail
# (from function `assert_success' in file test/test_helper/bats-assert/src/assert.bash, line 114,
#  in test file test/mail_hostname.bats, line 108)
#   `assert_success' failed
# 
# -- command failed --
# status : 1
# output : ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# --
# 
`mail_hostname.bats`: 58 checking configuration: non-subdomain: check headers of received mail
not ok 58 checking configuration: non-subdomain: check headers of received mail
# (from function `assert_success' in file test/test_helper/bats-assert/src/assert.bash, line 114,
#  in test file test/mail_hostname.bats, line 160)
#   `assert_success' failed
# 
# -- command failed --
# status : 1
# output : ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# --
# 
`mail_lmtp_ip.bats`: 68 checking postfix-lmtp: delivers mail to existing account
not ok 68 checking postfix-lmtp: delivers mail to existing account
# (from function `repeat_until_success_or_timeout' in file test/test_helper/common.bash, line 37,
#  in test file test/mail_lmtp_ip.bats, line 51)
#   `repeat_until_success_or_timeout 60 docker exec mail_lmtp_ip /bin/sh -c "grep 'postfix/lmtp' /var/log/mail/mail.log | grep 'status=sent' | grep ' Saved)'"' failed
# Timed out on command: docker exec mail_lmtp_ip /bin/sh -c grep 'postfix/lmtp' /var/log/mail/mail.log | grep 'status=sent' | grep ' Saved)'
`mail_privacy.bats`: 88 checking postfix: remove privacy details of the sender
not ok 88 checking postfix: remove privacy details of the sender
# (from function `repeat_until_success_or_timeout' in file test/test_helper/common.bash, line 37,
#  in test file test/mail_privacy.bats, line 43)
#   `repeat_until_success_or_timeout 120 docker exec mail_privacy /bin/bash -c '[[ $(ls /var/mail/localhost.localdomain/user1/new | wc -l) -eq 1 ]]'' failed
# Can't use SSL_get_servername
# depth=0 CN = localhost
# verify return:1
# 250 CHUNKING
# 250-mail.my-domain.com
# 250-PIPELINING
# 250-SIZE 10240000
# 250-ETRN
# 250-AUTH PLAIN LOGIN
# 250-AUTH=PLAIN LOGIN
# 250-ENHANCEDSTATUSCODES
# 250-8BITMIME
# 250-DSN
# 250 CHUNKING
# 334 UGFzc3dvcmQ6
# 235 2.7.0 Authentication successful
# 250 2.1.0 Ok
# 250 2.1.5 Ok
# 354 End data with <CR><LF>.<CR><LF>
# 250 2.0.0 Ok: queued as 9A32A338B96
# 221 2.0.0 Bye
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# Timed out on command: docker exec mail_privacy /bin/bash -c [[ $(ls /var/mail/localhost.localdomain/user1/new | wc -l) -eq 1 ]]
`mail_spam_junk_folder.bats`: 105 checking amavis: spam message is delivered and moved to the Junk folder (MOVE_SPAM_TO_JUNK=1)
not ok 105 checking amavis: spam message is delivered and moved to the Junk folder (MOVE_SPAM_TO_JUNK=1)
# (from function `assert_success' in file test/test_helper/bats-assert/src/assert.bash, line 114,
#  in test file test/mail_spam_junk_folder.bats, line 32)
#   `assert_success' failed
# b6d861c0ba4815248b9143017505b2a3b57a760f4f90e954d96892cf53780ae7
# 
# -- command failed --
# status : 1
# output (20 lines):
#   grep: /var/mail/localhost.localdomain/user1/.Junk/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/.Junk/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/.Junk/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/.Junk/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/.Junk/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/.Junk/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/.Junk/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/.Junk/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/.Junk/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/.Junk/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/.Junk/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/.Junk/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/.Junk/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/.Junk/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/.Junk/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/.Junk/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/.Junk/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/.Junk/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/.Junk/new/: No such file or directory
#   Timed out on command: sh -c docker exec mail_spam_moved_junk sh -c 'grep "Subject: SPAM: " /var/mail/localhost.localdomain/user1/.Junk/new/ -R'
# --
# 
# mail_spam_moved_junk
`mail_spam_junk_folder.bats`: 106 checking amavis: spam message is delivered to INBOX (MOVE_SPAM_TO_JUNK=0)
not ok 106 checking amavis: spam message is delivered to INBOX (MOVE_SPAM_TO_JUNK=0)
# (from function `assert_success' in file test/test_helper/bats-assert/src/assert.bash, line 114,
#  in test file test/mail_spam_junk_folder.bats, line 60)
#   `assert_success' failed
# d2b3c657d99638603b5f562be3dbc4ef9dce7c05ef2b98f7f2ce9470ec691f03
# 
# -- command failed --
# status : 1
# output (20 lines):
#   grep: /var/mail/localhost.localdomain/user1/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/new/: No such file or directory
#   grep: /var/mail/localhost.localdomain/user1/new/: No such file or directory
#   Timed out on command: sh -c docker exec mail_spam_moved_new sh -c 'grep "Subject: SPAM: " /var/mail/localhost.localdomain/user1/new/ -R'
# --
# 
# mail_spam_moved_new
`mail_special_use_folders.bats`: 108 checking normal delivery
not ok 108 checking normal delivery
# (from function `repeat_until_success_or_timeout' in file test/test_helper/common.bash, line 37,
#  in test file test/mail_special_use_folders.bats, line 41)
#   `repeat_until_success_or_timeout 30 docker exec mail_special_use_folders /bin/sh -c '[ $(ls /var/mail/localhost.localdomain/user1/new | wc -l) -eq 1 ]'' failed
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/new': No such file or directory
# Timed out on command: docker exec mail_special_use_folders /bin/sh -c [ $(ls /var/mail/localhost.localdomain/user1/new | wc -l) -eq 1 ]
`mail_with_mdbox.bats`: 159 checking dovecot mailbox format: mdbox file created
not ok 159 checking dovecot mailbox format: mdbox file created
# (from function `repeat_until_success_or_timeout' in file test/test_helper/common.bash, line 37,
#  in test file test/mail_with_mdbox.bats, line 42)
#   `repeat_until_success_or_timeout 30 docker exec mail_with_mdbox_format /bin/sh -c '[ $(ls /var/mail/localhost.localdomain/user1/storage/m.1 | wc -l) -eq 1 ]'' failed
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/storage/m.1': No such file or directory
# Timed out on command: docker exec mail_with_mdbox_format /bin/sh -c [ $(ls /var/mail/localhost.localdomain/user1/storage/m.1 | wc -l) -eq 1 ]
`mail_with_sdbox.bats`: 183 checking dovecot mailbox format: sdbox file created
not ok 183 checking dovecot mailbox format: sdbox file created
# (from function `repeat_until_success_or_timeout' in file test/test_helper/common.bash, line 37,
#  in test file test/mail_with_sdbox.bats, line 42)
#   `repeat_until_success_or_timeout 30 docker exec mail_with_sdbox_format /bin/sh -c '[ $(ls /var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1 | wc -l) -eq 1 ]'' failed
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# ls: cannot access '/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1': No such file or directory
# Timed out on command: docker exec mail_with_sdbox_format /bin/sh -c [ $(ls /var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1 | wc -l) -eq 1 ]

@georglauterbach
Copy link
Copy Markdown
Member

Thanks for providing a PR. Please now have a look at the tests failing to identify the issues. You could for example only turn off recursive changes when LDAP is enabled.

@casperklein
Copy link
Copy Markdown
Member

casperklein commented Oct 20, 2021

I don't understand this PR. So there is an issue with permissions/ownership when LDAP is involved.

Fixing an LDAP issue, while introducing possible issues for existing non LDAP setups doesn't seem a proper way to do it.

With this "fix" applied, what happens when files in subdirectorys of /var/mail have the wrong permission? They won't be fixed and therefore not accessible by dovecot for example.

@polarathene
Copy link
Copy Markdown
Member

With this "fix" applied, what happens when files in subdirectorys of /var/mail have the wrong permission? They won't be fixed and therefore not accessible by dovecot for example.

I think the assumption was that it was not clear what exactly required 5000:5000 ownership within /var/mail to function correctly. The PR author found that functionality for them worked well with their LDAP user permissions, as have other non-LDAP users apparently in the past... while others haven't.

Based on what information I could lookup via git blame and searching issues, it wasn't clear what chown -R on /var/mail was "Fixing permissions" for. Deferred to tests, which then provided a variety of failures, but I don't have time to look into them and delegate that to @MohammedNoureldin to resolve if they want to fix their issue via this PR.

Are you saying that dovecot requires /var/mail to have ownership of 5000:5000 to function correctly?


You could for example only turn off recursive changes when LDAP is enabled.

I don't know if that's an appropriate "fix" if the tests would still fail with LDAP settings. I'm reluctant to approve the PR if it's prone to subtle failures elsewhere that the author hasn't run into themselves.

I haven't looked at the failing tests, so perhaps the risk isn't there for LDAP 🤷‍♂️

@georglauterbach
Copy link
Copy Markdown
Member

@polarathene you're right, I wouldn't approve this either as long as tests fail.

@casperklein
Copy link
Copy Markdown
Member

It wasn't clear what chown -R on /var/mail was "Fixing permissions" for.

If you migrate to a new server/storage etc, or forget to backup permissions as well, the permissions in the data volume may be incorrect. I guess, this fix ensures that all permissions are as expected and the files are accessible by the various services.

Are you saying that dovecot requires /var/mail to have ownership of 5000:5000 to function correctly?

I think so, but cannot confirm this 100%. This was just an assumption based on the current script. I suppose, no one would introduce a fix for permissions, when there aren't any issues that could arise.

@MohammedNoureldin
Copy link
Copy Markdown
Contributor Author

MohammedNoureldin commented Oct 20, 2021

Hi guys, sure I will take a look on the tests that fail in the evening.

@casperklein overwriting the current permissions is definetely not a fix, this is in best cases a workaround to get things working when the user uses somehow wrong permissions (like copying the folders from another system without their permissions). However, this destroys the whole permissions for the other users who know that they really need custom permission configurations. IMO, the least painful and risk form of this workaround is to keep it but do not use it if LDAP is used, though this is not nice at all, it will work at least for all (hopefully). But for me it seems like it can be removed safely, as it is not needed to recusively change all permissions, only changing /var/mail should be sufficient. Or what do you think?

From what I saw quickly, Dovecot does not need necessarily uid 5000 to work, I myself use different uid -> different owners of folders and it works perfectly, of course, till I restart my container and all owners are overwritten to 5000 :(.

Sorry I cannot reply to all comments now as I am doing a short break, but I will take care about them as said in the evening.

@MohammedNoureldin
Copy link
Copy Markdown
Contributor Author

MohammedNoureldin commented Oct 20, 2021

Hello again @polarathene @georglauterbach @casperklein,

I took a look on the tests, I don't fully understand why it is not able to find a specific folder under /var/mail, probably it is not able now to write these folders, but I am not sure why.

So here I need some help from you please, what would you suggest either to fix the tests (I am not sure if fixing the tests is a good idea here), or do you suggest anything else to change in the code to make the tests no fail? What would you suggest? Will only checking if LDAP is activated and execute the code otherwise sufficient?

I still have the opinion that this recursive owner changing is not required, and is rather not good, but I don't want to trigger a big refactoring here. Any small fix that gets things to work properly for both LDAP and non-LDAP is fine.

Any suggestions what I should do further?

@polarathene
Copy link
Copy Markdown
Member

@polarathene you're right, I wouldn't approve this either as long as tests fail.

@georglauterbach

I was more referring to not hacking around the tests (eg: a feature flag that applies this PR only to LDAP users, when the failing tests are not configured for LDAP, so the tests pass), or modifying the tests to pass in a manner that hides the issue as well.


If you migrate to a new server/storage etc, or forget to backup permissions as well, the permissions in the data volume may be incorrect. I guess, this fix ensures that all permissions are as expected and the files are accessible by the various services.

@casperklein

I already pointed out that case as one of a few related to the issue this PR is addressing in this reveiw comment. Although it's not clear why that's happening.

I think so, but cannot confirm this 100%. This was just an assumption based on the current script. I suppose, no one would introduce a fix for permissions, when there aren't any issues that could arise.

See the same link I just provided. This "fix" was introduced in the very first commit of the project by the original author.

They've not always made sound choices and didn't seem to explain it's purpose during a relevant discussion I linked, I can't say I'm confident in the choice based on the history I dug up. They likely went with it because "it works for me" as a fix at the time.


But for me it seems like it can be removed safely, as it is not needed to recusively change all permissions, only changing /var/mail should be sufficient. Or what do you think?

@MohammedNoureldin

Without looking into the failing tests, I would like to know that they would pass for an LDAP setup if you applied your PR via a feature toggle (doesn't have to be LDAP specific).

My concern is that if tests are failing, just because you don't notice any issues doesn't mean that there are none, or that it won't affect other LDAP users as a result. This would be less of an issue by using an opt-in ENV, but I am not particularly fond of that either without a proper understanding of why it's needed (not your requirement, but why we can't use it by default due to tests failing).


I took a look on the tests, I don't fully understand why it is not able to find a specific folder under /var/mail, probably it is not able now to write these folders, but I am not sure why.

Permissions....? That's literally what this PR is changing.

The good news is that they were all ls and grep commands. Review the tests and how the filepaths that are checked are added/created. Try identify where the permissions are coming from, presumably it's the host system rather than the container. If the UID and GID make the files inaccessible to docker-mailserver, that's an issue.

What might work is just recursively adding the GID 🤷‍♂️ But then that should work for you if your LDAP users belonged to the 5000 group within docker-mailserver (should any UID from that group try to interact with the files). One of the linked issues in my review was about GID, but the user wanted to use a different GID within the container to match the one they already had host users sharing, I don't consider that an issue to worry about though.

When you have identified the failure cause for tests and can detail it here, we can discuss further.

What would you suggest? Will only checking if LDAP is activated and execute the code otherwise sufficient?

You may consider adding an ENV to ignore applying the chown -R, it should be opt-in by default.

Personally I would prefer you still look into the test failures for more information as to why they're failing, as if you add that ENV it should probably come with supporting tests anyway.

I still have the opinion that this recursive owner changing is not required, and is rather not good, but I don't want to trigger a big refactoring here. Any small fix that gets things to work properly for both LDAP and non-LDAP is fine.

While I agree, we need to understand why that is not the case with the tests first.

I was not able to dig up anything in project history that demonstrates what the permissions are being fixed for. We do thankfully have failing tests that should help enlighten us on that, but I do not have the time to do so myself.

If you want to resolve this, you'll need to investigate and find this information.


Any suggestions what I should do further?

Yes. If you do not want to pursue the above, you can choose to volume mount your fix over the related file within the container on your end instead of upstreaming it here. I assume user-patches.sh wouldn't work, otherwise I'd advise that and adding to our documentation the workaround.

The other maintainers may be fine with the opt-in ENV to disable the chown -R as well, but it would be great to at least try look into the test failures a little for insights.

@casperklein
Copy link
Copy Markdown
Member

You may consider adding an ENV to ignore applying the chown -R, it should be opt-in by default.

When I look in /var/mail/example.com/postmaster/new, I see that new mails have this permission -rw-r--r-- 1 5000 5000. So this is how the permissions are expected by dovecot. Therefore we should keep the permission fix.
When this is problematic for LDAP setups, an ENV to make it configurable is a good idea.

@polarathene
Copy link
Copy Markdown
Member

When I look in /var/mail/example.com/postmaster/new, I see that new mails have this permission -rw-r--r-- 1 5000 5000. So this is how the permissions are expected by dovecot.

So the tests are failing because we're providing data that's not using 5000:5000 I take it? (where container startup would usually set that)

If so, then we can safely have that data chown -R 5000:5000 instead prior to starting the container. A similar command could be added to setup.sh for convenience I guess, or just documented for troubleshooting, as this is only an issue when providing foreign data?

Therefore we should keep the permission fix.

I don't mind keeping it, when it's clear what the permission fix is actually required for. It should then be more explicitly mentioned that we're fixing permissions for that purpose.

But currently, what I'm hearing is that at runtime without LDAP, Dovecot works with 5000:5000 as expected. Not that it's running into any issues by not chown -R on /var/mail. We do not need to force the chown unless there's a valid reason for doing so (eg: permissions can somehow become incorrect for other situations that aren't data migration).

When this is problematic for LDAP setups, an ENV to make it configurable is a good idea.

If it can be identified that it's actually an issue for non-LDAP environments.

No point adopting a new workaround ENV if the problem wouldn't ever occur regardless when docker-mailserver is never provided foreign data to /var/mail.

@MohammedNoureldin
Copy link
Copy Markdown
Contributor Author

MohammedNoureldin commented Oct 20, 2021

@polarathene @casperklein I am working quickly on restoring the old condition and adding a new condition to check if LDAP is active. Nevertheless, I am still a bit not very comfortable with this, because I don't like having this chown -R at all, which may ruin my permissions somehow in the future, while we don't really know why it is needed.

Do you suggest anything else as a hotfix for this?

Distinguish between LDAP actived and disabled cases when changing the owners in */var/mail* to avoid overwriting the permissions and owners of mail folders for LDAP users.
@polarathene
Copy link
Copy Markdown
Member

adding a new condition to check if LDAP is active.

I won't approve of that unless proven that it's required. Add an opt-in ENV instead.

I still prefer you actually look into the test failures and the cause. Your quite possibly wasting effort on an alternative when your original PR here can be accepted provided you look into the test failures instead of hand-waving the failure away behind an ENV.

If you add the opt-in ENV, I want to know that those test failures will pass with the ENV when the tests are configured for LDAP. Otherwise, you will need to document that the ENV is not supported officially and may risk unexpected breakage/failures.


I don't like having this chown -R at all, which may ruin my permissions somehow in the future, while we don't really know why it is needed.

Then investigate it as has been suggested. You've been provided insights in the discussion here already.


Do you suggest anything else as a hotfix for this?

You can maintain the patch on your end, as was suggested earlier if you don't want to do what is required for upstreaming a fix.

@MohammedNoureldin
Copy link
Copy Markdown
Contributor Author

Then investigate it as has been suggested. You've been provided insights in the discussion here already.

I will work on getting more time to investigate this. Nevertheless, I would appreciate if anyone can check the first test that fails and tell me what he thinks about it when you have time. Because it was not really clear for me why the file is not being written to the expected folder and why is this happening.

You can maintain the patch on your end, as was suggested earlier if you don't want to do what is required for upstreaming a fix.

I would like it merged to the upstream, so nobody else faces this issue :)

@polarathene polarathene added this to the v12.0.0 milestone Jun 10, 2022
@georglauterbach georglauterbach modified the milestones: v12.0.0, v13.0.0 Mar 3, 2023
@georglauterbach georglauterbach added meta/needs triage This issue / PR needs checks and verification from maintainers kind/bug/report A report about a bug kind/bug/fix A fix (PR) for a confirmed bug and removed kind/bug priority/low meta/needs triage This issue / PR needs checks and verification from maintainers kind/bug/report A report about a bug labels Apr 6, 2023
@georglauterbach
Copy link
Copy Markdown
Member

This has stalled significantly. As part of #3289, I will close this (see my rationale here: #3289 (comment)).

@MohammedNoureldin this does not mean these changes are not worthwhile; I just cannot maintainer PRs that are years old. When you have the time, please propose a working set of changes on the most recent version of master with a new PR :)

@polarathene
Copy link
Copy Markdown
Member

This was intended to be investigated once the test suite was fully migrated to the new structure. LDAP did not get to that point for v12.

This has not been an issue raised by many other LDAP users AFAIK, there has been little involvement since the issue / PR was opened. If someone were to be faced by this problem and wants to resolve it, my advice is to do the following:

  • Remove the chown -R
  • Add that removed logic into a setup ... command with troubleshooting documentation.
  • IIRC there was a scenario where chown -R here was necessary (at least for non-LDAP). It may have been related to a feature or initial creation of mailboxes. DMS upgrades should be fine as the UID + GID for docker is hard-coded to 5000.

Seeing as it doesn't affect all LDAP users, I assume it's config specific or affected by choice of LDAP provider.

@MohammedNoureldin
Copy link
Copy Markdown
Contributor Author

Hi, thanks for notifying me @georglauterbach, I will check it again for sure once I have more time again.

@polarathene it is kind of configuration-specific, but not fully. If the administrator is OK to get all emails owned by the user 5000, then the issue will not appear. On the other hand, if every single LDAP user (with unique ID) should own only his own emails on the Linux system (chown) then the issue will appear.

So it will not appear in the less-secure option I would say, but it should be definitely be checked somewhen.

@AntiBlueQuirk
Copy link
Copy Markdown

AntiBlueQuirk commented Aug 4, 2023

Specifically, I think this is caused by including uid and gid in DOVECOT_USER_ATTRS. I'm a little fuzzy on the details, but Dovecot actually tries to switch the process to the uid and gid of a user when accessing mail. Normally, DMS gets around this by just setting all users to use the same uid and gid: 5000:5000. When using a manual user database, you can see this is set here in accounts.sh. I'm guessing similar permission problems are caused if you change the uid and gid of users in the manual user database.

When using LDAP, you can tell Dovecot to get the uid:gid from the database, which it will then switch to when accessing mail. Since the directories are all chowned to 5000:5000, this causes Dovecot to not actually be able to access the user's mail. You can manually correct the permissions, which makes Dovecot work correctly, but I was still having delivery problems.

I was using uidNumber=uid,gidNumber=gid as part of DOVECOT_USER_ATTRS, but right now I've replaced it with =uid=5000,=gid=5000, which makes all LDAP users use 5000:5000. It seems to be working now. I would prefer to keep the proper user permissions, but I like having working mail more.

@polarathene
Copy link
Copy Markdown
Member

I would prefer to keep the proper user permissions, but I like having working mail more.

The discussion above had attempted to only apply the chown -R 5000:5000 for non-LDAP config IIRC (or remove it completely, I think both were tried), but this caused test failures. So while we're happy to allow such logic for a better LDAP experience, someone has to spend time looking into why tests were failing.

We apply this chown at container startup, but also with the change-detection service. Presently that is only valid for non-LDAP config but there is a desire to enable change-detector (at least partially) for LDAP users as well.

A lot has happened with the project codebase since this PR was attempted, quite a bit of refactoring in our test suite and code related to this PR/issue.

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 meta/needs triage This issue / PR needs checks and verification from maintainers service/ldap stale-bot/ignore Indicates that this issue / PR shall not be closed by our stale-checking CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Restarting the container changes the owner of folders in /var/mail to 5000

6 participants