{"record":{"id":"2c8cb162e5f3235a","repo":"astrid-runtime/astrid","slug":"private-file-is-not-owned-by-the-current-user","errorCode":null,"errorMessage":"private file is not owned by the current user: {}","messagePattern":"private file is not owned by the current user: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-core/src/platform_fs.rs","lineNumber":548,"sourceCode":"    #[cfg(target_os = \"macos\")]\n    remove_extended_acl_macos(path)?;\n    validate_private_file_unix(path)\n}\n\n#[cfg(unix)]\nfn validate_private_file_unix(path: &Path) -> io::Result<()> {\n    use nix::sys::stat::fstat;\n\n    let file = open_file_no_follow_unix(path)?;\n    let metadata = fstat(&file).map_err(nix_io_error)?;\n    if metadata.st_mode & 0o170_000 != 0o100_000 {\n        return Err(io::Error::new(\n            io::ErrorKind::InvalidData,\n            format!(\"private path is not a regular file: {}\", path.display()),\n        ));\n    }\n    if metadata.st_uid != nix::unistd::getuid().as_raw() {\n        return Err(io::Error::new(\n            io::ErrorKind::PermissionDenied,\n            format!(\n                \"private file is not owned by the current user: {}\",\n                path.display()\n            ),\n        ));\n    }\n    if metadata.st_mode & 0o777 != 0o600 {\n        return Err(io::Error::new(\n            io::ErrorKind::PermissionDenied,\n            format!(\"private file is not owner-only: {}\", path.display()),\n        ));\n    }\n    if metadata.st_nlink != 1 {\n        return Err(io::Error::new(\n            io::ErrorKind::InvalidData,\n            format!(\n                \"private file has {} links; durable media must have exactly one\",","sourceCodeStart":530,"sourceCodeEnd":566,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-core/src/platform_fs.rs#L530-L566","documentation":"Private files must be owned by the current user; the library compares the inode's st_uid to getuid() during validation. If the file exists but belongs to another uid, it refuses to treat it as private, preventing use of state another account could manipulate.","triggerScenarios":"validate_private_file (or restrict_private_file, which validates at the end) encounters a file whose st_uid differs from the current uid — e.g. created by root, another user, or after a uid change.","commonSituations":"Files created by running the tool with sudo; a shared/home-directory migration where ownership was not preserved (rsync without -o, tar as another user); container running as a different uid than the volume's file owner; uid remap after LDAP/NSS change.","solutions":["Chown the file to the current user: `sudo chown $(id -u):$(id -g) <path>`.","Fix the directory ownership recursively: `sudo chown -R $(id -u) <dir>`.","Delete the file and let the library recreate it as the current user (atomic_write_private_file).","Run the application as the user who owns the file, or stop using sudo for it."],"exampleFix":"// before (file owned by root)\nvalidate_private_file(Path::new(\"/home/me/.astrid/credentials\"))?;\n// after (fix ownership first)\n// $ sudo chown $(id -u):$(id -g) /home/me/.astrid/credentials\nvalidate_private_file(Path::new(\"/home/me/.astrid/credentials\"))?;","handlingStrategy":"validation","validationCode":"use std::os::unix::fs::MetadataExt;\nfn owned_by_me(path: &std::path::Path) -> bool {\n    std::fs::metadata(path).map(|m| m.uid() == unsafe { libc::getuid() }).unwrap_or(false)\n}","typeGuard":"fn is_self_owned(path: &std::path::Path) -> bool {\n    std::fs::metadata(path).map(|m| m.uid() == nix::unistd::getuid().as_raw()).unwrap_or(false)\n}","tryCatchPattern":"match validate_private_file(path) {\n    Err(e) if e.kind() == std::io::ErrorKind::PermissionDenied => {\n        println!(\"fix ownership: sudo chown $(id -u) {path:?}\");\n    },\n    other => other?,\n}","preventionTips":["Never create private state with sudo","Use `rsync -o`/preserve ownership when migrating home directories","In containers, match the runtime uid to the volume's file owner"],"tags":["filesystem","unix","ownership","permission-denied"],"backgroundTag":"permission-denied","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}