this post was submitted on 13 Apr 2024
230 points (84.8% liked)

linuxmemes

20437 readers
1412 users here now

I use Arch btw


Sister communities:

Community rules

  1. Follow the site-wide rules and code of conduct
  2. Be civil
  3. Post Linux-related content
  4. No recent reposts

Please report posts and comments that break these rules!

founded 1 year ago
MODERATORS
 

Credit for the answer used in the right panel: https://serverfault.com/a/841150

you are viewing a single comment's thread
view the rest of the comments
[–] mholiv@lemmy.world 85 points 4 months ago (2 children)

When you hate something so much you have to find weird corner cases to support your views. Even then the way described isn’t how someone who knows that they are doing would do.

The best way for an unprivileged user to manage a service is for that user to run it. That way you inherit the correct permissions / acls / selinux contexts.

The command to do so is:

systemctl --user start the_service.service

[–] sorrybookbroke@sh.itjust.works 11 points 4 months ago* (last edited 4 months ago) (3 children)

What if multiple users have to manage that service?

Edit: nvrmnd, pretty sure the runnit solution won't allow this either, your answer is correct. What about while the service is already running? Wouldn't your solution require a restart?

[–] mholiv@lemmy.world 12 points 4 months ago (1 children)

If the service is already running it has to be stopped as a system service and run as a user service. In order to ensure that the service inherits all the correct permissions / acls / se linux policies the service needs to be launched from the limited permissions context.

With the systemd approach you’re not just passing a control handle around. You’re ensuring the process is running under an appropriate security context.

If you want to let multiple users manage the user systems service, I would probably go with sudo and systemd user files. You could create a group which has sudo access etc. The important idea is that an unprivileged user controls an unprivileged service.

[–] renzev@lemmy.world 3 points 4 months ago

With the systemd approach

What about this makes it "the systemd approach"? runit supports user services too. These are just two different tasks that are needed in different contexts. Sometimes what you need is to "pass a control handle around" to a privileged service. And sometimes you need to actually make a service unprivileged.

[–] renzev@lemmy.world 5 points 4 months ago* (last edited 4 months ago)

pretty sure the runnit solution won’t allow this either

I'm no expert, but I think you could make a special group, set the supervise directory to be owned by that group, and add all relevant users to that group? Either way, as I explained in a different reply, running the service as a user vs letting that user control a root service are completely different things, and one is not always a substitute for the other.

[–] MashedTech@lemmy.world 4 points 4 months ago* (last edited 4 months ago)

A generic stack overflow answer:

Do you REALLY need multiple users to manage that service? Maybe it's better to have multiple instances of that service and.... (This goes on and on)