_sudo puts the sudo password on the host's command line #19

Open
opened 2026-10-08 05:34:59 +00:00 by christianmanivong · 0 comments
Owner

_sudo() sends echo '<password>' | sudo -S -p "" <command> through the shell. For as long as it runs, the password is part of a process's argument list on the host, visible to every local user (ps, /proc/<pid>/cmdline), and in the shell's history if one is kept.

run_command(..., privileged=True) (#18) already does it right: the password goes to sudo -S on stdin of an exec channel and never into a command line.

Every _sudo caller is affected: package install/uninstall, updates, crontabs, VPN tunnels, fix_docker_permissions, fix_apt_proxy, fix_snmp. netOrk's Docker permission fix goes through run_device_action("fix_docker_permissions") since NetOrk/netork#775 (phase 7 of #765), which is how this came up.

Fix: let _sudo run privileged commands through run_command(privileged=True), or at least feed the password on stdin. That also overlaps with #10 (sudo -n without a password).

`_sudo()` sends `echo '<password>' | sudo -S -p "" <command>` through the shell. For as long as it runs, the password is part of a process's argument list on the host, visible to every local user (`ps`, `/proc/<pid>/cmdline`), and in the shell's history if one is kept. `run_command(..., privileged=True)` (#18) already does it right: the password goes to `sudo -S` on stdin of an exec channel and never into a command line. Every `_sudo` caller is affected: package install/uninstall, updates, crontabs, VPN tunnels, `fix_docker_permissions`, `fix_apt_proxy`, `fix_snmp`. netOrk's Docker permission fix goes through `run_device_action("fix_docker_permissions")` since NetOrk/netork#775 (phase 7 of #765), which is how this came up. **Fix:** let `_sudo` run privileged commands through `run_command(privileged=True)`, or at least feed the password on stdin. That also overlaps with #10 (`sudo -n` without a password).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: NAPALM/napalm-linux#19