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:
+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.
|
||||
|
||||
Reference in New Issue
Block a user