{"record":{"id":"cdc5ebaa7a1328cc","repo":"jdx/mise","slug":"cannot-determine-the-current-user-to-own","errorCode":null,"errorMessage":"cannot determine the current user to own {}","messagePattern":"cannot determine the current user to own (.+?)","errorType":"exception","errorClass":"eyre::Report","httpStatus":null,"severity":"error","filePath":"src/system/packages/brew/prefix.rs","lineNumber":204,"sourceCode":"    let missing_subdirs: Vec<PathBuf> = dirs.iter().filter(|p| !p.exists()).cloned().collect();\n    if !needs_create && !needs_chown && missing_subdirs.is_empty() {\n        return Ok(());\n    }\n    // try without elevation first — covers prefixes under user-writable\n    // parents; the real prefixes need sudo to create. Skipped under `sudo\n    // mise`: root could create the dirs, but they must be chowned to the\n    // invoking user afterwards\n    if needs_create\n        && !dry_run\n        && sudo_invoking_user().is_none()\n        && dirs.iter().try_for_each(std::fs::create_dir_all).is_ok()\n    {\n        return Ok(());\n    }\n    if needs_create || needs_chown {\n        let Some(user) = prefix_owner() else {\n            // never chown to a guessed owner — that can lock the user out\n            bail!(\n                \"cannot determine the current user to own {}\",\n                prefix.display()\n            );\n        };\n        // brew's install.sh chowns to user:admin on macOS, just the user on\n        // Linux (the admin group doesn't exist there)\n        let owner = if cfg!(target_os = \"macos\") {\n            format!(\"{user}:admin\")\n        } else {\n            user\n        };\n        let mut mkdir_dirs: Vec<String> = vec![prefix.to_string_lossy().to_string()];\n        mkdir_dirs.extend(dirs.iter().map(|d| d.display().to_string()));\n        let mkdir_args: Vec<String> = [\"-p\".to_string()].into_iter().chain(mkdir_dirs).collect();\n        let chown_args: Vec<String> = vec![\"-R\".to_string(), owner, prefix.display().to_string()];\n        if dry_run {\n            miseprintln!(\"{}\", sudo::argv(\"mkdir\", &mkdir_args).join(\" \"));\n            miseprintln!(\"{}\", sudo::argv(\"chown\", &chown_args).join(\" \"));","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/jdx/mise/blob/9dcfcaa0dc8747a2577d3270b69bb9d8313b2807/src/system/packages/brew/prefix.rs#L186-L222","documentation":"Creating or chowning the Homebrew prefix usually requires sudo, and afterwards ownership must be assigned to the invoking user (user:admin on macOS, just the user on Linux, matching brew's install.sh). mise resolves that user from the sudo environment; if it cannot determine one it aborts instead of guessing, because chowning to a wrong owner could lock the user out of the prefix.","triggerScenarios":"needs_create || needs_chown is true while prefix_owner() returns None — typically running as root without SUDO_USER set (bare docker exec as root), or the running uid having no matching passwd entry due to broken NSS/LDAP.","commonSituations":"Running mise in minimal containers as root without sudo; docker run with an arbitrary uid; LDAP/NSS misconfiguration so the invoking user cannot be looked up; CI jobs that drop environment variables including SUDO_USER.","solutions":["Run `mise bootstrap packages apply` as a regular user with sudo available, so the invoking user is identifiable","Ensure the running uid has a valid passwd entry and that SUDO_USER is preserved when escalating","Pre-create the prefix manually, chown it to your user, and re-run so no ownership decision is needed"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# fail fast when ownership cannot be determined\nif [ \"$(id -u)\" = 0 ] && [ -z \"${SUDO_USER:-}\" ]; then\n    echo \"running as root without SUDO_USER — brew prefix ownership is ambiguous\"; exit 1\nfi\ngetent passwd \"$(id -un)\" >/dev/null || { echo \"no passwd entry for $(id -un)\"; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run mise as a regular user with sudo, not as bare root","Ensure the running uid has a passwd entry, especially in containers with arbitrary uids","Pre-create and chown the prefix manually if the environment cannot express the invoking user"],"tags":["brew","sudo","ownership","prefix","permissions"],"backgroundTag":"sudo-user-resolution-failed","analyzedSha":"9dcfcaa0dc8747a2577d3270b69bb9d8313b2807","analyzedAt":"2026-08-17T14:28:50.624Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}