Description
Sometimes it's desirable to have files in the Nix store that are not world-readable, such as configuration files containing passwords. This could be implemented as follows:
- Private files are marked as such by giving them a certain magic prefix to the name, e.g.
p:
. When these are registered, Nix should make them readable only to root (permission 0700) and the calling user (using an ACL). (The Nix daemon knows the uid of the caller.) - The permissions on a derivation should be propagated to the output paths. Also, private derivations should be run with a umask of 0077.
- If another user attempts to register an already valid private file, then its uid should be added to the ACL of the file. If it's a derivation, then the uid should also be added to the ACLs of any valid outputs.
- Store operations that read files from the store (such as
exportPath()
) should check that the caller is in the ACL of the file.
So, for instance, if the root user builds a NixOS configuration containing some private files, then those files are only readable as root. If Alice builds the same configuration, then those files will be readable by root and Alice. If Alice then uses Charon to copy the configuration to a remote machine (i.e. nix-copy-closure --to root@remote ...
), then the files on the remote machine will only be readable by root.
This model only allows files that are private to the instantiating user and root. So it doesn't support specifying a file that is readable only to the sshd
user. But that's probably not necessary.