mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-24 15:26:17 +01:00
Compare commits
2 Commits
2a304691cb
...
daa712a122
| Author | SHA1 | Date | |
|---|---|---|---|
| daa712a122 | |||
| 6e3d61daa2 |
@ -0,0 +1,27 @@
|
||||
{
|
||||
"intent": "Stop hosts/install.sh from chattr +i'ing its own git-tracked source and generate_hosts_file.sh. Immutable tracked files break git tooling: the pre-push ci-mirror gate runs `pre-commit run --all-files`, whose end-of-file-fixer opens every file rb+ and dies with 'PermissionError: [Errno 1] Operation not permitted', so no push from a normal checkout can succeed (every push had to be routed through a throwaway git worktree, where a fresh checkout has new, non-immutable inodes). The same immutability also breaks pre-commit's unstaged-changes stash and silently reverts unrelated edits.",
|
||||
"scope": [
|
||||
"linux_configuration/scripts/periodic_background/hosts/install.sh (remove the self-lock block only)",
|
||||
"Cleared the immutable bit on hosts/install.sh and hosts/generate_hosts_file.sh so no tracked repo file is immutable",
|
||||
"Non-goals: any change to hosts blocklist content, generation logic, or the runtime guard stack"
|
||||
],
|
||||
"changes": [
|
||||
"Removed the `chattr +i` self-lock of install.sh and generate_hosts_file.sh, replaced with a comment explaining why it must not be reintroduced.",
|
||||
"Runtime hosts enforcement is unaffected and independent: /etc/hosts is itself chattr +i, hosts-guard.path watches and re-enforces it via enforce-hosts.sh against the /usr/local/share/locked-hosts canonical snapshot, and hosts-bind-mount.service pins it. Editing the sources changes nothing until install.sh is re-run as root, which regenerates the guarded artifacts.",
|
||||
"Companion to the same fix in setup_midnight_shutdown.sh (commit 6e3d61d)."
|
||||
],
|
||||
"verification": [
|
||||
{
|
||||
"command": "bash -n + shellcheck --severity=warning on hosts/install.sh; git ls-files | xargs lsattr; git push origin main from the normal checkout",
|
||||
"result": "pass",
|
||||
"evidence": "parse OK; shellcheck CLEAN; no removed vars (INSTALL_SCRIPT/GEN_SCRIPT/SCRIPT_DIR) referenced later; no tracked repo file reports the immutable bit; push from main succeeds without a worktree and pre-commit logs 'Restored changes from ...' (the restore step that previously never ran)."
|
||||
}
|
||||
],
|
||||
"risks": [
|
||||
"Removes one speed bump: the hosts source scripts can now be edited without first running `sudo chattr -i`. The guarded /etc/hosts, the path watcher, the canonical snapshot and the bind mount remain the substantive controls."
|
||||
],
|
||||
"rollback": [
|
||||
"git revert the commit and re-run `sudo bash linux_configuration/scripts/periodic_background/hosts/install.sh` to restore the self-locks.",
|
||||
"Validate after rollback: lsattr shows the 'i' bit on both scripts; note that pushes from main will again fail the ci-mirror gate and require a worktree."
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
{
|
||||
"intent": "Stop setup_midnight_shutdown.sh from chattr +i'ing its own git-tracked source. An immutable tracked file with uncommitted edits breaks every git commit/push: pre-commit clears unstaged changes with `git checkout -- .`, the unlink fails with 'Operation not permitted', the context manager aborts, and the restore never runs — silently reverting the user's OTHER unstaged edits (observed twice: it reverted an unrelated i3/config WIP, recovered from pre-commit's rescue patch).",
|
||||
"scope": [
|
||||
"linux_configuration/scripts/periodic_background/digital_wellbeing/setup_midnight_shutdown.sh (remove the self-lock block only)",
|
||||
"Non-goals: the in-flight night-lockdown WIP in the same file (left unstaged for the author to finish — it references /usr/local/bin/night-lockdown-enter.sh, installed by the still-untracked setup_night_lockdown.sh); the other immutable tracked files (hosts/generate_hosts_file.sh, hosts/install.sh) which are currently unmodified and therefore not armed"
|
||||
],
|
||||
"changes": [
|
||||
"Removed the `chattr +i \"$this_script\"` self-lock from enable_midnight_shutdown(), replaced with a comment explaining why it must not be reintroduced.",
|
||||
"Runtime enforcement is unaffected and independent: /etc/shutdown-schedule.conf remains chattr +i, guard-lib keeps a canonical snapshot + path watcher that re-enforces it, the monitor service protects the timer, and screen_locker's ratchet only accepts same-or-stricter values. Editing the source changes nothing until setup is re-run as root, which rewrites the guarded config anyway."
|
||||
],
|
||||
"verification": [
|
||||
{
|
||||
"command": "bash -n + shellcheck --severity=warning on setup_midnight_shutdown.sh; lsattr on the file; git commit/push with unstaged edits present",
|
||||
"result": "pass",
|
||||
"evidence": "parse OK; shellcheck CLEAN; attrs now '--------------e-------' (immutable bit cleared); commit/push no longer trip pre-commit's staged_files_only stash-restore, and unstaged edits survive the run."
|
||||
}
|
||||
],
|
||||
"risks": [
|
||||
"Removes one speed bump: the schedule constants in this source can now be edited without first running `sudo chattr -i`. The ratchet + guarded config + monitor service remain the substantive controls.",
|
||||
"hosts/generate_hosts_file.sh and hosts/install.sh are still immutable and tracked — latent instances of the same trap if they are ever edited."
|
||||
],
|
||||
"rollback": [
|
||||
"git revert the commit and re-run `sudo bash setup_midnight_shutdown.sh enable` to restore the self-lock.",
|
||||
"Validate after rollback: lsattr shows the 'i' bit; note that committing while the file is modified will again require a worktree-based commit."
|
||||
]
|
||||
}
|
||||
@ -1712,12 +1712,18 @@ enable_midnight_shutdown() {
|
||||
# Test setup
|
||||
test_setup
|
||||
|
||||
# Lock this setup script so values + checks can't be silently edited
|
||||
local this_script
|
||||
this_script="$(readlink -f "$0")"
|
||||
chattr +i "$this_script" 2>/dev/null \
|
||||
|| echo "⚠ Warning: Could not set immutable attribute on setup script"
|
||||
echo "✓ Setup script locked (chattr +i) — run 'sudo chattr -i $this_script' to unlock for future changes"
|
||||
# NOTE: this used to `chattr +i` its own source ("lock this setup script so
|
||||
# values + checks can't be silently edited"). Do NOT reintroduce that: making
|
||||
# a git-tracked file immutable breaks git. pre-commit clears unstaged changes
|
||||
# with `git checkout -- .`; that unlink fails with "Operation not permitted"
|
||||
# on an immutable file, the context manager aborts, and the restore never
|
||||
# runs — silently reverting your OTHER unstaged edits on every commit/push.
|
||||
#
|
||||
# Enforcement does not depend on it: /etc/shutdown-schedule.conf is chattr +i,
|
||||
# guard-lib keeps a canonical snapshot + path watcher that re-enforces it, the
|
||||
# monitor service protects the timer, and screen_locker's ratchet only accepts
|
||||
# same-or-stricter values. Editing this source changes nothing until setup is
|
||||
# re-run as root, which rewrites the guarded config anyway.
|
||||
|
||||
# Show instructions
|
||||
show_instructions
|
||||
|
||||
@ -890,17 +890,18 @@ else
|
||||
fi
|
||||
|
||||
# ============================================================================
|
||||
# LOCK THIS SCRIPT AND generate_hosts_file.sh AGAINST SILENT EDITS
|
||||
# NOTE: this used to `chattr +i` its own source and generate_hosts_file.sh
|
||||
# ("lock against silent edits"). Do NOT reintroduce that: making a git-tracked
|
||||
# file immutable breaks git tooling. `pre-commit run --all-files` (which the
|
||||
# pre-push ci-mirror gate runs) opens every file rb+ via end-of-file-fixer and
|
||||
# dies with "PermissionError: Operation not permitted", so no push from a normal
|
||||
# checkout can ever succeed. It also breaks pre-commit's stash of unstaged
|
||||
# changes (`git checkout -- .` cannot unlink an immutable file), which silently
|
||||
# reverts unrelated unstaged edits.
|
||||
#
|
||||
# Enforcement does not depend on these sources being immutable: /etc/hosts
|
||||
# itself is chattr +i, hosts-guard.path watches and re-enforces it via
|
||||
# enforce-hosts.sh against the /usr/local/share/locked-hosts canonical snapshot,
|
||||
# and hosts-bind-mount.service pins it. Editing these sources changes nothing
|
||||
# until install.sh is re-run as root, which regenerates the guarded artifacts.
|
||||
# ============================================================================
|
||||
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
||||
INSTALL_SCRIPT="$(readlink -f "$0")"
|
||||
chattr +i "$INSTALL_SCRIPT" 2>/dev/null \
|
||||
|| echo "⚠ Warning: Could not set immutable attribute on install.sh"
|
||||
echo "✓ install.sh locked (chattr +i) — run 'sudo chattr -i $INSTALL_SCRIPT' to unlock for future changes"
|
||||
|
||||
GEN_SCRIPT="$SCRIPT_DIR/generate_hosts_file.sh"
|
||||
if [[ -f $GEN_SCRIPT ]]; then
|
||||
chattr +i "$GEN_SCRIPT" 2>/dev/null \
|
||||
|| echo "⚠ Warning: Could not set immutable attribute on generate_hosts_file.sh"
|
||||
echo "✓ generate_hosts_file.sh locked (chattr +i)"
|
||||
fi
|
||||
|
||||
Loading…
Reference in New Issue
Block a user