Harden signed feeds and RelWithDebInfo releases
Modular container CI / release-build (push) Has been cancelled

This commit is contained in:
faumaray committed 2026-08-01 18:02:55 +03:00
1 parent 5b2d27a1e8
commit 8ac39621fd
21 files changed
+243 -40

No files matched your search

+7 -3
View File
@@ -14,7 +14,9 @@ mkdir -p "$stage/bin" "$stage/lib"
install -m 0755 /bin/true "$stage/bin/echoiond"
install -m 0755 /bin/true "$stage/bin/echoion-updater"
install -m 0644 /bin/true "$stage/lib/Echoion.ts"
printf '%s\n' '{"schemaVersion":2,"version":"1.2.3"}' >"$stage/manifest.json"
printf '%s\n' \
'{"schemaVersion":2,"version":"1.2.3","buildType":"RelWithDebInfo"}' \
>"$stage/manifest.json"
cat >"$stage/install.sh" <<'INSTALL'
#!/bin/sh
set -eu
@@ -73,6 +75,7 @@ artifact = Path(sys.argv[2])
manifest = Path(sys.argv[3])
release = payload["releases"][0]
assert payload["schemaVersion"] == 1
assert payload["releases"][0]["buildType"] == "RelWithDebInfo"
assert payload["feedId"] == "echoion-test"
assert payload["sequence"] == 42
assert release["component"] == "runtime"
@@ -147,9 +150,10 @@ envelope = json.loads(Path(sys.argv[2]).read_text(encoding="utf-8"))
def decode(value: str) -> bytes:
return base64.urlsafe_b64decode(value + "=" * (-len(value) % 4))
assert envelope["schemaVersion"] == 1
assert envelope["schemaVersion"] == 3
assert envelope["keyId"] == "test-key"
assert decode(envelope["payload"]) == payload
assert envelope["document"] == json.loads(payload)
assert decode(envelope["signedPayload"]) == payload
Path(sys.argv[3]).write_bytes(decode(envelope["signature"]))
PY
openssl pkey -in "$private_key" -pubout -out "$public_key" >/dev/null 2>&1
+12 -8
View File
@@ -84,17 +84,18 @@ install -m 0755 "$source_root/scripts/validate-release-manifest.py" \
ln -s Echoion.ts "$bundle/lib/Echoion-current.ts"
python3 "$source_root/scripts/generate-release-manifest.py" \
--root "$bundle" --version 1.2.3
--root "$bundle" --version 1.2.3 --build-type RelWithDebInfo
cp "$bundle/manifest.json" "$temporary/manifest.first.json"
python3 "$source_root/scripts/generate-release-manifest.py" \
--root "$bundle" --version 1.2.3
--root "$bundle" --version 1.2.3 --build-type RelWithDebInfo
cmp "$temporary/manifest.first.json" "$bundle/manifest.json"
unsafe_file_mode="$temporary/unsafe-file-mode"
cp -a "$bundle" "$unsafe_file_mode"
chmod 0666 "$unsafe_file_mode/lib/Echoion.ts"
if python3 "$source_root/scripts/generate-release-manifest.py" \
--root "$unsafe_file_mode" --version 1.2.3 >/dev/null 2>&1; then
--root "$unsafe_file_mode" --version 1.2.3 \
--build-type RelWithDebInfo >/dev/null 2>&1; then
echo "world-writable payload file unexpectedly entered manifest" >&2
exit 1
fi
@@ -103,7 +104,8 @@ unsafe_directory_mode="$temporary/unsafe-directory-mode"
cp -a "$bundle" "$unsafe_directory_mode"
chmod 0777 "$unsafe_directory_mode/lib"
if python3 "$source_root/scripts/generate-release-manifest.py" \
--root "$unsafe_directory_mode" --version 1.2.3 >/dev/null 2>&1; then
--root "$unsafe_directory_mode" --version 1.2.3 \
--build-type RelWithDebInfo >/dev/null 2>&1; then
echo "world-writable payload directory unexpectedly entered manifest" >&2
exit 1
fi
@@ -116,6 +118,7 @@ with open(sys.argv[1], encoding="utf-8") as stream:
manifest = json.load(stream)
assert manifest["schemaVersion"] == 2
assert manifest["version"] == "1.2.3"
assert manifest["buildType"] == "RelWithDebInfo"
assert manifest["executable"] == "bin/echoiond"
assert manifest["updater"] == "bin/echoion-updater"
assert manifest["core"] == "lib/Echoion.ts"
@@ -178,7 +181,7 @@ PY
tampered="$temporary/tampered"
cp -a "$bundle" "$tampered"
python3 "$source_root/scripts/generate-release-manifest.py" \
--root "$tampered" --version 1.2.4
--root "$tampered" --version 1.2.4 --build-type RelWithDebInfo
printf '%s\n' tampered >>"$tampered/lib/Echoion.ts"
if bash "$source_root/scripts/stage-release.sh" \
"$release_root" 1.2.4 "$tampered" >/dev/null 2>&1; then
@@ -189,7 +192,7 @@ fi
rogue="$temporary/rogue"
cp -a "$bundle" "$rogue"
python3 "$source_root/scripts/generate-release-manifest.py" \
--root "$rogue" --version 1.2.6
--root "$rogue" --version 1.2.6 --build-type RelWithDebInfo
printf '%s\n' rogue >"$rogue/lib/rogue.so"
if bash "$source_root/scripts/stage-release.sh" \
"$release_root" 1.2.6 "$rogue" >/dev/null 2>&1; then
@@ -201,7 +204,7 @@ fi
outside_entry="$temporary/outside-entry"
cp -a "$bundle" "$outside_entry"
python3 "$source_root/scripts/generate-release-manifest.py" \
--root "$outside_entry" --version 1.2.8
--root "$outside_entry" --version 1.2.8 --build-type RelWithDebInfo
printf '%s\n' outside >"$outside_entry/outside.dat"
python3 - "$outside_entry/manifest.json" "$outside_entry/outside.dat" <<'PY'
import hashlib
@@ -255,7 +258,8 @@ cp -a "$bundle" "$unsafe"
rm "$unsafe/lib/Echoion-current.ts"
ln -s ../bin/echoiond "$unsafe/lib/Echoion-current.ts"
if python3 "$source_root/scripts/generate-release-manifest.py" \
--root "$unsafe" --version 1.2.5 >/dev/null 2>&1; then
--root "$unsafe" --version 1.2.5 \
--build-type RelWithDebInfo >/dev/null 2>&1; then
echo "unsafe symlink unexpectedly entered manifest" >&2
exit 1
fi
@@ -4,9 +4,11 @@
from __future__ import annotations
import base64
import importlib.util
import json
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
@@ -86,6 +88,36 @@ class IndependentComponentReleaseTests(unittest.TestCase):
def tearDown(self) -> None:
self.temporary.cleanup()
def test_component_elf_requires_debug_information(self) -> None:
compiler = shutil.which("cc")
if compiler is None:
self.skipTest("C compiler is unavailable")
specification = importlib.util.spec_from_file_location(
"echoion_package_component", PACKAGE
)
self.assertIsNotNone(specification)
self.assertIsNotNone(specification.loader)
module = importlib.util.module_from_spec(specification)
specification.loader.exec_module(module)
package_root = self.root / "elf-stage"
package_root.mkdir()
source = self.root / "fixture.c"
executable = package_root / "fixture"
source.write_text("int main(void) { return 0; }\n")
subprocess.run(
[compiler, "-O2", "-g0", str(source), "-o", str(executable)],
check=True,
)
with self.assertRaisesRegex(SystemExit, "has no debug information"):
module.require_debug_information(package_root)
subprocess.run(
[compiler, "-O2", "-g", str(source), "-o", str(executable)],
check=True,
)
module.require_debug_information(package_root)
def package(self, component: str, package_id: str, version: str) -> tuple[Path, Path]:
package_root = self.root / f"stage-{component}"
package_root.mkdir()
@@ -111,6 +143,8 @@ class IndependentComponentReleaseTests(unittest.TestCase):
"git-sha1:" + ("3" if component == "EchoionApi" else "4") * 40,
"--abi-hash",
"sha256:" + ("5" if component == "EchoionApi" else "6") * 64,
"--build-type",
"RelWithDebInfo",
],
check=False,
text=True,
@@ -169,9 +203,17 @@ class IndependentComponentReleaseTests(unittest.TestCase):
@staticmethod
def payload(path: Path) -> dict[str, object]:
envelope = json.loads(path.read_text())
encoded = envelope["payload"]
if envelope["schemaVersion"] == 3:
encoded = envelope["signedPayload"]
document = envelope["document"]
else:
encoded = envelope["payload"]
document = None
raw = base64.urlsafe_b64decode(encoded + "=" * (-len(encoded) % 4))
return json.loads(raw)
payload = json.loads(raw)
if document is not None and document != payload:
raise AssertionError("readable document differs from signed payload")
return payload
def test_single_component_publication_merges_catalog(self) -> None:
api_manifest, api_archive = self.package(
@@ -206,6 +248,7 @@ class IndependentComponentReleaseTests(unittest.TestCase):
):
self.assertNotIn(private_field, api)
self.assertEqual(api["productCompatibility"], ">=2.0.0 <3.0.0")
self.assertEqual(api["buildType"], "RelWithDebInfo")
self.assertEqual(
api["artifact"]["url"],
"https://downloads.example.test/components/"
+3
View File
@@ -76,6 +76,8 @@ class PackageComponentsTests(unittest.TestCase):
"100",
"--product-version",
"2.0.0",
"--build-type",
"RelWithDebInfo",
],
check=False,
text=True,
@@ -90,6 +92,7 @@ class PackageComponentsTests(unittest.TestCase):
)
manifest = json.loads(manifest_path.read_text())
self.assertEqual(manifest["componentId"], "EchoionApi")
self.assertEqual(manifest["buildType"], "RelWithDebInfo")
self.assertTrue(
(
output / "echoion-api-2.0.0-linux-x86_64.tar.zst"
+35 -3
View File
@@ -109,6 +109,7 @@ class ComponentFeedTests(unittest.TestCase):
"dependencies": definition["dependencies"],
"platform": "linux",
"architecture": "x86_64",
"buildType": "RelWithDebInfo",
"toolchainContract": "linux-x86_64-glibc-2.35-cxx26",
}
(self.artifacts / f"{stem}.manifest.json").write_text(
@@ -156,14 +157,29 @@ class ComponentFeedTests(unittest.TestCase):
@staticmethod
def payload(path: Path) -> dict[str, object]:
envelope = json.loads(path.read_text())
encoded = envelope["payload"]
if envelope["schemaVersion"] == 3:
encoded = envelope["signedPayload"]
document = envelope["document"]
else:
encoded = envelope["payload"]
document = None
decoded = base64.urlsafe_b64decode(encoded + "=" * (-len(encoded) % 4))
return json.loads(decoded)
payload = json.loads(decoded)
if document is not None and document != payload:
raise AssertionError("readable document differs from signed payload")
return payload
def test_stable_layout_and_catalog(self) -> None:
self.write_packages("stable", 100)
self.publish("stable", 100)
catalog = self.payload(self.feeds / "feeds/stable/catalog.json")
catalog_path = self.feeds / "feeds/stable/catalog.json"
catalog_text = catalog_path.read_text()
catalog_envelope = json.loads(catalog_text)
self.assertTrue(catalog_text.startswith("{\n"))
self.assertIn('\n "document": {\n', catalog_text)
self.assertEqual(catalog_envelope["schemaVersion"], 3)
self.assertEqual(catalog_envelope["keyId"], "test-key")
catalog = self.payload(catalog_path)
self.assertEqual(len(catalog["components"]), 2)
self.assertTrue(
(self.feeds / "feeds/stable/echoion-api/2.0.0.json").is_file()
@@ -188,6 +204,7 @@ class ComponentFeedTests(unittest.TestCase):
self.assertEqual(release["artifactIdentity"], "echoion-api-2.0.0-linux-x86_64")
self.assertEqual(release["platform"], "linux")
self.assertEqual(release["architecture"], "x86_64")
self.assertEqual(release["buildType"], "RelWithDebInfo")
self.assertEqual(
release["toolchainContract"],
"linux-x86_64-glibc-2.35-cxx26",
@@ -204,6 +221,21 @@ class ComponentFeedTests(unittest.TestCase):
self.assertNotEqual(conflict.returncode, 0)
self.assertIn("unchanged source SHA", conflict.stderr)
def test_rejects_tampered_readable_document(self) -> None:
self.write_packages("stable", 100)
self.publish("stable", 100)
release_path = (
self.feeds / "feeds/stable/echoion-api/2.0.0.json"
)
envelope = json.loads(release_path.read_text())
envelope["document"]["sequence"] = 101
release_path.write_text(json.dumps(envelope))
rejected = self.publish("stable", 101, expect_success=False)
self.assertNotEqual(rejected.returncode, 0)
self.assertIn(
"readable document differs from signed payload", rejected.stderr
)
def test_beta_does_not_advance_stable_state(self) -> None:
self.write_packages("stable", 100)
self.publish("stable", 100)