scripts/hosts/guard
Krzysztof kuhy Rudnicki c2972c4c33 Fix check_and_enable_services.sh and hosts guard
- Fix startup_monitor check to verify timer instead of service
- Fix pacman hooks filename check (10-unlock-etc-hosts.hook, 90-relock-etc-hosts.hook)
- Add re-verification after fixes to update status correctly
- Set immutable attribute before bind mount in pacman-post-relock-hosts.sh
- Add new check_and_enable_services.sh script for verifying all digital wellbeing services
2025-12-04 15:14:50 +01:00
..
pacman-hooks Fix check_and_enable_services.sh and hosts guard 2025-12-04 15:14:50 +01:00
psychological fix: shellcheck issues 2025-11-01 15:36:22 +01:00
enforce-hosts.sh fix: shellcheck issues 2025-11-01 15:36:22 +01:00
hosts-bind-mount.service feat: more etc hosts friction 2025-10-01 20:50:56 +02:00
hosts-guard.path feat: more etc hosts friction 2025-10-01 20:50:56 +02:00
hosts-guard.service feat: more etc hosts friction 2025-10-01 20:50:56 +02:00
install_pacman_hooks.sh fix: shellcheck issues 2025-11-01 15:36:22 +01:00
README.md fix: pacman hooks for hosts 2025-10-13 10:21:35 +02:00
setup_hosts_guard.sh fix: shellcheck issues 2025-11-01 15:36:22 +01:00

Hosts Guard Components

This directory contains templates for hardening /etc/hosts against impulsive tampering by adding friction, NOT providing absolute security against a determined root user.

Components:

  1. enforce-hosts.sh Idempotent script that: compares /etc/hosts with canonical copy at /usr/local/share/locked-hosts and restores if different; reapplies immutable attribute.
  2. systemd units (to be installed under /etc/systemd/system):
    • hosts-guard.service (oneshot enforcement)
    • hosts-guard.path (triggers on PathChanged=/etc/hosts)
    • hosts-bind-mount.service (bind mounts /etc/hosts read-only after boot)
  3. psychological/ directory scripts that add delay + journaling before allowing a maintenance/unlock operation.
  4. pacman hooks automatically unlock/re-lock /etc/hosts around package transactions so pacman never fails due to the read-only bind mount.

Install Flow (suggested):

  1. After generating /etc/hosts via your existing hosts/install.sh, copy it to /usr/local/share/locked-hosts.
  2. Install enforce-hosts.sh to /usr/local/sbin/ (chmod 755).
  3. Place units and enable: systemctl daemon-reload systemctl enable --now hosts-guard.path systemctl enable --now hosts-bind-mount.service
  4. (Optional) Use psychological/unlock-hosts.sh as the ONLY sanctioned way to modify hosts (it removes protections temporarily, launches an editor after a delay, and re-enforces on close).
  5. Make pacman automatic (recommended): ./install_pacman_hooks.sh This installs hooks under /etc/pacman.d/hooks that:
    • PreTransaction: temporarily disable guard and make /etc/hosts writable
    • PostTransaction: re-run enforcement and re-enable guard (bind mount + path watcher)

Limitations:

  • A root user can still disable units, remount, remove attributes.
  • Purpose is to interrupt habit loops and create intentional friction.