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

Fix edge case with doas in multi-user install script #4690

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TheOPtimal
Copy link

@TheOPtimal TheOPtimal commented Apr 5, 2021

In the multi-user install script, it is assumed that sudo can parse environment variable declarations, when it infact cannot when sudo is provided by doas. This pull request fixes this by prepending env to the command.

Sudo uses a barebone shell parser, so we need to prepend `env` to
make the environment variables in the commands apply.
@edolstra edolstra requested a review from grahamc April 5, 2021 19:15
@abathur
Copy link
Member

abathur commented Apr 5, 2021

sudo can, in fact, do this:

$ sudo -h
sudo - execute a command as another user

usage: sudo -h | -K | -k | -V
usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user]
usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command]
usage: sudo [-AbEHknPS] [-C num] [-g group] [-h host] [-p prompt] [-T timeout] [-u user] [VAR=value] [-i|-s] [<command>]
                                                                                         ^^^^^^^^^^^
usage: sudo -e [-AknS] [-C num] [-g group] [-h host] [-p prompt] [-T timeout] [-u user] file ...
... snip ...

$ sudo env | grep -e HOME -e POTATO_CHIPS
HOME=/Users/abathur

$ sudo HOME=yep POTATO_CHIPS=sure env | grep -e HOME -e POTATO_CHIPS
HOME=yep
POTATO_CHIPS=sure

As far as I can tell (but this is a bit fuzzy), this functionality was first released in sudo v1.6.9 on or around July 16 2007.

You may need to make a better case for this. Do you have logs demonstrating a failed install?

@TheOPtimal
Copy link
Author

I do infact have a failed install because of this, but I don't have logs. I think the culprit might be because I'm using doas instead of sudo, and aliasing sudo to doas. I'll adjust the pull request title accordingly.

@TheOPtimal TheOPtimal changed the title Fix incorrect syntax with sudo in multi-user install script Fix edge case with doas in multi-user install script Apr 6, 2021
@abathur
Copy link
Member

abathur commented Apr 6, 2021

Thanks for clarifying.

I'm not sure what others will say wrt to whether this is the right approach, but I went ahead and pushed a copy of your branch to my Nix fork to test it out. I ran the new-ish installer tests against it and they came back clean. (This is very new CI functionality--it hasn't really been exercised much yet.) A bonus of running the tests is that they generate a hosted installer you can try out (unless you've already manually fixed up your install?)

You can try it by invoking: sh <(curl https://abathur-nix-install-tests.cachix.org/serve/sk4r2vpgidqqhdh5gss9flqxbmp11c5n/install) --daemon --tarball-url-prefix https://abathur-nix-install-tests.cachix.org/serve

I can also talk you through setting up the same test/installer-generation yourself if you'd rather not take scripts from a stranger. :)

@TheOPtimal
Copy link
Author

You've linked the single-user install script, not the multi-user one.

@abathur
Copy link
Member

abathur commented Apr 7, 2021

You've linked the single-user install script, not the multi-user one.

Sorry. It just needs the --daemon flag:
sh <(curl https://abathur-nix-install-tests.cachix.org/serve/sk4r2vpgidqqhdh5gss9flqxbmp11c5n/install) --daemon --tarball-url-prefix https://abathur-nix-install-tests.cachix.org/serve

@TheOPtimal
Copy link
Author

TheOPtimal commented Apr 8, 2021 via email

@TheOPtimal
Copy link
Author

Any update on getting this merged?

@grahamc
Copy link
Member

grahamc commented Apr 18, 2021

I'm a little bit concerned about this PR: there is no writing down in the patch about why env is needed, plus the high likelihood that a sudo=doas alias in the future could be broken. However, I'm not opposed to this PR. I've asked for an additional set of eyes to look at it, which should happen later today.

@stale
Copy link

stale bot commented Oct 22, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Oct 22, 2021
@TheOPtimal
Copy link
Author

"Later today" went well.

@stale stale bot removed the stale label Oct 22, 2021
@stale
Copy link

stale bot commented Apr 21, 2022

I marked this as stale due to inactivity. → More info

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

Successfully merging this pull request may close these issues.

4 participants