testsAndMisc/linux_configuration/docs/SUMMARY.md
Krzysztof kuhy Rudnicki 4f2b0ccdf7 Dissolve linux_configuration/scripts/ and single_use/
Two levels of pure taxonomy carrying no information, and a 2-directory
cap leaves no room for them. Categories now sit directly under
linux_configuration/: features, fixes, utils, misc, fresh-install,
installers, diagnostics, gaming, boot_recovery, periodic_background, lib,
meta, tests. A script's own lib/ and tests/ are exempt from the cap, so
those stay put.

Depth violations 248 -> 139; roughly 40 of the remainder are inside
digital_wellbeing and hosts, deferred until the guard-lib repoint.

The moves are the easy half. What breaks is every path that counted
levels, and three classes of it had to be found by resolving paths rather
than reading diffs:

  - 52 relative `source` lines for lib/common.sh and lib/android.sh. The
    correct prefix differs per file: 40 were ../../ and 12 were ../../../,
    so a blanket replace would have fixed one set and broken the other.
  - REPO_ROOT in 7 fixes/lib/tests harnesses and setup_syncyomi_guard.sh,
    each walking up four levels from a directory now two levels shallower.
    This caused a real regression -- the fixes suite went red with
    "log_warn: command not found" -- caught by running it and comparing
    against the pre-move baseline worktree.
  - conftest.py's sys.path entries, which took the pytest gate down with
    14 collection errors, and the `# shellcheck source=` directives, which
    took shellcheck down with SC1091.

16 symlinks in $HOME broke, including the entire i3blocks bar. All
repointed, and cpu_monitor/memory/disk/time/volume were run to confirm
they emit real output rather than merely resolving.

Verified: 1798 tests pass at 100% coverage, 8 of 9 lib/tests suites pass
(the ninth needs the coverage jail, identically at baseline), pre-commit
is clean, and the two untracked secret configs are still ignored after
their gitignore paths changed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
2026-08-23 18:53:30 +02:00

164 lines
5.6 KiB
Markdown

# Security Enhancement Summary
## Problem Addressed
The pacman wrapper had two critical security vulnerabilities:
1. **Easy Policy Bypass**: Users could edit `pacman_greylist.txt` to remove "virtualbox", reinstall the wrapper, and bypass all restrictions.
2. **VirtualBox Hosts Bypass**: VirtualBox VMs do not inherit the host's `/etc/hosts` file, allowing complete circumvention of content filtering inside VMs.
## Solution Overview
Implemented a **defense-in-depth** security architecture with multiple layers:
### Layer 1: Immutable Policy Files
- Policy files (`pacman_blocked_keywords.txt`, `pacman_greylist.txt`) are made immutable using `chattr +i`
- Prevents casual editing without root access and knowledge of filesystem attributes
- Requires explicit `chattr -i` command to modify
### Layer 2: SHA256 Integrity Checks
- SHA256 checksums generated for all policy files during installation
- Stored in `/var/lib/pacman-wrapper/policy.sha256` (also made immutable)
- **Every wrapper invocation** verifies file integrity before proceeding
- **Blocks all operations** if tampering is detected
### Layer 3: Hardcoded VirtualBox Restrictions
- VirtualBox detection is **compiled into the wrapper code**
- Cannot be bypassed by editing any text file
- Catches all packages matching `*virtualbox*` or `*vbox*` patterns
- More difficult challenge than standard greylist:
- 7-letter words (vs 6 for greylist)
- 150 words to memorize (vs 120)
- 120-second timeout (vs 90s)
- 45-second initial delay (vs 30s)
### Layer 4: VirtualBox Enforcement
- New script: `periodic_background/digital_wellbeing/virtualbox/enforce_vbox_hosts.sh`
- Automatically configures all VMs to:
- Use host's DNS resolution (`--natdnshostresolver1 on`)
- Enable NAT DNS proxy (`--natdnsproxy1 on`)
- Share `/etc` folder (read-only) for hosts file access
- Generates startup script for VM guests to sync hosts file
- Automatically runs after any VirtualBox installation
### Layer 5: Psychological Friction
- Enhanced delays and timeouts
- Clear warning messages about security implications
- Emphasizes that restrictions are hardcoded and cannot be easily bypassed
## Files Changed
### New Files (4)
1. `periodic_background/digital_wellbeing/virtualbox/enforce_vbox_hosts.sh` - VirtualBox enforcement script
2. `tests/test_pacman_wrapper_security.sh` - Comprehensive test suite (12 tests)
3. `docs/PACMAN_WRAPPER_SECURITY.md` - Detailed security documentation
4. `docs/SUMMARY.md` - This summary
### Modified Files (2)
1. `periodic_background/digital_wellbeing/pacman/install_pacman_wrapper.sh` - Added integrity checks and immutable attributes
2. `periodic_background/digital_wellbeing/pacman/pacman_wrapper.sh` - Added integrity verification and VirtualBox enforcement
## Security Guarantees
### What's Now Protected
✅ Policy files cannot be easily modified (immutable + checksums)
✅ VirtualBox restrictions are hardcoded (cannot bypass via file editing)
✅ VMs inherit host's content filtering (DNS proxy + shared hosts)
✅ Tampering is immediately detected and blocked
✅ Enhanced psychological friction for VirtualBox installation
### Known Limitations
⚠️ Root access can still bypass everything (by design - this is self-discipline, not security vs root)
⚠️ VM without Guest Additions won't get shared folder (but DNS proxy still works)
⚠️ Could replace `/usr/bin/pacman` symlink (but periodic maintenance can detect)
## Testing
All changes are fully tested:
```bash
bash tests/test_pacman_wrapper_security.sh
# ✓ All 12 tests pass
```
Tests verify:
- Script syntax validity
- Integrity check function exists and is called early
- Hardcoded VirtualBox detection exists
- VirtualBox challenge function exists
- Policy files are made immutable
- VirtualBox enforcement is integrated
- Error handling is proper
## Installation
```bash
cd periodic_background/digital_wellbeing/pacman
sudo ./install_pacman_wrapper.sh
```
This will:
1. Install wrapper and policy files
2. Generate SHA256 checksums
3. Make policy files immutable with `chattr +i`
4. Install VirtualBox enforcement script
5. Set up automatic enforcement
## Usage Impact
### For Normal Package Operations
- No change to normal pacman operations
- Integrity check adds minimal overhead (<100ms)
- Only applies to package installations/removals
### For VirtualBox Installation
- Must complete difficult word challenge (7-letter words, 120s timeout)
- Enhanced warnings about security implications
- Automatic VM configuration after successful installation
- Cannot bypass by editing policy files
### For Updating Policies
If legitimate policy updates are needed:
```bash
sudo chattr -i /usr/local/bin/pacman_greylist.txt
sudo nano /usr/local/bin/pacman_greylist.txt
cd periodic_background/digital_wellbeing/pacman
sudo ./install_pacman_wrapper.sh # Regenerates checksums
```
## Statistics
- **Lines Added**: 869
- **New Functions**: 7
- **Security Layers**: 5
- **Test Coverage**: 12 tests
- **Documentation**: 245 lines
## Conclusion
This enhancement significantly raises the bar for circumventing the pacman wrapper's restrictions:
**Before**: Edit text file → reinstall wrapper → bypass complete
**After**: Remove immutable attribute → edit text file → reinstall wrapper → still blocked by hardcoded check
For VirtualBox specifically:
**Before**: Install in VM → bypass all /etc/hosts restrictions
**After**: Complete difficult challenge → auto-configured to use host's DNS and hosts file
The solution balances security with usability, making casual circumvention significantly harder while maintaining transparency about what's being enforced and why.