-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow configuring the unix socket owner and group #89
Comments
Hello, @PhrozenByte! Thanks for a great idea! I'm thinking about another way to solve this. Systemd has some feature called "socket activation". Basically, it opens socket and runs specified unit process. Daemon process inherits already open socket from systemd launcher process and reads from environment fd number to pick up. This way we can delegate creation of socket to system facilities. I think it is a strictly superior approach for following reasons:
That should be quite easy to implement: just read few env vars and instantiate listener from fd. However, I don't think I'll be able to handle that soon because of quite tight workload. If you can contribute implementation of such approach, your PR will be welcome. Please tell what do you think about this. |
I like the idea! 👍 However, IMHO there must be a Systemd-independent solution. I'm running |
Hi, I'm a nosy bystander. In the meantime, I confirm this does work (as suggested upthread):
In the meantime, I confirm this does not work:
It works if systemd-tmpfiles runs after the daemon is running and the socket exists:
It does not work if systemd-tmpfiles runs before the daemon:
|
Is your feature request related to a problem? Please describe.
Similar to #45 I'd like to implement finer access to the
mta-sts-daemon
's unix socket. Right now I must add Postfix to the primary group of the user runningmta-sts-daemon
to use more restricted permissions like 660 for the socket. However, this still gives Postfix more access than it actually needs, because Postfix can then not just access the socket, but any other group-accessible file - i.e. usually all files of the user runningmta-sts-daemon
.Following the principle of least privilege (POLP), I'd like to change the unix socket's owner and group, not just its mode.
Describe the solution you'd like
Since
chown
ing files isn't possible for unprivileged users, it must be possible to startmta-sts-daemon
with root privileges and let the daemon drop its permissions to a configurable unprivileged user after creating the socket. As a side effect, this also allows users to bind to ports < 1024 without permanently running the daemon as root.Accordingly there should be three more config options: Two options to set the unix socket's owner and group respectively, and another option to set the unprivileged user to run the daemon with. Since the naming of the config options will likely cause confusion (owner of the unix socket vs. unprivileged user running the daemon), I'd recommend to change the config structure as follows (also move
host
,port
, andreuse_port
to thelisten_on
section, but still support the old configs to preserve BC):When running
mta-sts-daemon
as root, it will first create the socket/path/to/unix.sock
(owned bymta-sts-sock:mta-sts-sock
, mode 0600) and then drop its privileges to usermta-sts
. When trying to startmta-sts-daemon
as an unprivileged user, the daemon should bail, unless the executing user matches bothuser
andlisten_on.user
.Describe alternatives you've considered
In theory, one could add the
mta-sts
user to themta-sts-sock
group and then addExecStartPost=/usr/bin/chown mta-sts-sock:mta-sts-sock /path/to/unix.sock
to the Systemd unit file, but I didn't test it.On a side note, when using the
fork
syscall for a native implementation as suggested before, themta-sts
user isn't required to be a member of themta-sts-sock
group, because the unprivileged child process would inherit the open socket from the privileged root process.Additional context
A lot of ❤️ for your awesome project, keep up the great work, thank you! 👍
The text was updated successfully, but these errors were encountered: