-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
accept-flake-config
allows running commands as root
#9649
Comments
The design flaws around this resulted in the compromise of nix-ci.com: https://twitter.com/puckipedia/status/1693927716326703441 |
This was also the subject of a capture the flag security challenge I authored: https://github.com/ubcctf/maple-ctf-2023-public/blob/main/misc/flakey-ci/solve/flake.nix |
This requires that the user is a trusted-user, right? By default this only root. So the documentation should be updated to more clear reflect, that this setting must be used very careful. |
Part of the issue is that it's not entirely clear what features being in Also, the warning on the
I read this and thought "well, my user already has root access, so that's fine", but
Well, I run macOS, so there aren't any I've also noticed that the documentation for
|
see https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html?highlight=nixConfig#flake-format for what is allowed in nixConfig inside a flake.nix. I think the first warning in the docker documentation regarding the docker group is very similar to the issue at hand https://docs.docker.com/engine/install/linux-postinstall/
But isn't that describing this issue, even if it isn't very detailed? |
Yes, the lack of detail is the issue. Technically it's correct, but it doesn't do a good job of communicating the implications. "Root access" and "passwordless root access" are quite different in my threat model. |
Yeah, that's a great description -- it's detailed and clearly outlines how privilege escalation can be performed (by sharing filesystems between the host and containers) and the consequences of that access (containers can write to the host filesystem). We should have a page like that for the Nix daemon and |
"Root access" and "literally being This |
It is indeed (not just Agreed that it should be flagged out explicitly in the documentation. Would any one care to do that? Beyond just that, it would also be possible to mitigate this a bit by:
|
With your user in |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/help-needed-with-nix-trusted-users-behaviour/8369/4 |
Related: NixOS/nixpkgs#231408 |
Yes, anytime something needs more privileges than it would have by default it's really nice to have a range of options rather than a single "remove the checks; allow everything". Without that it's really hard to have features like this not turn into major vulnerabilities. But of course it's also hard to break privileges up into separate ones and be really sure that one sub-privilege can't possibly be exploited to break out into the other ones, and if you can't guarantee that then security-wise we're no better off than with the single "allow everything" sledgehammer. |
@cumber that could make sense, but even |
Yes, that's exactly the sort of thing I was thinking about when I said splitting privileges is hard to do. It'd need to be even more fine grained, and allow you to restrict the kind of Though TBF, a configuration that said "I'll accept flake config adding to |
Could we specify/use non-root user for invoke remote builders and post-build-hook? |
This can be abused for privilege escalation: NixOS/nix#9649 (comment)
This can be abused for privilege escalation: NixOS/nix#9649 (comment)
I found this issue specifically because I thought setting I also like @9999years suggestion “to have It might also be nice (although complicated and partial) if there was some standardized tagging of nix.conf options that indicated the vulnerability level of different settings (e.g., )
I’m not sure exactly what severities there are, and of course there are always undiscovered vulnerabilities, but indicating in the documentation the ones we are aware of seems quite important. We can have a standardized set of tags that consistently link to detailed descriptions of what they mean, ranging from “no known security issues” to “gives everyone on the Internet
I would be happy to try to update the nix.conf documentation with a first swipe at something like this, but not sure where to start – I created #11066, since I couldn’t find anything that already existed. If you think that issue is important, please give it some 👍 so I know to spend time on it. (But also, if someone else wants to do it, you’re probably better positioned than I am to make it happen). Please also comment on that issue with links to other issues or discussions that point out various known vulnerabilities (preserving those links in the documentation seems important). I’m thinking a single manual page that describes the security issues for each setting in detail, and a small high-vis tag on each setting in the nix.conf page, which links to that section of the security issue page. Making it easy to see and understand the known issues while also not getting in the way of general setting documentation. Documenting this also helps people figure out where we might be able to make improvements by splitting up the functionality into smaller pieces (again, like @9999years suggested re: accepting a list of specific settings for |
FYI Lix has changes to make accept-flake-config loudly tell you it's a bad idea everywhere in the documentation and the output, short of printing a warning to output that it's a bad idea. most recently: https://gerrit.lix.systems/c/lix/+/1541 |
`om ci`: Do not pass `--accept-flake-config` by default NixOS/nix#9649
Describe the bug
With the
--accept-flake-config
option oraccept-flake-config = true
innix.conf
, any flake build (nix build
,nix develop
,nix run
, etc.) gets root access.Steps To Reproduce
Demo here: https://github.com/9999years/accept-flake-config-demo/
Expected behavior
I expected
accept-flake-config
might do something like use untrusted caches, but "root access" is pretty extreme, and the manual doesn't say "enabling this setting is equivalent to giving root access to any flake you interact with" when it describesaccept-flake-config
.nix-env --version
outputnix-env (Nix) 2.18.1
Additional context
I don't think this is a bug per-se, in that the behavior is intended, but I don't think this should be allowed in the general case, and even if it is the manual should make it a lot clearer how dangerous this setting is.
It might be nice to have
accept-flake-config
take a list of settings instead, so that (e.g.)accept-flake-config = allow-import-from-derivation substituters
would allow flakes to set theallow-import-from-derivation
orsubstituters
options, but notbuilders
orpost-build-hook
.Priorities
Add 👍 to issues you find important.
The text was updated successfully, but these errors were encountered: