fix(nix): normalize integration file permissions to 0644
This commit is contained in:
parent
7124c8ed5c
commit
c806c98267
1 changed files with 37 additions and 3 deletions
|
|
@ -62,16 +62,37 @@ fn integration_dirs() -> &'static [&'static str] {
|
|||
"nix/var/nix/gcroots",
|
||||
"nix/var/nix/temproots",
|
||||
"nix/var/nix/daemon-socket",
|
||||
"etc/nix",
|
||||
]
|
||||
}
|
||||
|
||||
/// Nix integration files every user must read (0644).
|
||||
fn integration_files() -> &'static [&'static str] {
|
||||
&["etc/nix/nix.conf", "etc/profile.d/nix.sh"]
|
||||
}
|
||||
|
||||
fn normalize_integration_permissions(root: &Path) {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
for rel in integration_dirs() {
|
||||
let dir = target_path(root, rel);
|
||||
if dir.symlink_metadata().is_ok() {
|
||||
let _ = std::fs::set_permissions(&dir, std::fs::Permissions::from_mode(0o755));
|
||||
let path = target_path(root, rel);
|
||||
let Ok(meta) = std::fs::symlink_metadata(&path) else {
|
||||
continue;
|
||||
};
|
||||
if meta.file_type().is_symlink() || !meta.is_dir() {
|
||||
continue;
|
||||
}
|
||||
let _ = std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755));
|
||||
}
|
||||
for rel in integration_files() {
|
||||
let path = target_path(root, rel);
|
||||
let Ok(meta) = std::fs::symlink_metadata(&path) else {
|
||||
continue;
|
||||
};
|
||||
// Never chmod through a symlink (it could point at the store).
|
||||
if meta.file_type().is_symlink() || !meta.is_file() {
|
||||
continue;
|
||||
}
|
||||
let _ = std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o644));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -802,6 +823,19 @@ mod tests {
|
|||
}
|
||||
let payload_mode = std::fs::metadata(&payload).unwrap().permissions().mode() & 0o777;
|
||||
assert_eq!(payload_mode, 0o700);
|
||||
// Integration files become world-readable; symlinks are never
|
||||
// followed.
|
||||
let conf = root.join("etc/nix/nix.conf");
|
||||
std::fs::create_dir_all(conf.parent().unwrap()).unwrap();
|
||||
std::fs::write(&conf, "experimental-features = nix-command flakes\n").unwrap();
|
||||
std::fs::set_permissions(&conf, std::fs::Permissions::from_mode(0o600)).unwrap();
|
||||
let link = root.join("etc/nix/link.conf");
|
||||
std::os::unix::fs::symlink(&conf, &link).unwrap();
|
||||
normalize_integration_permissions(root);
|
||||
let conf_mode = std::fs::metadata(&conf).unwrap().permissions().mode() & 0o777;
|
||||
assert_eq!(conf_mode, 0o644);
|
||||
let link_meta = std::fs::symlink_metadata(&link).unwrap();
|
||||
assert!(link_meta.file_type().is_symlink());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue