-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
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
doas ignores environment variables set up in PAM, leading to many issues on NixOS #158988
Comments
I think I ran into this when running At first I assumed
Assuming this is because PATH is set by pam as per this issue. Can the workaround be included in my nix system configuration or does it need to be added to nixpkgs instead? |
Note: doas currently has issues with env vars set using PAM. This means `PATH` is broken, amoung other things, even when `keepEnv` is enabled. See NixOS/nixpkgs#158988
As described in <NixOS/nixpkgs#158988>.
Is there a reason not to upstream this workaround into the |
Because it's really an eyesore 😬 And anyway, the upstream project seems kinda dead. I removed it from my conf and installed |
Oh actually, |
The initial weird bug
I wanted to set my time locale to ISO-8601, so I did:
but then, using
doas
to getroot
printed some warningsbut
date
in that root shell was using the correct localeI still investigated a bit and found that
doas date
did not use the correct locale !???After spending way too many hours troubleshooting this mystery, I finally found the root cause: Duncaen/OpenDoas#2. It can also lead to many others difficult to understand issues..
Explanations
NixOS relies on some environment variables to be set to work properly.
For example,
PATH
must include/run/wrappers/bin
for SUID bins,/run/current-system/sw/bin
for system bins and/etc/profiles/per-user/$USER/bin
for user bins.We'll come back to
PATH
later.Another important one is
LOCALE_ARCHIVE
, which is used by Nixpkgs' patchedglibc
to find which locale archive to load.Basically, the patch first tries to lookup
LOCALE_ARCHIVE
and if unsuccessful, loads a basic archive with only the "C/POSIX" locale available.(more info can be found here also: #85823)
To ensure that they are set everywhere, NixOS configures PAM to include them in all new sessions:
https://github.com/NixOS/nixpkgs/blob/nixos-21.11/nixos/modules/config/system-environment.nix#L68
https://github.com/NixOS/nixpkgs/blob/nixos-21.11/nixos/modules/security/pam.nix#L573
Unfortunately
doas
ignore those: Duncaen/OpenDoas#2.This makes binaries started with
doas
behave incorrectly on NixOS:locale-archive
will fail to load and fall back to a basic one. However, login shells also source/etc/set-environment
which also load those variables. This doesn't solve the locale issue for the shell because the locale-archive is loaded only at startup time but it makes programs started from the shell behave correctly.LOCALE_ARCHIVE
, the user env inPATH
(/etc/profiles/per-user/$USER/bin
),NIX_PATH
, the XDG vars,INFOPATH
,LD_LIBRARY_PATH
and many others. Right now thePATH
has some nix-specific paths thanks to this patch: https://github.com/NixOS/nixpkgs/blob/nixos-21.11/pkgs/tools/security/doas/0001-add-NixOS-specific-dirs-to-safe-PATH.patchFor example, on my machine,
git
is installed through home-manager and so is in/etc/profiles/per-user/$USER/bin
.Scripts launched with
doas
will not findgit
.They'll also fail to load any locale.
Comparing with sudo
Solutions
Fix doas
The obvious solution is to make
doas
set the vars given by PAM, just likesudo
. I'll speak with the maintainer referring to this issue.Work around
Since we control what goes in
/etc/pam/environment
, we can also set them in/etc/doas.conf
.It's an eyesore and can cannot handle variable interpolation like PAM, but here's my workaround:
Inform the users?
In the meantime, I think we should update the docs to warn NixOS users of those shortcomings and workarounds.
This is especially important because those bugs are difficult to analyze, and it is very unexpected that
doas
ignores PAM env vars.The text was updated successfully, but these errors were encountered: