What was wrong:set_hostname() wrote the new /etc/hosts as root to the fixed /tmp/_netork_hosts and moved it over /etc/hosts. A local user could create that file (or a symlink) beforehand: root's write went into the user's file, and the user owned /etc/hosts afterwards. Found in NetOrk/netork#2446.
Fix:t=$(mktemp /etc/.hosts.XXXXXX) (root's directory, same filesystem as the target), write, chmod 644, mv into place; a failed step removes the file (|| { rm -f "$t"; false; }). set_hostname keeps its length (quality baseline).
Tests:tests/test_set_hostname.py — the write goes through a mktemp file in /etc and no /tmp name (red before the fix); the rename tests still read what is written (their helper now finds the write by base64 -d and /etc/hosts). Checked the command in a real sh against a scratch directory: the file lands with mode 644 and no temporary file is left.
The five failures of tests/test_time_sync.py in my environment fail the same way on main.
Merge note: #65 (hostname quoting) appends to the same test file and CHANGELOG section; whichever goes second needs a trivial rebase/merge of those hunks.
**What was wrong:** `set_hostname()` wrote the new `/etc/hosts` as root to the fixed `/tmp/_netork_hosts` and moved it over `/etc/hosts`. A local user could create that file (or a symlink) beforehand: root's write went into the user's file, and the user owned `/etc/hosts` afterwards. Found in NetOrk/netork#2446.
**Fix:** `t=$(mktemp /etc/.hosts.XXXXXX)` (root's directory, same filesystem as the target), write, `chmod 644`, `mv` into place; a failed step removes the file (`|| { rm -f "$t"; false; }`). `set_hostname` keeps its length (quality baseline).
**Tests:** `tests/test_set_hostname.py` — the write goes through a mktemp file in /etc and no /tmp name (red before the fix); the rename tests still read what is written (their helper now finds the write by `base64 -d` and `/etc/hosts`). Checked the command in a real `sh` against a scratch directory: the file lands with mode 644 and no temporary file is left.
The five failures of `tests/test_time_sync.py` in my environment fail the same way on `main`.
Merge note: #65 (hostname quoting) appends to the same test file and CHANGELOG section; whichever goes second needs a trivial rebase/merge of those hunks.
Closes #66
The new /etc/hosts was written as root to the fixed /tmp/_netork_hosts
and moved over /etc/hosts. A local user could create that file (or a
symlink) beforehand: root's write went into the user's file, and the
user owned /etc/hosts afterwards (NetOrk/netork#2446).
The file is now made with mktemp beside the target (/etc/.hosts.XXXXXX,
root's directory, same filesystem), written, set to 644 and moved into
place; a failed step removes it.
napalm-device-types 4.36.0 (released after main's last CI run) changed
PosixTimeSyncMixin: get_time_sync() reports DHCP-provided servers apart
(dhcp_ntp_servers), and configure_time_sync() no longer comments out the
DHCP client's chrony sourcedir; it gives back one that 4.35.0 took out
(NetOrk/netork#2380). CI installs the newest release, so five time-sync
tests failed on every branch.
The tests now expect that behaviour, read DHCP's servers apart, and check
that a node 4.35.0 aligned gets its DHCP sourcedir back. The floor moves
to 4.36.0, so the lowest-versions job tests the same behaviour; README,
CHANGELOG and the module docstring say what a write leaves alone.
The mktemp write of /etc/hosts made set_hostname one line shorter, and
the quality ratchet fails on a baseline entry that is no longer reached
(stale). Lowered with napalm-standard ratchet --write.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
What was wrong:
set_hostname()wrote the new/etc/hostsas root to the fixed/tmp/_netork_hostsand moved it over/etc/hosts. A local user could create that file (or a symlink) beforehand: root's write went into the user's file, and the user owned/etc/hostsafterwards. Found in NetOrk/netork#2446.Fix:
t=$(mktemp /etc/.hosts.XXXXXX)(root's directory, same filesystem as the target), write,chmod 644,mvinto place; a failed step removes the file (|| { rm -f "$t"; false; }).set_hostnamekeeps its length (quality baseline).Tests:
tests/test_set_hostname.py— the write goes through a mktemp file in /etc and no /tmp name (red before the fix); the rename tests still read what is written (their helper now finds the write bybase64 -dand/etc/hosts). Checked the command in a realshagainst a scratch directory: the file lands with mode 644 and no temporary file is left.The five failures of
tests/test_time_sync.pyin my environment fail the same way onmain.Merge note: #65 (hostname quoting) appends to the same test file and CHANGELOG section; whichever goes second needs a trivial rebase/merge of those hunks.
Closes #66