SELinux, incorrect labelling from derivation #546
Labels
No labels
Area/build-packaging
Area/cli
Area/evaluator
Area/fetching
Area/flakes
Area/language
Area/profiles
Area/protocol
Area/releng
Area/remote-builds
Area/repl
Area/store
bug
crash 💥
Cross Compilation
devx
docs
Downstream Dependents
E/easy
E/hard
E/help wanted
E/reproducible
E/requires rearchitecture
imported
Needs Langver
OS/Linux
OS/macOS
performance
regression
release-blocker
RFD
stability
Status
blocked
Status
invalid
Status
postponed
Status
wontfix
testing
testing/flakey
ux
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lix-project/lix#546
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Describe the bug
A clear and concise description of what the bug is.
Given the simple example of generating a systemd service file:
Building it will generate a file with incorrect labels compared to what is described in SELinux (see below).
Running
restorecon -v
against the path will show that this is incorrectly created.Steps To Reproduce
nix repl
and load nixpkgs with:l <nixpkgs>
:b
ls -lhaZ
, see its incorrect compared to what is expected.restorecon -v .../path
and see if it relabels the file or not.Expected behavior
It will label files correctly as described by SELinux.
nix --version
outputnix (Lix, like Nix) 2.91.0
Additional context
The current SELinux file context against /nix/store.
okay so, the thing is, nix (both lix and cppnix) doesn't do anything to the selinux metadata as far as I'm aware; nix is completely selinux unaware.
so i pose the question: what should nix be doing in this situation, given that the derivation builder itself isn't causing the correct xattrs to be placed? (or perhaps it is getting the xattrs wiped, which would be our fault entirely and is certainly a bug!)
further question:
my guess is that the selinux stuff on your system was put there by the installer as, quite frankly, laziness to avoid implementing it properly in nix and thus it's very much only partially applied and only to the paths that matter to installing nix originally. thus I'm wondering how it should actually work if it were done properly.
For context, I hit this issue while looking into the support of System-Manager, which pushes service files to SystemD of a SELinux enabled distro, so we cannot just have unconfied types (from my understanding). https://github.com/numtide/system-manager/issues/115
If this is even feasable to support inside Nix/Lix or System-Manager I do not know.
The NixOS workgroup had some patches for SELinux to allow a quite simple link between /nix/store and /.
There's also some work here https://github.com/NixOS/nix/pull/2670/files from a previous attempt.
well, i am not really convinced in the cleverness in matching special fs paths in derivation outputs but you might be able to achieve what you want using the existing post-build-hook functionality in lix to apply restorecon (though that would only work on builds, not substitutes, which isn't ideal at all).
without someone with selinux expertise to provide guidance as to the reasonable way to integrate selinux with nix, a system that will likely have a lot of complexities to integrate with (sandbox and such; it's a package manager and a docker like thing), i don't think this is likely to happen. but if you can find someone to provide that expertise and maintain it, likely it could be done?
i am also very unsure as to how much scope this feature has: how much of selinux needs to be supported in lix to work properly? i have an idea as to why restorecon was required to begin with (the directory didn't have a label to inherit, probably), but if that's the problem, fixing it requires doing something equivalent to restorecon on every store path, which is doable.
looking through the discussion on 2670 and the other issue about SELinux support, it seems like the reaction to "we need to have extra metadata in the store" is "let the installer deal with just the specific paths in question", which leads to the exact state you arrived at.
i also don't think it's really an acceptable end state of support; it leaves nix upgrade-nix busted and of course system-manager is also going to be busted, since the restorecon stuff is only applied manually to just the store paths you care about.
whether we are going to commit resources to fixing this is another question entirely imo. though i have not polled the core team, i haven't heard it brought up. there is the concern raised by the others that this is some weird sidecar metadata that the nix system just does not natively support and can get out of sync and that is real. but it already gets badly out of sync today with the installer hacks, so i am not convinced by that argument.
per Eelco:
this is very much accurate. it's weird metadata that the store does not natively manage, and it will get desynced. it is quite gross that the labels are not actually transmitted through the system and that they are applied based on file paths.