#!/usr/bin/env python3 """SECURITY.md says what the cockpit's user can reach as root, as the code has it. It said the cockpit reached root through "exactly one surface", its sudoers lines, while install.sh requires the user to be in the docker group (root-equivalent by itself) and two of those lines install a file the user writes into /etc/systemd/system, next to daemon-reload and restart: whoever writes it runs what it says as root (found in review, 2026-09-24). These tie the page to the two facts, so it cannot drift back.""" import pathlib import re import unittest REPO = pathlib.Path(__file__).resolve().parents[1] SECURITY = (REPO / "SECURITY.md").read_text() FLAT = re.sub(r"\s+", " ", SECURITY) class TheCockpitsRootIsStatedAsItIs(unittest.TestCase): def test_no_single_surface_claim(self): self.assertNotIn("reaches root through exactly one", FLAT) def test_the_docker_group_is_named_while_install_sh_requires_it(self): # install.sh reaches docker through lanes.sh (docker_grant) since v1.37.2: the check # reads both, or it would have stopped checking without a word when the line moved code = (REPO / "install.sh").read_text() + (REPO / "lanes.sh").read_text() self.assertIn("docker_grant", (REPO / "install.sh").read_text()) self.assertIn("usermod -aG docker", code) self.assertIn("`docker` group", FLAT) self.assertIn("root-equivalent", FLAT) def test_the_page_says_the_installer_adds_the_account(self): # it adds the account itself on a box whose first-boot setup left it out (v1.37.2) if "sudo usermod -aG docker" in (REPO / "lanes.sh").read_text(): self.assertIn("adds it to that group when it is not in it", FLAT) self.assertIn("before it runs sudo", FLAT) # and not a promise of a password prompt that a sudo ticket skips (found in review) self.assertIn("does not ask while an earlier ticket is still valid", FLAT) def test_the_staged_unit_install_is_named_while_the_allowlist_has_it(self): sudoers = (REPO / "dashboard" / "sudoers-cockpit.template").read_text() if re.search(r"/usr/bin/install .*switch-stage /etc/systemd/system/", sudoers): self.assertIn("switch-stage", FLAT) self.assertIn("runs what it says as root", FLAT) class WhatLeavesTheBoxIsStatedAsItIs(unittest.TestCase): """Three sentences of SECURITY.md were false: the update check ran "at most once every six hours" (a failure retries after a minute), downloads went only to Hugging Face and the image registry (GitHub too), and every pinned byte was hash-verified with nothing said of the image lane's unpinned pip dependencies (found in review, 2026-09-24).""" def test_github_is_named_while_install_sh_downloads_from_it(self): if "https://github.com/anomalyco/opencode/releases" in (REPO / "install.sh").read_text(): self.assertIn("the pinned opencode release", FLAT) def test_the_retry_schedule_is_the_code_s(self): ck = (REPO / "dashboard" / "cockpit.py").read_text() if "min(60.0 * 2 ** max(0, _RELEASE[\"fails\"] - 1), 21600.0)" in ck: self.assertNotIn("at most once every six hours", FLAT) self.assertIn("retried after one minute, then two, four, eight", FLAT) def test_the_image_lanes_unpinned_bytes_are_named(self): img = (REPO / "install-image.sh").read_text() if "--require-hashes" not in img: self.assertIn("pip resolves the wheel's dependency tree from PyPI", FLAT) if __name__ == "__main__": unittest.main(verbosity=2)