Skip to content

chore: Remove redundant capability SYS_PTRACE#2624

Merged
polarathene merged 3 commits intodocker-mailserver:masterfrom
polarathene:chore/remove-redundant-capability-sysptrace
Jun 6, 2022
Merged

chore: Remove redundant capability SYS_PTRACE#2624
polarathene merged 3 commits intodocker-mailserver:masterfrom
polarathene:chore/remove-redundant-capability-sysptrace

Conversation

@polarathene
Copy link
Copy Markdown
Member

Description

This capability was added as part of the original check-for-changes.sh feature PR in Oct 2017:

  • The original explanation for needing this was detailed in an associated issue comment, but it is unclear if they were referring to the earlier postfix reload commit, or the supervisorctl restart postfix line that replaced it.
  • A review comment expressed a concern with using postfix reload that may possibly lead to a process (which one?) losing a PID (for Postfix?).

In June 2018, the SYS_PTRACE requirement was clarified:

Without SYS_PTRACE one of the unit tests fails with several of these in syslog:

Jun 20 08:51:22 mail postfix/postfix-script[2964]: fatal: the Postfix mail system is already running

I think the postfix script is trying to connect to the master process with the saved pid and fails without SYS_PTRACE.
I haven't seen this on my server so far, but perhaps the tests are doing something that doesn't happen very often.

and:

This can happen when the system is running as well. The postfix management script needs SYS_PTRACE.

That is still a bit vague. None of the current unit tests seem to fail anymore. I assume the referenced "postfix management script" is wrappers/postfix-wrapper.sh?

postfix-wrapper.sh was introduced in Aug 2017 (as part of adding supervisord into the image), so a little bit earlier than the change detection service. The wrapper purpose is described:

Some processes are not single processes like postfix and fail2ban and they have a wrapper.
The wrapper takes care of proper shutdown and checking if the process is running or not. Supervisored will restart the wrapping script if the process is gone.


I'm not sure what has changed since. Perhaps @casperklein or @georglauterbach know of a reason to keep SYS_PTRACE around?

I'd also like to understand the intent to require restarting Postfix and Dovecot, as opposed to postfix reload /dovecot reload. This was used prior to adopting supervisord (and the wrapper scripts that it seemed to require?). All I have to go by is the concern that maintainer expressed with a PID possibly being lost.

Type of change

  • Improvement (non-breaking change that does improve existing functionality)

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation (README.md or the documentation under docs/)
  • New and existing unit tests pass locally with my changes

Doesn't seem to be required. It was originally added when the original change detection feature PR apparently needed it to function.
@polarathene polarathene added area/tests kind/improvement Improve an existing feature, configuration file or the documentation area/documentation area/configuration (file) labels Jun 6, 2022
@polarathene polarathene added this to the v11.1.0 milestone Jun 6, 2022
@polarathene polarathene self-assigned this Jun 6, 2022
@casperklein
Copy link
Copy Markdown
Member

Older Postfix versions < 3.4.7-2 shipped with the following line in the init script, to determine whether the process is running or not:

dir=$(ls -l /proc/$pid/exe 2>/dev/null | sed 's/.* -> //; s/\/[^\/]*$//')

That required the Docker container SYS_PTRACE capability.

Reference: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=941293

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 6, 2022

Documentation preview for this PR is ready! 🎉

Built with commit: 66f7cf7

@polarathene
Copy link
Copy Markdown
Member Author

@casperklein Oh awesome thank you so much for sharing that! 😁

Good to know this is safe to go ahead with then :)

@polarathene polarathene merged commit 62fdcb0 into docker-mailserver:master Jun 6, 2022
@polarathene
Copy link
Copy Markdown
Member Author

@casperklein would this also mean that the wrapper scripts aren't likely required anymore? At least for Postfix?

Or do you know if the concerns about losing PID remain valid for using postfix reload in check-for-changes.sh instead of supervisorctl restart postfix?

@casperklein
Copy link
Copy Markdown
Member

The wrapper script is (still) needed, because:

# You cannot start postfix in some foreground mode and
# it's more or less important that docker doesn't kill
# postfix and its chilren if you stop the container.
#
# Use this script with supervisord and it will take
# care about starting and stopping postfix correctly.

However, there should be no problem when issuing service postfix reload etc.

Not sure if I understood your question correctly, let me know if not 😉

@georglauterbach
Copy link
Copy Markdown
Member

The wrapper script is (still) needed, because:

# You cannot start postfix in some foreground mode and
# it's more or less important that docker doesn't kill
# postfix and its chilren if you stop the container.
#
# Use this script with supervisord and it will take
# care about starting and stopping postfix correctly.

What about https://serverfault.com/a/916072?

@casperklein
Copy link
Copy Markdown
Member

I didn't know that. That might be worth investigating/testing. Not sure, if the things sekretts mentions in his comment could cause problems in our setup.

@polarathene
Copy link
Copy Markdown
Member Author

polarathene commented Jun 14, 2022

What about https://serverfault.com/a/916072?

I'm not sure what benefit there is from starting Postfix in foreground mode for a multi-service/process container? Isn't this the difference between docker-compose up and docker-compose up -d? Or is this different because supervisord is handling it, and foreground mode would be preferable there?

Postfix 3.3 (Feb 2018) and Postfix 3.4 (March 2019) mentioned in the link at least does mean those were not available originally in Oct 2017 when the wrapper workaround was added. So I suppose it could be worth looking into.

Not sure, if the things sekretts mentions in his comment could cause problems in our setup.

Someone running Podman Rootless had some odd permission issues occur, not sure why though:

#2630 (comment)

It affected /var/spool/postfix/private rather than /var/spool/postfix/etc, although this was with our current image not the suggested alternative way to start Postfix.


However, there should be no problem when issuing service postfix reload etc.

This was apparently an issue cited around the same time, some concern about losing a PID. The maintainer at the time did not clarify the concern that well.

@casperklein
Copy link
Copy Markdown
Member

casperklein commented Jun 15, 2022

I'm not sure what benefit there is from starting Postfix in foreground mode

No benefit, but a requirement for supervisord. Because postfix did not support foreground mode in the past, the wrapper script was needed.

  1. supervisord expects the command to be running in the foreground, so that signals like SIGTERM can be passed through. command=service postfix start for example is a one-shot (it immediately exits after execution, so no signals can be passed).
  2. More important, if the command exits, supervisord "thinks" the process is gone and trys to restart, since we set autorestart=true in target/supervisor/conf.d/supervisor-app.conf. This leads to an endless restart loop (postfix is running, but supervisord falsely think its gone and trys to restart it)

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

Labels

area/configuration (file) area/documentation area/tests kind/improvement Improve an existing feature, configuration file or the documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants