Test that what root runs is root's alone

60-security.sh now also checks, in the smoketest VM, that each file
CoreDesktop installs for root (the pacman guard and hook, the captive
portal script, sshd, ufw and systemd settings, and after configure
security-key and fingerprint, the PAM files, the lid check and the key
list), and every folder above it, is root's and not writable by the
user; that nothing in /etc, /usr, /boot or /opt is the user's to write;
and that nothing root runs names a path in a home folder.

pam_env gives logins ~/.local/bin on PATH, so it checks that root's
PATH under sudo, sudo -i and systemd has only root's folders, also for
a user who types a password: tester's sudo needs none, and then PAM's
auth step, where Arch runs pam_env, never runs. With a security key
registered but not plugged in and fingerprints turned on, the password
still works for sudo and a wrong or missing one doesn't.

It found nothing to fix. Each check was shown to fail on a machine
broken the way it looks for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 17:07:44 -07:00
co-authored by Claude Opus 5.5
parent e991264ddc
commit d5925fa551
2 changed files with 216 additions and 34 deletions
@@ -1,6 +1,6 @@
--- ---
name: coredesktop-security-checks name: coredesktop-security-checks
description: Plan and progress for CoreDesktop's security test suite. The report receiver, report's redaction and the agent sandbox are tested; the checks still to write run in the smoketest VM (network exposure, what root runs, the install path). Use when resuming, continuing, checking the status of, or changing CoreDesktop's security or penetration tests. description: Plan and progress for CoreDesktop's security test suite. The report receiver, report's redaction, the agent sandbox and what root runs are tested; the checks still to write run in the smoketest VM (network exposure, the install path). Use when resuming, continuing, checking the status of, or changing CoreDesktop's security or penetration tests.
--- ---
# CoreDesktop's security checks # CoreDesktop's security checks
@@ -25,7 +25,7 @@ leak data or give away control, in this order:
2. `report`'s redaction, which decides what leaves a user's computer. **Done.** 2. `report`'s redaction, which decides what leaves a user's computer. **Done.**
3. The agent sandbox: the one place that runs code CoreDesktop doesn't trust. **Done.** 3. The agent sandbox: the one place that runs code CoreDesktop doesn't trust. **Done.**
4. Network exposure from outside. 4. Network exposure from outside.
5. Files root runs, and secrets only root may read. 5. Files root runs, and secrets only root may read. **Done.**
6. The install path (federated.sh, the `[federated]` repo). 6. The install path (federated.sh, the `[federated]` repo).
The pacman guard (`system/pacman-guard`) is The pacman guard (`system/pacman-guard`) is
@@ -105,6 +105,30 @@ Lessons for the next scenarios:
- Outside checks can leave state behind (an empty config file broke a later - Outside checks can leave state behind (an empty config file broke a later
check once); make them look, not change. check once); make them look, not change.
## Done: step 5 (the commit "Test that what root runs is root's alone")
`root_checks` in `60-security.sh`. It found nothing to fix. It checks:
- `ROOT_FILES` and `PAM_FILES` (keep them up to date when CoreDesktop installs
something root runs): each, and every folder above it, is root's and not
writable by the user, following links too (`root_only`)
- nothing in /etc, /usr, /boot or /opt is the user's or writable by them
- no `/home`, `~/`, `$HOME` or `@{HOME}` in what root runs: system units,
pacman hooks, NetworkManager dispatcher, PAM, sudoers, udev and polkit
rules, /usr/local
- root's PATH under sudo, sudo -i and systemd has only root's folders.
`pam_env.conf` gives logins `@{HOME}/.local/bin`; sudo's secure_path keeps
it from root. Checked as `pamtest`, who types a password: `tester`'s sudo
needs none, so PAM's auth step, where Arch runs pam_env, never runs for it.
- the real `use_keys` and `use_fingerprint`, with a key registered but not
plugged in: the password still works, a wrong or empty one doesn't, and the
sudo and polkit-1 stacks only gained their lines
Each check was shown to fail by a throwaway scenario that broke the VM five
ways (a world-writable file, a user-owned folder above the guard, a unit
running from /home, secure_path in /home, `pam_permit.so` atop sudo's stack).
`/etc/coredesktop/smb` isn't checked: only `configure storage` makes it, which
needs an SMB server.
## Running the smoketest ## Running the smoketest
- `coredesktop-dev smoketest run 60-security`, outside Claude Code's sandbox - `coredesktop-dev smoketest run 60-security`, outside Claude Code's sandbox
@@ -118,7 +142,7 @@ Lessons for the next scenarios:
- The user's global git config has no name or email. Commits so far used - The user's global git config has no name or email. Commits so far used
`git -c user.name="David Young" -c user.email=...` from the repo's history. `git -c user.name="David Young" -c user.email=...` from the repo's history.
## Next: steps 4 to 6 in the smoketest VM ## Next: steps 4 and 6 in the smoketest VM
Add them to `smoketest/scenarios/60-security.sh` (or a sibling scenario if it Add them to `smoketest/scenarios/60-security.sh` (or a sibling scenario if it
grows too long), with the same `check` style. Where a check needs a second grows too long), with the same `check` style. Where a check needs a second
@@ -141,30 +165,6 @@ VM against itself goes through loopback, which ufw allows. Find out from
`coredesktop-dev` whether the VM can get a bridged or tap network, or a second `coredesktop-dev` whether the VM can get a bridged or tap network, or a second
VM, before writing this one. VM, before writing this one.
### 5. What root runs, and root-only secrets
Every file root runs must be owned by root and not writable by the user, and
so must every folder above it. Check it with `stat`, walking up to `/`. As of
2026-11-16:
- `/etc/coredesktop/smb` (mode 600, root), sshd's
`10-coredesktop-keys-only.conf`, the ufw rules, and the systemd drop-ins in
`system/defaults.sh`.
- Added with the Omarchy features (commit 9dc5eb1):
- the pacman hook `/etc/pacman.d/hooks/00-coredesktop-guard.hook` and
`/usr/local/lib/coredesktop/pacman-guard`
- `/etc/NetworkManager/dispatcher.d/90-coredesktop-captive-portal`
- after `configure security-key` and `configure fingerprint`:
`/usr/local/lib/coredesktop/lid-closed`, `/etc/pam.d/sudo`,
`/etc/pam.d/polkit-1` and `/etc/u2f_mappings`
Also check that nothing root runs reads a path in a user's home. That's why
the pacman guard and the lid check are copies in /usr/local, not run from
~/.local/share/coredesktop.
For `/etc/pam.d/sudo`: after the fingerprint or security-key item, a wrong
password must still fail, and `sudo -k; sudo true` without the key must still
ask for the password.
### 6. The install path ### 6. The install path
- `https://federated.sh` sends `wget` (User-Agent not starting with - `https://federated.sh` sends `wget` (User-Agent not starting with
+189 -7
View File
@@ -1,10 +1,10 @@
#!/bin/bash #!/bin/bash
# shellcheck disable=SC2034,SC2016 # shellcheck disable=SC2034,SC2016
DESCRIPTION="security: what an agent in the sandbox can't read, write, reach or see" DESCRIPTION="security: what an agent in the sandbox can't do, and what root runs"
IMAGE=installed IMAGE=installed
TIER="nightly" TIER="nightly"
# Each check is made twice. Outside the sandbox it must work, so the thing is # Step 3 of the security checks: the agent sandbox. Each check is made twice. Outside the sandbox it must work, so the thing is
# really there. Inside it must fail, while a marker shows that the sandbox did # really there. Inside it must fail, while a marker shows that the sandbox did
# start, so a wrapper that fails to start doesn't count as a pass. # start, so a wrapper that fails to start doesn't count as a pass.
# #
@@ -13,8 +13,10 @@ TIER="nightly"
# runs it exactly as it would run opencode, Hermes or Cline Desktop: same # runs it exactly as it would run opencode, Hermes or Cline Desktop: same
# config, same srt, same proxy. # config, same srt, same proxy.
# #
# Steps 4 to 6 of the security checks (network exposure, what root runs, the # Step 5, below the sandbox's: what root runs is root's alone, nothing root runs
# install path) are still to come. # is in a user's home, and a security key or fingerprint for sudo keeps the
# password working. Steps 4 (network exposure, which needs a second machine)
# and 6 (the install path) are still to come.
AGENTS=(opencode hermes cline-desktop) AGENTS=(opencode hermes cline-desktop)
FAKE_BIN="\$HOME/smoketest-agents" FAKE_BIN="\$HOME/smoketest-agents"
@@ -28,7 +30,7 @@ LAN_PORT_OTHER=18081
LOOPBACK_PORT=18082 LOOPBACK_PORT=18082
USER_SANDBOX_CONF="\$HOME/.config/coredesktop/sandbox/base.json" USER_SANDBOX_CONF="\$HOME/.config/coredesktop/sandbox/base.json"
# The sandbox checks that failed. A failure doesn't stop the others, so one # The checks that failed. A failure doesn't stop the others, so one
# run shows every gap; the scenario fails at the end if there were any. # run shows every gap; the scenario fails at the end if there were any.
FAILED=() FAILED=()
@@ -142,7 +144,182 @@ setup_vm() {
exit 1" exit 1"
} }
scenario() { # --- Step 5: what root runs, and root-only secrets ---------------------------
# A user who has to type a password for sudo. tester's sudo needs none, and
# then PAM's auth step, which is also where Arch's system-auth runs pam_env,
# never runs.
PAM_USER=pamtest
PAM_PASSWORD=Smoketest-pw-1
# Files CoreDesktop installs that root runs or reads, on every installed machine
ROOT_FILES=(
/usr/local/lib/coredesktop/pacman-guard
/etc/pacman.d/hooks/00-coredesktop-guard.hook
/etc/NetworkManager/dispatcher.d/90-coredesktop-captive-portal
/etc/ssh/sshd_config.d/10-coredesktop-keys-only.conf
/etc/ssh/ssh_config.d/20-coredesktop-keepalive.conf
/etc/systemd/system.conf.d/10-coredesktop-timeout.conf
/etc/systemd/user.conf.d/10-coredesktop-timeout.conf
/etc/systemd/user/app.slice.d/10-coredesktop-oomd.conf
/etc/security/pam_env.conf
/etc/security/faillock.conf
/etc/ufw/after.rules
/etc/ufw/user.rules
/etc/ufw/user6.rules
/etc/xdg/reflector/reflector.conf
/etc/pacman.conf
/etc/fstab
/etc/avahi/services/ssh.service
/etc/nsswitch.conf
)
# And those configure security-key and configure fingerprint add
PAM_FILES=(
/usr/local/lib/coredesktop/lid-closed
/etc/pam.d/sudo
/etc/pam.d/polkit-1
/etc/u2f_mappings
)
# VM-side helpers, put in front of the scripts that use them
ROOT_LIB='
# root_only PATH: PATH, or the nearest folder above it that exists, and every
# folder above that up to /, are owned by root and not writable by whoever runs
# this. Both the path as named and, if a link leads elsewhere, where it leads.
root_only() {
local p="$1" real
while [ ! -e "$p" ] && [ ! -L "$p" ] && [ "$p" != / ]; do p="$(dirname "$p")"; done
root_only_chain "$p" || return 1
real="$(realpath -e "$p")" || { echo "$p: a link to nowhere"; return 1; }
[ "$real" = "$p" ] || root_only_chain "$real"
}
root_only_chain() {
local p="$1"
while :; do
if [ "$(stat -c %u "$p")" != 0 ] || { [ ! -L "$p" ] && [ -w "$p" ]; }; then
echo "$p: owned by $(stat -c %U "$p"), mode $(stat -c %a "$p"), writable by $(id -un): $([ -w "$p" ] && echo yes || echo no)"
return 1
fi
[ "$p" = / ] && return 0
p="$(dirname "$p")"
done
}
# path_root_only PATH-VALUE: every folder in a PATH is root_only
path_root_only() {
local dir status=0 IFS=:
echo "PATH: $1"
for dir in $1; do
[ -n "$dir" ] || { echo "PATH has an empty entry, which means the current folder"; status=1; continue; }
case "$dir" in /*) ;; *) echo "PATH has a relative entry: $dir"; status=1; continue ;; esac
root_only "$dir" || status=1
done
return $status
}
'
# as_pam_user SCRIPT: a VM script that runs SCRIPT as PAM_USER
as_pam_user() {
echo "sudo -u $PAM_USER -i bash -c $(q "$1")"
}
# pam_sudo PASSWORD: a VM script in which PAM_USER runs sudo true with PASSWORD
pam_sudo() {
as_pam_user "echo $(q "$1") | timeout 60 sudo -S -k true"
}
setup_root_checks() {
assert_vm "make a user who types a password for sudo" "set -e
id $PAM_USER > /dev/null 2>&1 || sudo useradd -m $PAM_USER
echo $PAM_USER:$PAM_PASSWORD | sudo chpasswd
echo '$PAM_USER ALL=(ALL) ALL' | sudo install -m 440 /dev/stdin /etc/sudoers.d/50-smoketest-$PAM_USER
sudo visudo -c > /dev/null"
}
# Turn on configure security-key and configure fingerprint the way they do it,
# with no key or reader: PAM_USER has a key registered, but it isn't plugged in
use_security_key_and_fingerprint() {
assert_vm "keep the PAM files as they were" "set -e
sudo install -d -m 700 /root/smoketest-pam
sudo cp /etc/pam.d/sudo /root/smoketest-pam/sudo
if [ -f /etc/pam.d/polkit-1 ]; then sudo cp /etc/pam.d/polkit-1 /root/smoketest-pam/polkit-1
else sudo cp /usr/lib/pam.d/polkit-1 /root/smoketest-pam/polkit-1; fi"
assert_vm "turn on the security key and fingerprint for sudo and polkit" "set -e
export COREDESKTOP=\$HOME/.local/share/coredesktop
sudo pacman -S --needed --noconfirm pam-u2f fprintd > /dev/null
source \$COREDESKTOP/configure.d/70-security-key.sh
use_keys
echo '$PAM_USER:smoketest-handle,smoketest-key,es256,+presence' | sudo tee -a \$U2F_MAPPINGS > /dev/null
sudo chmod 644 \$U2F_MAPPINGS
source \$COREDESKTOP/configure.d/71-fingerprint.sh
use_fingerprint
grep -q pam_u2f.so /etc/pam.d/sudo && grep -q pam_fprintd.so /etc/pam.d/polkit-1"
}
root_checks() {
local file service
setup_root_checks
# --- Files root runs ---
for file in "${ROOT_FILES[@]}"; do
check "root: $file and the folders above it are root's alone" "$ROOT_LIB
[ -e $file ] || { echo 'missing: $file'; exit 1; }
root_only $file"
done
# /etc/coredesktop/smb isn't here: only configure storage makes it, which
# needs an SMB server. It writes it with install -m 600 -o root.
# Anything in the system's folders the user can write, CoreDesktop's or not
check "root: nothing in /etc, /usr, /boot or /opt is the user's to write" "
found=\$(find /etc /usr /boot /opt -xdev \\( -writable -o -user \$(id -u) \\) ! -type l -print 2> /dev/null | head -n 20)
[ -z \"\$found\" ] || { echo \"\$found\"; exit 1; }"
# --- Nothing root runs is in a user's home ---
# System units, pacman hooks, NetworkManager's scripts, PAM, sudo, udev and
# polkit rules: what root runs on its own or for anyone. (fstab's davfs line
# and pam_env's PATH name home folders for the user's own use; PATH is
# checked below.)
check "root: nothing root runs names a path in a home folder" "
found=\$(sudo grep -rnIE '/home/|~/|\\\$HOME|@\\{HOME\\}' /etc/systemd/system /etc/pacman.d/hooks \
/etc/NetworkManager/dispatcher.d /etc/pam.d /etc/udev/rules.d /etc/sudoers /etc/sudoers.d \
/etc/polkit-1/rules.d /usr/local 2> /dev/null)
[ -z \"\$found\" ] || { echo \"\$found\"; exit 1; }"
# pam_env.conf gives logins @{HOME}/.local/bin and mise's shims. Root must
# get neither, whoever runs sudo, or the user could put a sudo command there.
check "root: sudo's PATH (tester, no password) has only root's folders" "$ROOT_LIB
path_root_only \"\$(sudo sh -c 'echo \$PATH')\""
check "root: sudo -i's PATH (tester) has only root's folders" "$ROOT_LIB
path_root_only \"\$(sudo -i sh -c 'echo \$PATH')\""
check "root: sudo's PATH ($PAM_USER, with a password) has only root's folders" "$ROOT_LIB
path=\$($(as_pam_user "echo $(q "$PAM_PASSWORD") | sudo -S -k sh -c 'echo \$PATH' 2> /dev/null"))
path_root_only \"\$path\""
check "root: systemd's PATH for system services has only root's folders" "$ROOT_LIB
path_root_only \"\$(systemctl show-environment | sed -n 's/^PATH=//p')\""
# --- PAM: a security key and a fingerprint add a way in, and take none away ---
check "pam: before: $PAM_USER's password works for sudo" "$(pam_sudo "$PAM_PASSWORD")"
check "pam: before: a wrong password doesn't" "! $(pam_sudo wrong-password)"
use_security_key_and_fingerprint
for file in "${PAM_FILES[@]}"; do
check "root: $file and the folders above it are root's alone" "$ROOT_LIB
[ -e $file ] || { echo 'missing: $file'; exit 1; }
root_only $file"
done
for service in sudo polkit-1; do
check "pam: $service's stack only gained the key and fingerprint lines" "
diff <(sudo cat /root/smoketest-pam/$service) \
<(grep -vE 'pam_u2f\\.so|pam_fprintd\\.so|/usr/local/lib/coredesktop/lid-closed' /etc/pam.d/$service)"
done
assert_vm "reset $PAM_USER's failed logins" "sudo faillock --user $PAM_USER --reset"
# Without the key or a finger, it falls through to the password, as before
check "pam: after: $PAM_USER's password still works for sudo" "$(pam_sudo "$PAM_PASSWORD")"
check "pam: after: a wrong password still doesn't" "! $(pam_sudo wrong-password)"
check "pam: after: no password at all doesn't" "! $(as_pam_user 'timeout 60 sudo -S -k true < /dev/null')"
}
sandbox_checks() {
local agent secret lan="http://\$(cat \$HOME/smoketest-lan-ip)" local agent secret lan="http://\$(cat \$HOME/smoketest-lan-ip)"
setup_vm setup_vm
@@ -208,9 +385,14 @@ scenario() {
blocked "talks to the D-Bus session bus" \ blocked "talks to the D-Bus session bus" \
'gdbus call --session --timeout 5 --dest org.freedesktop.DBus --object-path /org/freedesktop/DBus --method org.freedesktop.DBus.ListNames' 'gdbus call --session --timeout 5 --dest org.freedesktop.DBus --object-path /org/freedesktop/DBus --method org.freedesktop.DBus.ListNames'
blocked "talks to systemd --user" 'systemctl --user show-environment > /dev/null' blocked "talks to systemd --user" 'systemctl --user show-environment > /dev/null'
}
scenario() {
sandbox_checks
root_checks
if [ ${#FAILED[@]} -gt 0 ]; then if [ ${#FAILED[@]} -gt 0 ]; then
printf 'failed: %s\n' "${FAILED[@]}" printf 'failed: %s\n' "${FAILED[@]}"
fail "${#FAILED[@]} sandbox checks failed" fail "${#FAILED[@]} security checks failed"
fi fi
} }