-
Notifications
You must be signed in to change notification settings - Fork 89
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
aur-build: drop privileges with setpriv(1)
#977
Conversation
d925d6a
to
333c9c2
Compare
runuser(1)
There are three cases: 1. If UID==0, drop privileges for user commands (repo-add, gpg, makepkg) 2. If UID>0, raise privileges for root commands (pacman) 3. Otherwise, run the command as-is. This approach and gpg-set-passphrase(1) renders examples/chroot-batch obsolete, demonstrative purposes excepted.
The main difference between both commands is that runuser(1) uses a PAM session while setpriv(1) does not. From a practical perspective, runuser(1) is more lenient with environment variables: $ sudo setpriv --reuid archie printenv HOME DISPLAY /root :0:0 $ sudo setpriv --reuid archie --reset-env printenv HOME DISPLAY /home/archie $ sudo runuser --pty -u archie printenv HOME DISPLAY /home/archie :0:0 $ sudo runuser --pty -u archie -p printenv HOME DISPLAY /root :0:0 Having both HOME and DISPLAY set allows in particular to use `gpg(1)` with a graphical pinentry.
Together with runuser(1), this removes the need for the chroot-batch example.
Printing the runuser(1) command-line is only used in one place. Compose as_user and run_msg instead.
/dev/stdout points to /proc/self/fd/1, which has chmod 700 for the owning process. In particular, when running `aur-repo --status` with setpriv(1) or runuser(1) from a process run as root, the error /dev/stdout: Permission denied occurs. Remove the redirection and only add it if --status-file is specified.
runuser(1) --pty results in messy output, even when the man page claims it does not. The flag was used for the better security advertised in the manual. Instead of removing --pty, switch back to setpriv(1) without --reset-env and USER, HOME, LOGNAME and SHELL set manually.
This way "as_user" can be removed from the "Running makepkg ..." diagnostic
Fix a mistake introduced with 5c7db7e Add a similar `elif` statement for pacman.conf just in case.
This turned out to be a lot more work than anticipated. On the flip-side, using |
runuser(1)
setpriv(1)
Another observation is that this seems much easier in languages exposing |
Yes, but that means using |
There are three cases:
UID == 0
, drop privileges for user commands (e.g.repo-add
,gpg
,makepkg
)UID > 0
, raise privileges for root commands (pacman
)aur-chroot
)This approach and
gpg-set-passphrase(1)
rendersexamples/chroot-batch
obsolete, demonstrative purposes excepted. It can replaced by a corresponding section inaur-build(1)
.