navigator-elevation
As root -- doing a step refused permission (EACCES/EPERM) again as root, a departure (DOS refused no one). navigator/lib/system/elevate.py (ELEVATION, sudo -S with Navigator's own password box or pkex
Files1
View on GitHubSKILL.md.claude/skills/navigator-elevation/SKILL.md
GitHubAs root
A departure: DN never met a permission. When a step on the local disk fails with EACCES/EPERM, the error box
offers As root beside Skip/Cancel; answered, the step is done again through a root helper, and every later step
of that operation goes through it without asking again (DN's All).
The pieces
navigator/lib/system/elevate.py--ELEVATION, the one helper.begin()starts it and answersREADY_STATE,Asked(prompt, wrong)orRefused(reason);answer(password | None)continues. Everything blocks: call on a thread (asyncio.to_thread), never the loop.- sudo runs as
sudo -S -p MARKER -- python -I -B -c BOOTin a new session with no terminal of ours: its prompt comes through stderr and is recognised byMARKER; Sorry before it meanswrong. The password goes to sudo's stdin and is never kept. pkexec's polkit agent asks for itself, sobeginmay wait (START_TIMEOUT). [system] elevate(auto= sudo else pkexec,sudo,pkexec,off);available()is false when already root, off, or no tool installed -- then As root is not offered at all.release()at the end of every operation closes the helper when[system] root_timeoutis 0; otherwise the reaper closes it that many idle minutes after its last step.Navigator.on_stopcloses it.close()never waits for ever. Steps queued for the lock are turned away. The step under way getsSTEP_WAIT(1 s), then the socket is shut under it, so its read ends withEIOand it lets go; if the lock is still held after anotherSTEP_WAIT, closing gives up and quitting goes on. Found as a full-suite timeout: a tree onroot:///probing a slow network mount (s3fs/sshfs under/mnt) held Alt+X with it.hold()/unhold(): a window that keeps a file open through the helper (F3's_RootRandom) holds it; neitherrelease()nor the reaper closes a held helper. The handle'sclose()unholds and releases.ELEVATION.commandreplaces the tool's argv: tests run the helper unprivileged with it (tests/test_elevate.py).
- sudo runs as
navigator/lib/system/roothelper.py-- the root process. Messages are a 4-byte big-endian length, that much JSON, thensizeraw bytes. Only names inOPS(the public methods of_Helper) may be asked; an unknown op isEINVAL. Answers are{"ok": ...}or anOSErroraserrno/strerror/filename, re-raised as the sameOSErrorsubclass on our side. It saysREADYonce and ends at end of input. Started with-I -B, the package path inserted explicitly, so nothing from the user's current directory or environment is imported as root, and no.pycis written as root into the user's tree.navigator/lib/drives/root.py--ROOT_DRIVE, aLocalDrivewhose every step is a helper request (files are_RootFiles read/written aCHUNKper request).write_fileis the editor'ssave.write_filerun in the helper; the text is gathered there first, so it is not stoppable part way. The lock check is done here, not in the helper (check_lock=Falsethere): the editor's ownflockwould otherwise make the root process look like another program and refuse the save.
Threat model (reviewed 2026-10-26)
Not a backdoor: no setuid file, no daemon, no sudoers/polkit rule, the password never kept; every start is the user's own authentication. What the review found and the rules it left:
- The channel to root is a
socketpair, never a pipe. A pipe's end can be reopened through/proc/<navigator-pid>/fd/Nby any process of the user's (Yamaptrace_scope=1restricts attach only) and fed requests: root without a password forroot_timeoutminutes. A socket refuses that (ENXIO). On top, Navigator is made non-dumpable (prctl(PR_SET_DUMPABLE, 0),_set_dumpable) while the helper runs -- no ptrace, no/proc/<pid>for the user's processes, even atptrace_scope=0-- and dumpable again in_shut. A debugger or py-spy cannot attach to Navigator meanwhile; that is the point. - Root runs code the user may be able to change (a checkout, a virtualenv,
pip --user:untrusted_code()overcode_paths(), which include the venv'ssite-packages, whose.pthfiles run even under-I). It is said in the question (as_root._question), not refused: no worse thansudo ~/script, and how development works. The packaged install is root's and says nothing. Tests patchas_root.untrusted_code(autousetrusted_code). - A step that changes the disk follows no symlink another user owns (
_Helper._pinned): only root's and the asker's (SUDO_UID/PKEXEC_UID, elsegetuid()),ELOOPotherwise. Each directory on the way is held open withO_PATHand the step done through/proc/self/fd/<dir>/<name>, so a directory swapped for a link between two steps (therm -rfrace, a shared directory, the home of the user whose tree is being erased) cannot send root's next unlink, write or chmod elsewhere.open_writeaddsO_NOFOLLOWafter resolving,chmodchanges anO_PATH-held inode,write_texthandswrite_file(follow=False)the resolved name. Reads are left alone: the user has root already. The kernel'sfs.protected_symlinkscovers sticky world-writable directories only; this is everywhere. Elsewhere than Linux (PINNABLEfalse) steps go by name, as before. - Live root is visible:
RootMark(navigator/widgets/shell/root_mark.py) shows ROOT white on red before the clock whileELEVATION.running(polled once a second,Shell.follow_root), since a panel or the quick view may then go to root unasked. Utilities > Close root access (CloseRootAccess, enabled while it shows) sendsroot:panels back to the disk and closes the helper. - What a
root:panel offers: whatever goes through a drive (copy, erase, F7, Alt+E, F3/F4, Find, Find duplicates, checksums --RootSiteDrivereads through the helper). Not what runs as the user against the place -- Panelize ($SHELL -c), Show hard links, Mount image, git status, zoxide -- greyed with Not as root: the command runs as you (manager._disk_only), not the old, wrong Only on the local disk. - Utilities has one root entry (
root_accessinmain_menu.nml, commandToggleRootAccess): Elevate root access while closed (Shell.open_root_access,open_root's password box), Close root access while open (close_root_access).Shell._name_root_access, an effect onroot_mark.open, sets its caption and tooltip; both keep the same hotkey in every catalogue. Greyed when there is no way to root (Shell._root_reachable,ELEVATION.available()cached by[system] elevate) or when already root.CloseRootAccessstays a command of its own: the mark's click and a user's key binding run it. - Elevating also makes the console root's (the menu entry only; an As root answer does not):
- The op. The helper's
consoleop starts the helper user's own login shell (bash, zsh or sh; else bash onSECURE_PATH) on apty.forkof its own. Navigator's hook (subshell.shell_argv) goes into a root-ownedmkdtemp, never the user's temp directory. The environment issudo -i's (console_environment): the target's HOME/USER/LOGNAME/SHELL,SECURE_PATH, and of what Navigator sends onlyCONSOLE_KEEPandLC_*. The cwd is reached through_pinned(no other user's link), else root's home. - Handing the pty back. The op answers
WithFd._servesends the reply with"fd": true, then the master withSCM_RIGHTSon the same socket (_send_fd), then closes its copy.Elevation.call_fdreceives both under the lock; the channel is unbuffered, so nothing is read ahead. - Lifetime.
console_stopand the end of the helper (_stop_consoles) hang the shell up (SIGHUP, SIGKILL afterCONSOLE_GRACE) and remove its rc directory._reap_consolescollects one that exited by itself. - The Navigator side. It is
RootSubshell(console-command-line). Ithold()s root access while it lives, so the idle timeout leaves it alone.Shell.close_root_accessandfollow_root(the helper gone) call_back_to_user_shell.exittyped at it brings the user's shell back with root access left open. - The command line while it is root's (
Console.root, reactive): aroot:panel counts as its own place on the disk (Shell._as_the_shell_sees, used by_front_directory,_front_remoteand_command_directory). So the shell follows the panel there, commands run there, and the shell's own prompt (root's\$,#) shows instead of theroot://...$stand-in. The stand-in prompt ends in#too. The terminal's title saysroot@hostwith~meaning root's home (title.window_title(where, root=True), fromShell._name_window). - The status line says ROOT too while the menu bar's mark cannot be seen (console up, or Hide menu bar):
key_root_markinshell.nml, a secondRootMarkbound to the first'sopen, at the key bar's right end;KeyBar.reservekeeps the items (and an open menu's hint) clear of it. - Following a cd.
_follow_shellgoes through_panel_to_shell: a place the user cannot even stat (/root/sub; 3.12'sis_dir()raisesEACCESthere) takes the panel straight toroot:. - Threat model. The master fd exists only in Navigator, which is non-dumpable while the helper runs, as for the socket. Nothing user-writable is run as root: root's rc files, root's home, a root PATH, a root-owned rc directory.
- The op. The helper's
- Its tooltip (
RootMark.tooltip_at) says what it means, that it closes afterroot_timeoutidle minutes (left out at 0), and that Utilities > Close root access closes it now -- the path built from the menu's own translated captions, so it reads as the menu does. - Still open, by choice: files created as root in the user's own tree stay root's (a
chownback would be a departure; not asked for).
Wiring an operation
- Workers subclass
filecopy.Elevated: useself._drive_of(location)instead ofdrive_of, wrap a step inself._try(path, step)(or loop onself._failed(path, error)), and callself._release()inrun'sfinally.Failure.elevateis set only for a local path, a refusal errno, and a worker not yet elevated -- a step refused even as root is just Skip/Cancel.is_rootturns true once elevated, so Preserve attributes sets owners. Copy/move (_Copier), erase (_Eraser) and Alt+E (fileattr._Changer, whose own_stat/_childrengo through the helper once elevated, andapply_one(as_root=True)) are wired. Alt+E's ACL, Xattrs and Flags pages go throughRootDrive'slistxattr/getxattr/setxattr/removexattr/get_flags/set_flags, each a helper op through_pinnedlikechmod(getxattranswers its value as the raw payload,setxattrtakes it as one). While root access is open (the menu bar's ROOT), Alt+E's owner field is enabled and every group offered:fileattr.can_chown_user()iseuid == 0 or ELEVATION.running. A request with an owner or group then starts_Changerelevated (checked inrun(), so a helper closed meanwhile falls back to refuse-then-offer). The dialog's own As root (root_button, declared inattr_dialog.nmland moved into the base'srowbetween OK and Cancel in__init__; shown whengather()'scan_elevate: local, not root,ELEVATION.available()) runsopen_root, enables Owner, offers every group, and setsAttrRequest.as_root, which elevates_Changerfor any change. - The loop side is
navigator/widgets/file_ops/as_root.py:ask_skip(app, message, elevate=)(Skip / As root / Cancel; answers True, None orAS_ROOT),ask_as_root(app, message)(As root / Cancel), andopen_root(app)(thePasswordDialogtitled Root access until sudo accepts, an Error box on a refusal, silence on Cancel).Manager._ask_skippassesquestion.elevatethrough. - The editor:
EditWindow._write_or_root(F2'ssaveandsave_as) offers it on a refused write (not for aUseFilecopy) and writes throughROOT_DRIVE.write_file, releasing after._check_for_over's lifting of a read-only mode is let pass when refused and root is available: the write is refused next and offers As root. - ^K W / ^K R (
write_block,read_block): the same retry withask_as_root; ^K W writes throughROOT_DRIVE.write_file(oropen_write(append=True)for Append), ^K R reads withdocument.read_text(as_root=True)(read_documentstats and opens throughROOT_DRIVE). - F3 (
Manageron a local file, afteropen_vieweris refused):ask_as_root, thenas_root.view_as_rootopens aviewer.ChunkedSourceonROOT_DRIVE.open_random-- chunks fetched on a thread as a server file's are, never a helper round trip on the loop -- withsource.drive = ROOT_DRIVEso the viewer's Save as reads through it too. The helper'sread_atop isos.preadon the open handle. - Ctrl+Q quick view (
QuickViewer._opened): a refused open is read as root only whileELEVATION.running-- moving the cursor never asks for a password -- throughas_root.root_source(aChunkedSource, full path as itspathso the "already showing" check holds), retried once, never again. - F4 opening (
Manager.edit_file->open_editor(as_root=True)->load_document->read_document(as_root=)): the text read into memory through the helper, released after; the window's path is the original, so F2 is refused in its turn and offers As root again. - F3 As DataBase (
.dbf):as_root.database_as_rootfetches it and its.dbt/.fptwithusefile.fetch(..., drive=ROOT_DRIVE)into the private directory, owner-only (0600) whatever the original's mode -- it may hold what only root could read.TempCopy.drivemakesconflicts/uploadgo through it;uploadthrough a drive withwrite_file(root's) writes in place of the original keeping owner and mode, never the usual new file renamed over (which root would own).Manager._may_as_rootis the shared ask for F4/As DataBase. - Ctrl+F7/F8 UU (
Manager._run_uucode(..., as_root=)): a refusal (source unreadable, target refused) offers As root and runs the work again throughManager._staged(..., as_root=True): the source fetched throughROOT_DRIVEinto the private directory, encoded/decoded into staging, the files put on the disk withusefile.put_files(..., drive=ROOT_DRIVE)(asked about first, as for another drive). A target naming a directory is staged as one. New files are root's, as a copy made as root is. - Alt+L list file (
Manager._write_list, both the local and the elsewhere writer): a refused write to the disk offers As root and writes throughROOT_DRIVE.makedirs/open_write(append=). - Archives on the disk (
navigator/lib/drives/archive.py): an unreadable one raisesPermissionErrorfromopen_archive(before,zipfile.is_zipfileswallowed it and it was taken for not an archive, i.e. run as a program).open_archive(as_root=True)opens it the way an archive on another drive is opened: a private copy fetched withusefile.fetch(..., drive=ROOT_DRIVE), every rewrite put back through root'swrite_file(owner and mode kept).ArchiveDrive.as_rootdrives hold the helper untilclose()(unhold + release), since a put-back can come at any time.ArchiveDrive.go_root(job)switches an open one whose rewrite was refused: staged members stay staged, the rewrite is made in the copy.finish_drives(..., elevate=)asksElevated._finish_as_rootfirst (copy/move, erase and Alt+E pass it; Alt+E's finish now runs inside_Changer.run). On the loop,widgets/drives/archives.open_archive_or_root(Enter, Shift+F2's Extract) asksask_as_root. - F3's Shift+F2 Store (
FileWindow.store): a refused write of bytes typed in hex offers As root. ThenRootDrive.patch_filechecks the size (stat), opens the file withopen_update(_pinned(follow=True),O_RDWR|O_NOFOLLOW, noO_CREAT, noO_TRUNC, and only a regular file), and writes each run withwrite_at(os.pwrite). Nothing is created or truncated, and owner, mode and inode stay. A file viewed as root already (aChunkedSourceonROOT_DRIVE, orroot:///) is written the same way, unasked. - The viewer's Save as (
FileWindow.save_as): a refused local target retriesviewer.save_as(..., as_root=True), written throughROOT_DRIVE.write_file(owner/mode kept), released after. - A write-protected
.dbf(DBWindow._edit_as_root): editing a field offers As root, then the window moves onto a copy fromas_root.fetch_database; every field goes back through root. A root-fetched dBase copy holds the helper (DBWindow.root_held) until the window closes -- else, withroot_timeout0, the first put-back found it closed.database_as_rootsets the same. - F7 and Alt+A inside an archive whose rewrite is refused: F7's remote branch offers
_may_as_rootand finishes throughgo_root;multirename._finishasks aFailure(withelevatefor a local archive) where the failure used to be passed over in silence -- the renames were shown and never written. - Browsing an unreadable directory (
navigator/lib/drives/root.py's second half): a panel lists and works as root atROOT_SITE(Site("root"), shownroot:///path) -- the disk's paths on a site of their own, so every step is a drive's, exactly as on a server, and copy/erase/F3/F4/Alt+E/... need nothing new.RootSiteDrivehands each step toROOT_DRIVEonon_disk(location); itsscanis the helper'slistingop (the disk's ownlisting.read_listing, entries packed as lists -- an op must never return a tuple that is not(value, payload)). Noexec(Enter opens a program rather than running it, as on every drive but the disk); the free space comes back with the helper's listing. Disconnect (Alt+H) ignores it. Auto refresh is aPollWatchthrough the helper everyroot.POLL_INTERVAL(2 s) -- not[remote] refresh, off by default, as this is the disk;_arrived_at_rootsets the watch up again, the first having found no drive mounted.root.hold(panel)mounts the drive and holds the helper;root.leaveunmounts with the last holder and the panel releases.Panel._hold_root(an effect) follows the location -- butPanel._go_rootholds before it moves, since the rescan effect runs first and would find no drive.- The offer:
Panel._apply, for a navigation read (not a re-read) of a local directory that failed andos.accesssays is unreadable ->_offer_root, once per place (_root_offered). While the helper runs already, it switches unasked, as the quick view does -- every time:_root_offeredstops only a repeat of the question (declined, or no way to root), so a place first reached by the root console'scd, left, and entered again from the panel isroot:again, not Permission denied. - Leaving: Enter and
..onroot:go back to the disk itself wherereadable_plainlysays the user may list; so do a directory chosen in the tree (Manager.on_tree_chosen) and in Alt+T (Panel._plain_where_readable). - Alt+F7 and the trees (Ctrl+T, Alt+T) need nothing of their own there:
filefind._search_driveandDirectoryTree's drive reads go throughdrive_of, which isRootSiteDrive(tests intest_elevate.py). - Coming back to a
root:place (a history, a bookmark, a typed URL -- anything throughShell.reach-- or a saved desktop / the command line, which set the location directly):Shell.reachhandsROOT_SITEtoas_root.reach_root(Open … as root?, titled Root access, thenroot.mount_drive()), never toSESSIONS. A panel that lands there unasked is caught by_hold_root->_arrived_at_root: the same question, then a re-read; declined, the disk's own place, not asked about again. root._HOLDERSis module-level: a test whose app ends with a panel atroot:leaves its holder (thehelperfixture intests/test_elevate.pyclears it).
- File > Encoding > Convert text (
textconv.convert(..., as_root=)): not anElevatedworker, sincerun_with_progressrelays no questions -- refusals are gathered inTextJob.refusedandManager._convert_as_roothands them toManager._again_as_root, which asksask_as_rootonce for the batch, then converts those again throughROOT_DRIVE. A drive withwrite_file(ROOT_DRIVE, theroot:site's) writes through it, so the file keeps its owner, mode and links; a new file renamed over would be root's. - The ask-once shape,
Manager._again_as_root(job, question, rerun, *, keep=, errors=):job.refused((location, size, reason), the disk only, not root yet) listed in one question, rerun(refused) through the helper, thenELEVATION.release(keep: the caller goes on as root -- Decrypt's passphrase questions -- and releases itself); declined, they go in errors (job.errors).root.rooted(location, as_root)is the one rule every such module reaches the disk by. Users: Convert text; Encryption/Decryption (EncryptJob.refuse→refused,refused_plans, an unread head planned again as root;as_rootset on the job); Checksums' each-file mode (write_each(as_root=): read failureserrors, write failureswrite_errorsunder their own could not be written heading). - Asked at the file, as the copier does (
Failure(elevate=True)→ask_skip→AS_ROOT): Replace in files (a refused write throughROOT_DRIVE.write_file, later ones unasked:ReplaceJob.as_root); Trash > Restore (restore(as_root=):ROOT_DRIVEmakes the place and renames into it, the info file the user's;RestoreJob.as_root). The manager releases the helper after (_release_if). - Split / Combine (
splitfile.split/combine(as_root=)) through_run_uucode'sas_root=, as UU. Alt+T's Make directory is F7's (navigator/widgets/file_ops/make_directory.py,make_directory_in: the disk, As root, another drive, an archive's refused rewrite, Undo;failure_textnames the directory). - Remote drives are deliberately not offered it: local root cannot get past a server's refusal (FTP, SMB, S3
have no notion of it; SFTP would need the server's
sftp-serverunder its own sudo -- a separate feature, declined for now). Manager._may_as_root(error, message)is the shared ask;_as_root_declinedis only meaningful right after it was called -- guard a read of it with the same condition that called it.- Multi-rename (
multirename.run): a refused rename of a file still under its own name asks withelevate;AS_ROOTsetsRenameJob.elevatedand retries, every later rename on a local place going toROOT_DRIVE. A file stranded under its.navrename-name keeps the old put-back path (no offer). Alt+F6/Shift+F6 (Manager._rename_entry) asksask_as_rootand renames onROOT_DRIVE. - On the loop (F7, Shift+F5): the first step stays on the loop as before; once elevated every step goes to a
thread, since a helper request blocks. F7 asks
ask_as_rootand makes the directory withROOT_DRIVE.mkdir;Manager.link_entriesasksask_skip(elevate=)per refusal until answered, thenfilelink.make_link(..., as_root=True)andROOT_DRIVE.makedirsfor the rest, releasing in itsfinally.
Checked against the real tools (2026-10-26)
sudo 1.9.15p5 and pkexec 124 (polkit-gnome agent, XFCE), by a script driving ELEVATION and ROOT_DRIVE
directly plus a hand run in Navigator: the \x01 prompt marker survives sudo, wrong passwords are told apart,
3 MB of every byte value go through unchanged (no pty in the way), write_file keeps owner/mode/backup, a
root-only directory lists and copies, release/timeout close it, and -B leaves no root-owned .pyc. By hand:
F2 and F7 as root keep owner and mode, Enter on /root lists it at root:///root, and Ctrl+T shows its tree. Found
there and fixed: RootDrive.write_file's own lock check could not resolve a path inside a directory only root
may enter -- the helper now checks locks itself then (write_text(check_lock=True)). Both tools start with
start_new_session=True: pkexec with no polkit agent (over ssh) would otherwise ask on the terminal Navigator
draws on; without one it refuses and says why.
Not wired yet
Remote drives (see above); Shift+F4's new file in a directory the user cannot write is offered at F2's save. Each would follow the pattern above.