Files
coredesktop/.claude/skills/coredesktop-security-checks/SKILL.md
T
davidandClaude Opus 5.5 ffbaf71ba7
shellcheck / shellcheck (push) Failing after 19s
Keep other machines on the network from reaching Docker containers
60-security.sh now checks network exposure (step 4), from two other
machines made of network namespaces in the VM: one on private addresses,
like a neighbour on the same Wi-Fi, and one on public-looking ones. From
each, over IPv4 and IPv6: only SSH and LocalSend are open, a container's
published port can't be reached, containers still reach both machines,
and SSH takes keys only. It also checks ufw's rules and sshd -T.

It found that ufw-docker's rules let any private address (10/8,
172.16/12, 192.168/16) reach published ports, so anyone on a café's or
hotel's Wi-Fi could. system/docker-firewall.sh lets only Docker's own
bridges (docker0, br-+) past instead; firewall.sh runs it on a new
install and migration 1794878760 on existing machines. To let other
machines reach a container's port: sudo ufw-docker allow <container> <port>.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 07:32:44 -07:00

12 KiB


name: coredesktop-security-checks description: Plan and progress for CoreDesktop's security test suite. All six steps are written and pass: the report receiver, report's redaction, and in the smoketest VM (smoketest/scenarios/60-security.sh) the agent sandbox, network exposure, what root runs and the install path. A few follow-ups remain. Use when resuming, checking the status of, extending or changing CoreDesktop's security or penetration tests.

CoreDesktop's security checks

Written on 2026-11-16; all six steps were done the same day. Work out the current state before doing anything:

git -C ~/Projects/coredesktop fetch && git -C ~/Projects/coredesktop log --oneline origin/main -15
ls ~/Projects/coredesktop/smoketest/scenarios/ ~/Projects/coredesktop/server/report-receiver/

Tell the user what's left (the follow-ups below) and confirm before starting any of it.

Scope

The suite covers what CoreDesktop itself adds. It doesn't test Arch or GNOME, which upstream looks after. It goes after the places where a mistake would leak data or give away control, in this order:

  1. The report receiver, the only part on the public internet. 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.
  4. Network exposure from outside. Done.
  5. Files root runs, and secrets only root may read. Done.
  6. The install path (federated.sh, the [federated] repo). Done.

The pacman guard (system/pacman-guard) is a safety net against mistakes, not a security control: anyone with sudo gets past it by design. Don't test it as a boundary.

Done: steps 1 and 2 (the commit "Test the report receiver and redaction against attacks")

  • server/report-receiver/test_security.py sends the receiver what an attacker could. It found, and the commit fixed:

    • a negative Content-Length (read without limit)
    • parts nested thousands deep (RecursionError, connection dropped)
    • thousands of parts (8 s of CPU for 5.7 MB)
    • a rate limit per IPv6 address instead of per /64
    • Markdown in report fields reaching the Gitea issue: @mentions, issue references, links, tracking images
    • no guard against filling the disk
  • tests/report.bats (the "Redaction" section) found report sending:

    • passwords in URLs
    • tokens, API keys, Nextcloud app passwords and private keys
    • IPv6 and MAC addresses
    • the Core's domain and the user's name
    • user and host names with regex characters, unredacted

    All fixed. A test also checks it doesn't over-redact (pacman's ::, times, epoch versions, std::string).

  • Each test was checked to fail against the code before the fix.

Still open from these steps:

  • Deploy the new receiver.py on federated.sh (server/report-receiver/README.md, "To update it later").
  • Slow uploads. Caddy streams them to the receiver, one thread each. Try request_buffers 11MB in Caddyfile.example's reverse_proxy, and check that caddy validate accepts it.
  • Gitea attachments. Check on the real server that Gitea serves attached .log files as text or as downloads, never as HTML (a log can contain <script>).
  • The daily limit. The 500-a-day limit for everyone lets one sender block reports for a day. That was left as a design trade-off; ask before changing it.

Done: step 3 (the commits "Test the agent sandbox from inside..." and the Hermes homeserver fix)

smoketest/scenarios/60-security.sh runs a script as opencode, Hermes and Cline Desktop would, through sandbox/bin's wrappers with a fake agent first on PATH, so it gets the real config, srt and proxy. About 130 checks; each runs outside the sandbox too, where it must work. It checks that agents can't:

  • read ~/.ssh, ~/.gnupg, the keyring, Bitwarden (package and Flatpak), ~/.config/coredesktop, ~/.winboat, or /etc/coredesktop/smb via sudo
  • write home, another project, ~/.bashrc, ~/.local/bin, systemd user units, autostart, either sandbox config, srt's settings file, or the project's .git/hooks and .git/config
  • reach domains, LAN addresses or this machine's loopback servers that aren't allowed, or anything without the proxy; an allowed LAN host:port works and another port on that host doesn't
  • see root's processes or GNOME Shell, or talk to the D-Bus session bus or systemctl --user

What it found, all fixed:

  • every sandbox could read ~/.config/coredesktop (the Core's domain and user name); sandbox/config/base.json now hides it
  • found by reading the code, not the scenario: Hermes could write MATRIX_HOMESERVER in ~/.hermes/.env, and sandbox/setup.sh then allowed that host for the gateway. The allowed homeserver now lives in ~/.config/coredesktop/sandbox/hermes.json, which configure hermes asks about (sandbox/hermes-homeserver.sh); a migration carried over the one allowed before. Tested in tests/sandbox.bats.
  • edit_json (configure.d/lib/json.sh) wrote nothing back to an empty file, so configure ai-servers could report a server added that wasn't.

Lessons for the next scenarios:

  • A write check must look at the real file from outside. srt hides a denied folder by mounting an empty, writable tmpfs over it, so a write in the sandbox can "work" and go nowhere. See write_blocked.
  • Every in-sandbox check prints a marker first, so a wrapper that fails to start isn't counted as the sandbox blocking something.
  • The scenario's check records a failure and goes on, and fails at the end, so one run shows every gap. Keep that for steps 4 to 6.
  • Outside checks can leave state behind (an empty config file broke a later 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.

Done: step 6 (the commit "Test the install path")

install_path_checks in 60-security.sh. It found nothing to fix.

  • federated.sh, live: wget is redirected to install.sh on Gitea, every hop HTTPS (curl --proto-redir =https); real wget gets it; plain HTTP redirects to HTTPS without serving the script; a browser goes to coredesktop.computer. install.sh's shebang is #!/bin/bash -i. The nightly run fails if federated.sh or Gitea is down.
  • [federated] in pacman.conf is exactly SigLevel = Required DatabaseRequired and the HTTPS server, after [core] and [extra]; the pinned key is fully trusted; Gitea's repository.key is that key alone.
  • A stand-in repo (a package built in the VM, served from files, with [federated]'s real settings and keyring, installed into a throwaway root): pacman refuses it unsigned, signed by an unknown key, signed by a key it has but doesn't trust, and with a signed database but unsigned package; the control, its key trusted in a copy of the keyring, installs.
  • Code scan: every download piped to bash or pacman-key is HTTPS; no --insecure or weak SigLevel.
  • pacman can't pin a repo to one key: Required takes any trusted key, Arch packagers' too. Not fixable in CoreDesktop.

A sabotage run (SigLevel Optional TrustAll, [federated] above [core], the key deleted) failed the matching checks, and found a check that tested only its last line: give a check's tests &&, or end on the one that counts, since check scripts don't run with set -e.

Running the smoketest

  • coredesktop-dev smoketest run 60-security, outside Claude Code's sandbox (it needs KVM). The first run builds the installed image (an hour or more); later runs take about five minutes.
  • It tests a commit. To test uncommitted changes, including new files, make a throwaway commit without touching the branch: write a tree from a temporary index (GIT_INDEX_FILE=... git add -A; git write-tree; git commit-tree) and pass it with --ref. The scenario files themselves are read from the working copy.
  • The user's global git config had no name or email on 2026-11-16. A privacy hook refuses commands that put the user's email address on the command line (git -c user.email=...), so if it's still unset, ask the user to set it or to commit themselves. Throwaway test commits can use Smoketest <smoketest@localhost>.
  • The full 60-security run takes about 12 minutes; past the Bash tool's 10, so run it in the background.

Done: step 4 (the commit "Keep other machines on the network from reaching Docker containers")

network_checks in 60-security.sh. There's no second VM or bridged network (coredesktop-dev uses QEMU user networking), so the scenario makes two "other machines" inside the VM: network namespaces joined by veth pairs, whose traffic arrives on an ordinary interface like a LAN machine's. lan has private addresses (192.168.77.0/24, fd77:1::/64), wan public-looking ones (198.51.100.0/24, 2001:db8:77::/64). From each, over IPv4 and IPv6:

  • nmap -p- finds only 22 and 53317 open; a test listener on every address doesn't show
  • UDP 18091 doesn't answer; LocalSend's 53317 does (the control)
  • a container's published port can't be reached; containers on Docker's default bridge and on their own network still reach both machines; after ufw-docker allow, the LAN machine reaches the container
  • SSH offers only publickey, and tester's real password (tester) fails Plus: ufw is active, denies incoming, and has exactly the four allow rules; sshd -T (CamelCase names in this OpenSSH) has no passwords, keyboard-interactive or root login.

It found: ufw-docker's rules let any private source (10/8, 172.16/12, 192.168/16) reach published ports over IPv4, so anyone on the same Wi-Fi could. The user chose to block it. system/docker-firewall.sh replaces those lines with -i docker0 and -i br-+ RETURNs (run by system/firewall.sh and migration 1794878760); tests/firewall.bats tests it. People who reached a container from their LAN now need sudo ufw-docker allow <container> <port>.

Lessons: socat UDP-RECVFROM,fork answered only its first sender; loop a one-shot listener instead. Show a check's evidence on failure (the ufw-docker block, sshd -T's output) so a run explains itself.

Follow-ups

  • From steps 1 and 2 (above): deploy the new receiver.py; try Caddy's request_buffers for slow uploads; check how Gitea serves attached .log files; the daily report limit (ask before changing it).
  • The tailscale0 allow rule isn't tested: it needs a Tailscale login.
  • Keep ROOT_FILES and PAM_FILES in 60-security.sh up to date when CoreDesktop installs something new that root runs.
  • Check on a real machine which ports WinBoat's Windows container publishes, and on which addresses (not checked yet). The Docker fix keeps the LAN out of any it publishes on all addresses.