fix(live): harden hostname helpers (-I isolated python, transactional rollback, multiline guard, disjoint USB/disk pairs) #96

Merged
clawdie merged 1 commit from fix/harden-hostname-helpers into main 2026-11-21 19:41:14 +01:00
Owner

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).

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).
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 deleted branch fix/harden-hostname-helpers 2026-11-21 19:41:14 +01:00
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!96
No description provided.