feat: SudoHistoryMixin, the sudo password left in shell histories (NetOrk/netork#1090) #60

Merged
christianmanivong merged 2 commits from feat/sudo-history-cleanup into main 2026-10-30 20:47:48 +00:00
Showing only changes of commit 0f0064c2d7 - Show all commits
+4 -3
View File
@@ -33,7 +33,7 @@ class _Host(SudoHistoryMixin):
self.home = home
self.bin_dir = bin_dir
self.root = root
#: Who ``id -un`` says the login user is; None for this machine's answer.
#: Who ``id -un`` says the login user is; None for this machine's user name.
self.user: str | None = None
self.ran: list[tuple[str, bool]] = []
@@ -55,8 +55,9 @@ class _Host(SudoHistoryMixin):
}
if command.strip() == "id -u; id -un" and self.root:
return CommandResult("0\nroot\n", "", 0)
if command.strip() == "id -u; id -un" and self.user:
return CommandResult(f"4242\n{self.user}\n", "", 0)
if command.strip() == "id -u; id -un":
# Never this machine's uid: CI runs as root, which the owner step skips.
return CommandResult(f"4242\n{self.user or getpass.getuser()}\n", "", 0)
done = subprocess.run( # noqa: S603 - the test's own scripts
["sh", "-c", command], capture_output=True, text=True, env=env, timeout=timeout
)