fix(live): harden hostname helpers (-I python, transactional rollback, multiline guard, disjoint pairs) #95

Closed
clawdie wants to merge 0 commits from clawdie/fix/harden-hostname-helpers into main AGit
Owner

Fixes all 4 Codex findings on 67c9bd8 before PR B: isolated absolute-path python3 -I in clawdie-set-hostname, all-or-nothing read/validate/stage/rollback preserving file modes and ownership, whole-input multiline rejection in retarget-be.sh, and guaranteed-disjoint USB/disk hostname pairs in clawdie-name-derive.

Fixes all 4 Codex findings on 67c9bd8 before PR B: isolated absolute-path python3 -I in clawdie-set-hostname, all-or-nothing read/validate/stage/rollback preserving file modes and ownership, whole-input multiline rejection in retarget-be.sh, and guaranteed-disjoint USB/disk hostname pairs in clawdie-name-derive.
Addresses all four post-merge Codex findings on 67c9bd8 before PR B:

1. Isolated system Python under privilege (High):
   - clawdie-set-hostname pins interpreter to /usr/local/bin/python3 or
     /usr/bin/python3 (never trusts caller PATH) and runs with -I so caller
     CWD modules (e.g. poison secrets.py/pathlib.py) can never be imported.
   - clawdie-name-derive also runs python3 -I.
2. Transactional all-or-nothing rename + permission/ownership preservation (High):
   - clawdie-set-hostname reads and validates both /etc/rc.conf and /etc/hosts
     in full before writing anything, preserves existing file modes and uid/gid,
     stages both temp files atomically, and rolls back both files (content +
     mode + ownership) if replace or live hostname(1) fails.
3. Whole-input multiline validation in retarget-be.sh (Medium):
   - Rejects whitespace/control chars and embedded newlines (wc -l != 0) before
     LC_ALL=C grep -Eq so multiline TARGET_HOSTNAME cannot pass via one valid line.
4. Strictly disjoint USB/disk hostname pairs (Medium):
   - clawdie-name-derive derives (usb_hostname, disk_hostname) together via
     derive_pair() (plus new 'pair' subcommand), guaranteeing usb != disk for
     every input including Helix-USB, Helix-USB-USB, USB, localhost-usb, and
     truncated 63+ char names.

Verified on Debian 13 (debby) and FreeBSD 15.1-RELEASE-p7 (valhala):
clawdie-hostname-helper-test 59/59, retarget-be-test 103/103,
clawdie-live-selfcheck-test 25/25, doas-policy-test 83/83 (FreeBSD live doas -C).
clawdie closed this pull request 2026-11-21 19:58:41 +01:00
All checks were successful
format-check / gates (pull_request) Successful in 2m42s

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
clawdie/clawdie-iso!95
No description provided.