I am working with Dovecot 2.3.4.1 and EncFS (encfs version 1.9.5) encrypted mailboxes on Debian 10 (no SELinux)
Basic setup is:
EncFS mounted with
encfs --public /var/encrypted-mail /var/decrypted-mail -o nonempty --verbose
Mailbox-Setup:
/var/decrypted-mail/domain.com/foo@domain.com/[cur,new...]
drwx------ 8 mail mail 4096 Dec 29 2019 /var/decrypted-mail
(those permissions are recursive)
All dovecot processes run as mail
user:
mail 5194 0.0 0.0 6308 4312 ? S 14:52 0:00 dovecot/imap
Despite everything seemingly being configured correctly, I can not create new folders or rename existing ones.
I get this error in the /var/log/dovecot.log
:
Jan 24 14:59:04 imap(foo@domain.com)<6010><Us21sxWS5OZaC6Ex>: Error: Couldn't create mailbox list lock /var/decrypted-mail/domain.com/foo@domain.com/mailboxes.lock: file_create_locked(/var/decrypted-mail/domain.com/foo@domain.com/mailboxes.lock) failed: link(/var/decrypted-mail/domain.com/foo@domain.com/mailboxes.lockba53af3795974a32, /var/decrypted-mail/domain.com/foo@domain.com/mailboxes.lock) failed: Operation not permitted
The source code for that error message resides here: https://github.com/dovecot/core/blob/4d09884528e592a0fa5d38bf479b3ddab1a4a0ef/src/lib/file-create-locked.c#L109-L123
If I read that correctly, it can not use a 'regular locking' mechanisem and tries to symlink a temporary file to mailboxes.lock
.
This indicates, that it COULD create the temporary file mailboxes.lockba53af3795974a32
and is just not able to symlink it.
When I run this command in the shell:
sudo -u mail bash -c 'touch mailboxes.lockba53af3795974a32 && ln -s mailboxes.lockba53af3795974a32 mailboxes.lock'
It works properly and I get no errors.
How is it possible that dovecot behaves so differently from a normal shell?
The only explanation I would have is a timing problem (temp file is accessed before, but why does this not appear in the bash reproduction?).
I also tried chmod -R g+rwx /var/decrypted-mail
, to make sure that all those gids are not the problem, but that was just a desperate attempt to find a fix.