Skip to content

Conversation

Arceliar
Copy link
Member

This is built on #804 (thanks @tsuraan)

It's essentially identical to that PR, except it wraps the syscalls in a separate function, so we can return an error on platforms where this isn't supported (which seems to at least include windows).

I'm not sure exactly what build directives make the most sense here... at the moment, it only supports linux, darwin, freebsd, and openbsd, but maybe !windows is more correct.

We should probably think a bit about what behavior we want. If we always want to drop permissions, then we could maybe skip the -uid and -gid args, and hard code a specific user to switch to (nobody or whatever makes the most sense).

Jeremy Groven and others added 3 commits July 6, 2021 16:39
yggdrasil seems to prefer to run as a privileged user, but it also seems
to work fine if permissions are dropped after the socket initialization
is performed. This adds -uid and -gid flags so that an instance run with
root perms can drop them once it's ready.
@zander
Copy link
Contributor

zander commented Jul 24, 2021

The creation of the socket file is a filesystem permissions issue.

It is at best very unconventional to solve this filesystem permissions issue the way this PR suggests: starting out as superuser and trusting ygg to drop to the permissions it wants.
Honestly, this is not a clean solution to solve a simple "This user can not write in this dir" problem.

@Arceliar
Copy link
Member Author

This isn't just about the socket file. If the process was started as root, then there's no reason to keep running as root after the point where elevated permissions may have been needed. A long standing issue in go prevented this until recently.

@neilalexander neilalexander self-requested a review July 24, 2021 19:01
@neilalexander
Copy link
Member

Adding my own review to remind me to test this on macOS and FreeBSD.

logger.Infoln("Setting gid to:", args.rungid)
if err := setgid(args.rungid); err != nil {
logger.Errorln("Failed to set gid:", err)
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of simply returning, you likely want to abort() here.

Not being able to change gid/uid (or egid/euid) is not a failure you should ignore and then simply continue running.

@neilalexander
Copy link
Member

Closing in favour of #927.

neilalexander added a commit that referenced this pull request Sep 22, 2024
different from
#817 in that it
can resolve user names, automatically use user's primary gid & allows
specifying gid in the same argument, with `:` eg `username:groupname`.
feel free to criticize & suggest different argument name & description
because i didn't put much of thought to that.

---------

Co-authored-by: Neil <[email protected]>
Co-authored-by: VNAT <[email protected]>
Co-authored-by: Neil Alexander <[email protected]>
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

Successfully merging this pull request may close these issues.

3 participants