Capture the updater from the verified source archive before unprivileged build handoff. Exclude build-supplied updater files from copied artifacts and atomically install the trusted command in the root-owned release. Cover source and output replacement with an adversarial publishing regression. Refs #21
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
# Proxmox deployment tools
|
||||
Host creates only a new explicitly selected CT. Updates run inside the CT with finaltoken-update and require this installer's marker. Use the operator's existing reverse proxy; new installs expose private HTTP :5187 and never install a proxy. Legacy migration may change only the known listener and disable finaltoken-proxy.service; preserve keys/data and unrelated services. Never destroy a CT, alter host package repositories or read provider credentials. Builds run inside the CT as an isolated user. Keep commands as argv lists. Test with `python -B tools/proxmox/test_installer.py` and `python -B tools/proxmox/test_update.py`.
|
||||
Host creates only a new explicitly selected CT. Updates run inside the CT with finaltoken-update and require this installer's marker. Use the operator's existing reverse proxy; new installs expose private HTTP :5187 and never install a proxy. Legacy migration may change only the known listener and disable finaltoken-proxy.service; preserve keys/data and unrelated services. Never destroy a CT, alter host package repositories or read provider credentials. Builds run inside the CT as an isolated user; root updater code must come directly from the verified archive, never build-writable source/output. Keep commands as argv lists. Test with `python -B tools/proxmox/test_installer.py` and `python -B tools/proxmox/test_update.py`.
|
||||
|
||||
+13
-3
@@ -200,6 +200,17 @@ def configure(meta, enrollment_key=None):
|
||||
|
||||
|
||||
def build(archive, meta):
|
||||
# The updater runs as root: capture it from the verified, root-owned archive,
|
||||
# never from source or output writable by the unprivileged compiler.
|
||||
with tarfile.open(archive, "r:gz") as bundle:
|
||||
try:
|
||||
member = bundle.getmember("tools/lxc_update.py")
|
||||
except KeyError:
|
||||
raise ValueError("Source archive has no updater script") from None
|
||||
if not member.isfile() or member.size > 16 * 1024 * 1024:
|
||||
raise ValueError("Source archive has an invalid updater script")
|
||||
with bundle.extractfile(member) as stream:
|
||||
trusted_updater = stream.read().decode("utf-8")
|
||||
entry = user("finaltoken-build", BUILD)
|
||||
temporary = Path(tempfile.mkdtemp(prefix="build-", dir=BUILD))
|
||||
try:
|
||||
@@ -217,12 +228,11 @@ def build(archive, meta):
|
||||
if meta["role"] != "worker" and not (release / "web/wwwroot/index.html").is_file():
|
||||
shutil.copytree(source / "src/FinalToken.Web/wwwroot", release / "web/wwwroot", dirs_exist_ok=True)
|
||||
shutil.copy2(source / "LICENSE", release / "LICENSE")
|
||||
shutil.copy2(source / "tools/lxc_update.py", release / "finaltoken-update")
|
||||
destination = APP / "releases" / (meta["sourceSha256"][:16] + "-" + uuid.uuid4().hex[:8])
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
APP.chmod(0o755)
|
||||
destination.parent.chmod(0o755)
|
||||
shutil.copytree(release, destination)
|
||||
shutil.copytree(release, destination, ignore=shutil.ignore_patterns("finaltoken-update"))
|
||||
destination.chmod(0o755)
|
||||
for path in destination.rglob("*"):
|
||||
path.chmod(0o755 if path.is_dir() else 0o644)
|
||||
@@ -236,7 +246,7 @@ def build(archive, meta):
|
||||
if header[:4] != b"\x7fELF" or header[18:20] != b"\x3e\x00":
|
||||
raise ValueError("Published executable is not a Linux x64 ELF binary")
|
||||
executable.chmod(0o755)
|
||||
(destination / "finaltoken-update").chmod(0o755)
|
||||
atomic(destination / "finaltoken-update", trusted_updater, 0o755)
|
||||
return destination
|
||||
finally:
|
||||
# Only this invocation's fresh build directory, never profiles, state or previous releases.
|
||||
|
||||
@@ -413,6 +413,32 @@ class GuestTests(unittest.TestCase):
|
||||
release = guest.build(archive, {"role": "worker", "sourceSha256": "0" * 64})
|
||||
self.assertEqual(license_text, (release / "LICENSE").read_bytes())
|
||||
|
||||
def test_build_user_cannot_replace_the_root_updater(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
trusted = b"#!/usr/bin/env python3\n# trusted archive updater\n"
|
||||
malicious = b"#!/usr/bin/env python3\n# build-user replacement\n"
|
||||
archive = root / "source.tgz"
|
||||
with tarfile.open(archive, "w:gz") as stream:
|
||||
for name, content in (("LICENSE", b"fixture"), ("tools/lxc_update.py", trusted)):
|
||||
item = tarfile.TarInfo(name)
|
||||
item.size = len(content)
|
||||
stream.addfile(item, io.BytesIO(content))
|
||||
home = root / "build"
|
||||
home.mkdir()
|
||||
def compromised_publish(name, home, command, **kwargs):
|
||||
source = Path(kwargs["cwd"])
|
||||
(source / "tools/lxc_update.py").write_bytes(malicious)
|
||||
output = Path(command[command.index("-o") + 1])
|
||||
output.mkdir(parents=True)
|
||||
(output / "finaltoken-worker").write_bytes(b"\x7fELF" + b"\0" * 14 + b"\x3e\x00")
|
||||
(output.parent / "finaltoken-update").write_bytes(malicious)
|
||||
with patch.object(guest, "APP", root / "app"), patch.object(guest, "BUILD", home), \
|
||||
patch.object(guest, "user", return_value=types.SimpleNamespace(pw_uid=1000, pw_gid=1000)), \
|
||||
patch.object(guest.os, "chown", create=True), patch.object(guest, "as_user", side_effect=compromised_publish):
|
||||
release = guest.build(archive, {"role": "worker", "sourceSha256": "0" * 64})
|
||||
self.assertEqual(trusted, (release / "finaltoken-update").read_bytes())
|
||||
|
||||
def test_atomic_configuration_is_never_replaced_on_update(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
target = Path(tmp) / "config.json"
|
||||
|
||||
Reference in New Issue
Block a user