fix: keep the sudo password out of files written as root (0.2.1) #15

Merged
christianmanivong merged 1 commits from fix/privileged-stdin-8 into main 2026-10-16 22:43:21 +00:00
Owner

run_command prepended the sudo password to the caller's stdin. A sudo that does not prompt left it for the command, and fix_snmp wrote it into a world-readable snmpd.conf.

  • run_command refuses stdin to a privileged command while a sudo password is set (as napalm-linux does).
  • fix_snmp stages the configuration without privilege (mktemp, umask 077); root installs it next to the target and renames it over.
  • Temporary names on the host are neutral: /tmp/napalm-bsd-stage.*, *.napalm-tmp.

Tests: the refusal, the password-only stdin, the cases where no password goes first, and that the config reaches the host only through the unprivileged stage.

Closes #8. Part of NetOrk/netork#1105 (step 1).

`run_command` prepended the sudo password to the caller's stdin. A sudo that does not prompt left it for the command, and `fix_snmp` wrote it into a world-readable `snmpd.conf`. - `run_command` refuses stdin to a privileged command while a sudo password is set (as napalm-linux does). - `fix_snmp` stages the configuration without privilege (`mktemp`, umask 077); root installs it next to the target and renames it over. - Temporary names on the host are neutral: `/tmp/napalm-bsd-stage.*`, `*.napalm-tmp`. Tests: the refusal, the password-only stdin, the cases where no password goes first, and that the config reaches the host only through the unprivileged stage. Closes #8. Part of NetOrk/netork#1105 (step 1).
christianmanivong added 1 commit 2026-10-16 09:48:34 +00:00
fix: keep the sudo password out of files written as root (0.2.1)
CI / test (3.10) (push) Successful in 27s
CI / test (3.11) (push) Successful in 27s
CI / test (3.12) (push) Successful in 25s
CI / test (3.10) (pull_request) Successful in 29s
CI / test (3.11) (pull_request) Successful in 24s
CI / test (3.12) (pull_request) Successful in 25s
707e048792
run_command prepended the sudo password to the caller's stdin. A sudo
that does not prompt left it for the command, and fix_snmp's
'cat > snmpd.conf' wrote it as the configuration's first line before
making the file world-readable.

run_command now refuses stdin to a privileged command while a sudo
password is set. fix_snmp stages the configuration in a mktemp file
without privilege, and root installs it next to the target and renames
it over, so nothing root runs follows a symlink.

Closes #8
christianmanivong merged commit 6ff556d714 into main 2026-10-16 22:43:21 +00:00
christianmanivong deleted branch fix/privileged-stdin-8 2026-10-16 22:43:21 +00:00
Sign in to join this conversation.