Skip to content
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

Need a way to change user/group after listening sockets are opened #415

Open
cminyard opened this issue Aug 23, 2024 · 2 comments
Open

Need a way to change user/group after listening sockets are opened #415

cminyard opened this issue Aug 23, 2024 · 2 comments

Comments

@cminyard
Copy link

To open the necessary sockets, like 53, you need to run as root. However, once you have them opened, it's good security practice to drop privileges to some other user.

@qaako
Copy link

qaako commented Sep 12, 2024

This functionality is already provided by core linux utilities. If you are using systemd, there are many hardening options. You can set the AmbientCapabilities field, you can set User and Group, there are also many other systemd-specific hardening features that I am not even familiar with.
Maybe you already know this, but if you don't know where to start, I would recommend setting AmbientCapabilities=CAP_NET_BIND_SERVICE and DynamicUser=yes which seems to be more preferred compared to {User,Group}=nobody.

Personally I am using runit and it also has its own implementation of changing user/group of services. I just run as group/user=nobody and have cap_net_bind_service set on the executable itself. This is probably somewhat less secure than setting cap_net_bind_service for the specific service only, but it's more than satisfying enough for my personal use.

If you already knew all of this, and still want this functionality to be re-implemented in the program, then I am not in a position to comment with very much weight because I am just a user like you, but I would assume that duplication of existing functionality that's already provided elsewhere would needlessly increase code complexity.

@cminyard
Copy link
Author

If you already knew all of this, and still want this functionality to be re-implemented in the program, then I am not in a position to comment with very much weight because I am just a user like you, but I would assume that duplication of existing functionality that's already provided elsewhere would needlessly increase code complexity.

Yes, I know all this. You can set capabilities like this, but that is still not best. It's best to drop all capabilities that you do not need. And it's not that hard. But as you say, just having CAP_NET is certainly a lot better than having everything, and probably enough for most people.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants