Harden signed feeds and RelWithDebInfo releases
Modular container CI / release-build (push) Has been cancelled
Modular container CI / release-build (push) Has been cancelled
This commit is contained in:
21 files changed
+243
-40
No files matched your search
+10
-1
@@ -154,7 +154,16 @@ https://<gitea>/<owner>/<repo>/raw/branch/release-feed/feeds/stable/catalog.json
|
||||
The catalog resolves immutable component documents under
|
||||
`feeds/<channel>/<component>/<version>.json` and plugin documents under
|
||||
`feeds/<channel>/plugins/<plugin-id>/<version>.json`. The embedded updater
|
||||
trust configuration is represented by
|
||||
accepts legacy signed envelopes but new component and product publications use
|
||||
envelope schema 3:
|
||||
the signed document is rendered as indented JSON in `document`, while
|
||||
`signedPayload` preserves the exact bytes covered by the Ed25519 signature.
|
||||
Verification rejects any semantic difference between those two representations.
|
||||
Component and product manifests, plus their corresponding
|
||||
feeds, attest `buildType: "RelWithDebInfo"`; release tooling rejects any other
|
||||
build type.
|
||||
|
||||
The embedded updater trust configuration is represented by
|
||||
`.gitea/release-keys/official-update-keys.json`. `scripts/release.sh` validates and
|
||||
embeds that JSON automatically. Release workflows also pass the HTTPS
|
||||
channel catalog through `--official-update-feed-url`, so a fresh installation
|
||||
|
||||
+2
-2
@@ -11,7 +11,7 @@ include(cmake/DependencyLock.cmake)
|
||||
set(ECHOION_PRODUCT_VERSION "${PROJECT_VERSION}")
|
||||
set(ECHOION_COMPONENT_VERSION "${PROJECT_VERSION}")
|
||||
|
||||
# Default to a Release build when the developer/CI did not pick a config.
|
||||
# Default to a RelWithDebInfo build when the developer/CI did not pick a config.
|
||||
# Without this, single-config generators leave CMAKE_BUILD_TYPE empty and GCC
|
||||
# falls back to -O0, so "production" builds shipped unoptimised. Set this before
|
||||
# any CPMAddPackage() below so fetched dependencies (Void, Boost, quickjs) are
|
||||
@@ -21,7 +21,7 @@ if(NOT _isMultiConfig AND NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Build type" FORCE)
|
||||
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
|
||||
Debug Release RelWithDebInfo MinSizeRel)
|
||||
message(STATUS "No CMAKE_BUILD_TYPE set; defaulting to Release")
|
||||
message(STATUS "No CMAKE_BUILD_TYPE set; defaulting to RelWithDebInfo")
|
||||
endif()
|
||||
|
||||
# Use ccache (or sccache) as a compiler launcher when available to speed up
|
||||
|
||||
+2
-2
@@ -11,10 +11,10 @@
|
||||
"displayName": "Linux dynamic runtime release",
|
||||
"description": "Bot, Core, web dashboard, tests, and a runtime-only install component",
|
||||
"generator": "Ninja",
|
||||
"binaryDir": "${sourceDir}/build-release",
|
||||
"binaryDir": "${sourceDir}/build-relwithdebinfo",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
|
||||
"CMAKE_INSTALL_PREFIX": "${sourceDir}/build-release/stage",
|
||||
"CMAKE_INSTALL_PREFIX": "${sourceDir}/build-relwithdebinfo/stage",
|
||||
"BUILD_SHARED_LIBS": "ON",
|
||||
"ECHOION_STATIC_LINK": "OFF",
|
||||
"ECHOION_INSTALL_RUNTIME_BUNDLE": "ON",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Immutable dependency revisions used by clean and release builds. Local
|
||||
# development may still override either package with CPM_<name>_SOURCE.
|
||||
set(ECHOION_VOID_REVISION
|
||||
"4418374de7509c5b764737a78926ee2621452a05"
|
||||
"cb58236538d791d5605fb97e6bc79e0543b84b72"
|
||||
CACHE STRING "VoidLibrary commit used by Echoion")
|
||||
set(ECHOION_VOID_TEAMSPEAK_REVISION
|
||||
"c0cd95187d4ce7e28daa48a753e4e3bd38d662b6"
|
||||
|
||||
@@ -20,10 +20,10 @@
|
||||
},
|
||||
"EchoionCore": {
|
||||
"repository": "Void/EchoionCore",
|
||||
"revision": "16d9a667eb0174002cf6957e1918c8a3a5c5a257",
|
||||
"revision": "c2ec314eb9cc3b06f7dae7c01cd85be8a22bbfc5",
|
||||
"componentVersion": "2.0.0",
|
||||
"abiHash": "sha256:9cb668e2a502dcfe02d145ed63635d63619732d77ff5749685834382705e8d21",
|
||||
"sourceTreeHash": "git-sha1:a34c4822215e0f9d1bf50540c4af3eb79ea8cf98",
|
||||
"sourceTreeHash": "git-sha1:7887ff0ee0be9a8b4f074eae025e758d0b318adf",
|
||||
"artifactIdentity": "echoion-core-2.0.0-linux-x86_64"
|
||||
},
|
||||
"EchoionWeb": {
|
||||
|
||||
@@ -107,7 +107,9 @@ def collect_entries(root: Path) -> list[dict[str, object]]:
|
||||
return entries
|
||||
|
||||
|
||||
def write_manifest(root: Path, version: str, output: Path) -> None:
|
||||
def write_manifest(
|
||||
root: Path, version: str, build_type: str, output: Path
|
||||
) -> None:
|
||||
entries = collect_entries(root)
|
||||
regular_files = {
|
||||
str(entry["path"]) for entry in entries if entry["type"] == "file"
|
||||
@@ -141,6 +143,7 @@ def write_manifest(root: Path, version: str, output: Path) -> None:
|
||||
manifest = {
|
||||
"schemaVersion": 2,
|
||||
"version": version,
|
||||
"buildType": build_type,
|
||||
"executable": executable,
|
||||
"updater": updater,
|
||||
"core": core,
|
||||
@@ -168,6 +171,9 @@ def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--root", required=True, type=Path)
|
||||
parser.add_argument("--version", required=True)
|
||||
parser.add_argument(
|
||||
"--build-type", choices=("RelWithDebInfo",), required=True
|
||||
)
|
||||
parser.add_argument("--output", type=Path)
|
||||
arguments = parser.parse_args()
|
||||
|
||||
@@ -175,7 +181,7 @@ def main() -> int:
|
||||
parser.error("version must contain only letters, digits, dot, underscore, or dash")
|
||||
root = arguments.root.resolve(strict=True)
|
||||
output = arguments.output or root / "manifest.json"
|
||||
write_manifest(root, arguments.version, output)
|
||||
write_manifest(root, arguments.version, arguments.build_type, output)
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
@@ -217,8 +217,11 @@ def main() -> None:
|
||||
not isinstance(manifest, dict)
|
||||
or manifest.get("schemaVersion") != 2
|
||||
or manifest.get("version") != arguments.version
|
||||
or manifest.get("buildType") != "RelWithDebInfo"
|
||||
):
|
||||
fail("release manifest schema/version does not match the feed")
|
||||
fail(
|
||||
"release manifest schema/version/build type does not match the feed"
|
||||
)
|
||||
|
||||
source_epoch = os.environ.get("SOURCE_DATE_EPOCH")
|
||||
if arguments.generated_at:
|
||||
@@ -263,6 +266,7 @@ def main() -> None:
|
||||
}
|
||||
if manifest_path is not None:
|
||||
release["releaseManifestSha256"] = digest(manifest_path)
|
||||
release["buildType"] = manifest["buildType"]
|
||||
|
||||
payload_document = {
|
||||
"schemaVersion": 1,
|
||||
@@ -306,9 +310,10 @@ def main() -> None:
|
||||
fail("output envelope would overwrite an input or payload file")
|
||||
signature = sign_payload(output_payload, private_key)
|
||||
envelope = {
|
||||
"schemaVersion": 1,
|
||||
"schemaVersion": 3,
|
||||
"keyId": arguments.key_id,
|
||||
"payload": urlsafe(payload),
|
||||
"document": payload_document,
|
||||
"signedPayload": urlsafe(payload),
|
||||
"signature": urlsafe(signature),
|
||||
}
|
||||
atomic_write(
|
||||
|
||||
@@ -10,6 +10,7 @@ import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
from types import ModuleType
|
||||
from typing import Any, NoReturn
|
||||
@@ -23,6 +24,7 @@ SEMVER = re.compile(
|
||||
r"(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$"
|
||||
)
|
||||
TOKEN = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._-]{0,255}$")
|
||||
RELEASE_BUILD_TYPE = "RelWithDebInfo"
|
||||
|
||||
|
||||
def fail(message: str) -> NoReturn:
|
||||
@@ -51,6 +53,38 @@ def load_json_object(path: Path, label: str) -> dict[str, Any]:
|
||||
return value
|
||||
|
||||
|
||||
def require_debug_information(root: Path) -> None:
|
||||
readelf = shutil.which("readelf")
|
||||
if readelf is None:
|
||||
fail("readelf is required to verify RelWithDebInfo artifacts")
|
||||
for path in sorted(root.rglob("*")):
|
||||
if path.is_symlink() or not path.is_file():
|
||||
continue
|
||||
try:
|
||||
with path.open("rb") as stream:
|
||||
is_elf = stream.read(4) == b"\x7fELF"
|
||||
except OSError as error:
|
||||
fail(f"cannot inspect {path}: {error}")
|
||||
if not is_elf:
|
||||
continue
|
||||
completed = subprocess.run(
|
||||
[readelf, "-SW", os.fspath(path)],
|
||||
check=False,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
env={**os.environ, "LC_ALL": "C"},
|
||||
)
|
||||
if completed.returncode != 0:
|
||||
message = completed.stderr.strip() or completed.stdout.strip()
|
||||
fail(f"readelf failed for {path.relative_to(root)}: {message}")
|
||||
if re.search(r"\]\s+\.(?:z)?debug_info\s", completed.stdout) is None:
|
||||
fail(
|
||||
f"ELF {path.relative_to(root)} has no debug information; "
|
||||
f"expected a {RELEASE_BUILD_TYPE} artifact"
|
||||
)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--registry", type=Path, default=Path("components.json"))
|
||||
@@ -65,6 +99,9 @@ def main() -> None:
|
||||
parser.add_argument("--source-tree-hash", required=True)
|
||||
parser.add_argument("--abi-hash")
|
||||
parser.add_argument("--build-dependencies", type=Path)
|
||||
parser.add_argument(
|
||||
"--build-type", choices=(RELEASE_BUILD_TYPE,), required=True
|
||||
)
|
||||
parser.add_argument("--platform", default="linux")
|
||||
parser.add_argument("--architecture", default="x86_64")
|
||||
parser.add_argument(
|
||||
@@ -122,6 +159,7 @@ def main() -> None:
|
||||
package_root = arguments.package_root.resolve(strict=True)
|
||||
if package_root.is_symlink() or not package_root.is_dir():
|
||||
fail("--package-root must be a real directory")
|
||||
require_debug_information(package_root)
|
||||
output = arguments.output.resolve()
|
||||
output.mkdir(parents=True, exist_ok=True)
|
||||
epoch_value = os.environ.get("SOURCE_DATE_EPOCH", "0")
|
||||
@@ -152,6 +190,7 @@ def main() -> None:
|
||||
"activation": definition["activation"],
|
||||
"dependencies": definition["dependencies"],
|
||||
"buildDependencies": build_dependencies,
|
||||
"buildType": arguments.build_type,
|
||||
"platform": arguments.platform,
|
||||
"architecture": arguments.architecture,
|
||||
"toolchainContract": arguments.toolchain_contract,
|
||||
|
||||
@@ -17,6 +17,7 @@ from typing import Any, NoReturn
|
||||
|
||||
|
||||
CHANNELS = {"stable", "beta", "nightly"}
|
||||
RELEASE_BUILD_TYPE = "RelWithDebInfo"
|
||||
SEMVER = re.compile(
|
||||
r"^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)"
|
||||
r"(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$"
|
||||
@@ -180,6 +181,9 @@ def main() -> None:
|
||||
parser.add_argument("--channel", choices=sorted(CHANNELS), default="stable")
|
||||
parser.add_argument("--sequence", type=int, required=True)
|
||||
parser.add_argument("--product-version", required=True)
|
||||
parser.add_argument(
|
||||
"--build-type", choices=(RELEASE_BUILD_TYPE,), required=True
|
||||
)
|
||||
parser.add_argument(
|
||||
"--toolchain-contract",
|
||||
default="linux-x86_64-glibc-2.35-cxx26",
|
||||
@@ -261,6 +265,7 @@ def main() -> None:
|
||||
"abiHash": locked["abiHash"],
|
||||
"activation": definition["activation"],
|
||||
"dependencies": definition["dependencies"],
|
||||
"buildType": arguments.build_type,
|
||||
"platform": "linux",
|
||||
"architecture": "x86_64",
|
||||
"toolchainContract": arguments.toolchain_contract,
|
||||
|
||||
@@ -45,6 +45,19 @@ def canonical(document: Any) -> bytes:
|
||||
)
|
||||
|
||||
|
||||
def readable(document: Any) -> bytes:
|
||||
return (
|
||||
json.dumps(
|
||||
document,
|
||||
ensure_ascii=False,
|
||||
allow_nan=False,
|
||||
sort_keys=True,
|
||||
indent=2,
|
||||
).encode("utf-8")
|
||||
+ b"\n"
|
||||
)
|
||||
|
||||
|
||||
def load_object(path: Path, label: str) -> dict[str, Any]:
|
||||
try:
|
||||
document = json.loads(path.read_text(encoding="utf-8"))
|
||||
@@ -154,11 +167,12 @@ class Signer:
|
||||
signature = signature_path.read_bytes()
|
||||
if len(signature) != 64:
|
||||
fail("OpenSSL returned a non-Ed25519 signature")
|
||||
return canonical(
|
||||
return readable(
|
||||
{
|
||||
"schemaVersion": 2,
|
||||
"schemaVersion": 3,
|
||||
"keyId": self.key_id,
|
||||
"payload": base64.urlsafe_b64encode(payload_bytes)
|
||||
"document": payload,
|
||||
"signedPayload": base64.urlsafe_b64encode(payload_bytes)
|
||||
.rstrip(b"=")
|
||||
.decode("ascii"),
|
||||
"signature": base64.urlsafe_b64encode(signature)
|
||||
@@ -170,8 +184,19 @@ class Signer:
|
||||
def verify(self, envelope_bytes: bytes, label: str) -> dict[str, Any]:
|
||||
try:
|
||||
envelope = json.loads(envelope_bytes)
|
||||
schema = envelope.get("schemaVersion")
|
||||
if schema == 2:
|
||||
encoded_payload = envelope["payload"]
|
||||
displayed_document = None
|
||||
elif schema == 3:
|
||||
encoded_payload = envelope["signedPayload"]
|
||||
displayed_document = envelope["document"]
|
||||
if not isinstance(displayed_document, dict):
|
||||
raise TypeError("document is not an object")
|
||||
else:
|
||||
raise ValueError("unsupported envelope schema")
|
||||
payload = base64.urlsafe_b64decode(
|
||||
str(envelope["payload"]) + "=" * (-len(envelope["payload"]) % 4)
|
||||
str(encoded_payload) + "=" * (-len(encoded_payload) % 4)
|
||||
)
|
||||
signature = base64.urlsafe_b64decode(
|
||||
str(envelope["signature"])
|
||||
@@ -180,11 +205,12 @@ class Signer:
|
||||
except (KeyError, ValueError, TypeError, json.JSONDecodeError) as error:
|
||||
fail(f"invalid existing {label}: {error}")
|
||||
if (
|
||||
envelope.get("schemaVersion") != 2
|
||||
or envelope.get("keyId") != self.key_id
|
||||
envelope.get("keyId") != self.key_id
|
||||
or len(signature) != 64
|
||||
):
|
||||
fail(f"existing {label} has the wrong schema, key, or signature")
|
||||
if displayed_document is not None and canonical(displayed_document) != payload:
|
||||
fail(f"existing {label} readable document differs from signed payload")
|
||||
payload_path = self.directory / "verify-payload.json"
|
||||
signature_path = self.directory / "verify-signature.bin"
|
||||
payload_path.write_bytes(payload)
|
||||
@@ -335,6 +361,7 @@ def load_packages(
|
||||
],
|
||||
"platform": "linux",
|
||||
"architecture": "x86_64",
|
||||
"buildType": "RelWithDebInfo",
|
||||
}
|
||||
for field, value in expected.items():
|
||||
if manifest.get(field) != value:
|
||||
@@ -520,6 +547,7 @@ def main() -> None:
|
||||
"activation": definition["activation"],
|
||||
"platform": manifest["platform"],
|
||||
"architecture": manifest["architecture"],
|
||||
"buildType": manifest["buildType"],
|
||||
"toolchainContract": manifest["toolchainContract"],
|
||||
"dependencies": definition["dependencies"],
|
||||
"artifact": artifact,
|
||||
@@ -541,6 +569,7 @@ def main() -> None:
|
||||
"activation",
|
||||
"platform",
|
||||
"architecture",
|
||||
"buildType",
|
||||
"toolchainContract",
|
||||
"dependencies",
|
||||
"artifact",
|
||||
|
||||
@@ -73,6 +73,8 @@ def validate_manifest(
|
||||
fail("manifest productCompatibility is missing")
|
||||
if not isinstance(manifest.get("buildDependencies"), dict):
|
||||
fail("manifest buildDependencies must be an object")
|
||||
if manifest.get("buildType") != "RelWithDebInfo":
|
||||
fail("manifest buildType must be RelWithDebInfo")
|
||||
for field in (
|
||||
"artifactIdentity",
|
||||
"platform",
|
||||
@@ -245,6 +247,7 @@ def main() -> None:
|
||||
"toolchainContract": manifest["toolchainContract"],
|
||||
"dependencies": definition["dependencies"],
|
||||
"buildDependencies": manifest["buildDependencies"],
|
||||
"buildType": manifest["buildType"],
|
||||
"artifact": artifact,
|
||||
}
|
||||
envelope = signer.envelope(payload)
|
||||
|
||||
@@ -264,9 +264,9 @@ done < <(jq -r '.cmakeOptions | to_entries[] | [.key, .value] | @tsv' \
|
||||
"$configuration")
|
||||
|
||||
cmake "${cmake_arguments[@]}"
|
||||
cmake --build "$build" --parallel
|
||||
ctest --test-dir "$build" --output-on-failure
|
||||
cmake --install "$build"
|
||||
cmake --build "$build" --config RelWithDebInfo --parallel
|
||||
ctest --test-dir "$build" --build-config RelWithDebInfo --output-on-failure
|
||||
cmake --install "$build" --config RelWithDebInfo
|
||||
|
||||
package_arguments=(
|
||||
--registry "$root/components.json"
|
||||
@@ -278,6 +278,7 @@ package_arguments=(
|
||||
--source-sha "$source_sha"
|
||||
--source-tree-hash "$source_tree_hash"
|
||||
--build-dependencies "$build_dependencies"
|
||||
--build-type RelWithDebInfo
|
||||
)
|
||||
if [[ -n $abi_hash ]]; then
|
||||
package_arguments+=(--abi-hash "$abi_hash")
|
||||
|
||||
+5
-2
@@ -6,7 +6,7 @@ usage() {
|
||||
usage: scripts/release.sh --version VERSION [options]
|
||||
|
||||
Options:
|
||||
--build-dir DIR Clean build directory (default: build-release)
|
||||
--build-dir DIR Clean build directory (default: build-relwithdebinfo)
|
||||
--dist-dir DIR Release output directory (default: dist)
|
||||
--jobs N Parallel build jobs
|
||||
--skip-tests Skip CTest and frontend tests
|
||||
@@ -65,7 +65,7 @@ source_dir=$(cd -- "$script_dir/.." && pwd -P)
|
||||
# shellcheck source=lib/docker-daemon-path.sh
|
||||
source "$script_dir/lib/docker-daemon-path.sh"
|
||||
version=
|
||||
build_dir="$source_dir/build-release"
|
||||
build_dir="$source_dir/build-relwithdebinfo"
|
||||
dist_dir="$source_dir/dist"
|
||||
jobs=
|
||||
run_tests=1
|
||||
@@ -460,6 +460,7 @@ elf_validation_args=(
|
||||
--root "$stage"
|
||||
--report "$dependency_report"
|
||||
--max-glibc 2.35
|
||||
--require-debug-info
|
||||
--forbid-content-prefix "$source_dir"
|
||||
--forbid-content-prefix "$build_dir"
|
||||
)
|
||||
@@ -561,6 +562,7 @@ python3 "$source_dir/scripts/collect-frontend-licenses.py" \
|
||||
python3 "$source_dir/scripts/generate-release-manifest.py" \
|
||||
--root "$stage" \
|
||||
--version "$version" \
|
||||
--build-type RelWithDebInfo \
|
||||
--output "$stage/manifest.json"
|
||||
|
||||
# Installer helpers are mutable prefix-level files and intentionally are not
|
||||
@@ -651,6 +653,7 @@ if ((package_components)); then
|
||||
--channel "$update_channel" \
|
||||
--sequence "$component_sequence" \
|
||||
--product-version "$version" \
|
||||
--build-type RelWithDebInfo \
|
||||
--toolchain-contract linux-x86_64-glibc-2.35-cxx26
|
||||
fi
|
||||
(
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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/"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -181,6 +181,7 @@ def validate(
|
||||
root: Path,
|
||||
maximum_glibc: tuple[int, ...] | None = None,
|
||||
forbidden_content_prefixes: tuple[bytes, ...] = (),
|
||||
require_debug_info: bool = False,
|
||||
) -> list[str]:
|
||||
executable = root / "bin/echoiond"
|
||||
updater = root / "bin/echoion-updater"
|
||||
@@ -225,6 +226,13 @@ def validate(
|
||||
re.MULTILINE,
|
||||
):
|
||||
raise ValueError(f"{relative} is not an x86-64 ELF")
|
||||
if require_debug_info:
|
||||
sections = command_output(["readelf", "-SW", os.fspath(path)])
|
||||
if re.search(r"\]\s+\.(?:z)?debug_info\s", sections) is None:
|
||||
raise ValueError(
|
||||
f"{relative} has no debug information; expected a "
|
||||
"RelWithDebInfo artifact"
|
||||
)
|
||||
dynamic = command_output(["readelf", "-dW", os.fspath(path)])
|
||||
runpaths = RUNPATH_PATTERN.findall(dynamic)
|
||||
if path in plugin_files:
|
||||
@@ -313,6 +321,11 @@ def main() -> int:
|
||||
parser.add_argument("--root", required=True, type=Path)
|
||||
parser.add_argument("--report", type=Path)
|
||||
parser.add_argument("--max-glibc", type=parse_version)
|
||||
parser.add_argument(
|
||||
"--require-debug-info",
|
||||
action="store_true",
|
||||
help="reject ELF payloads without DWARF debug information",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--forbid-content-prefix",
|
||||
action="append",
|
||||
@@ -334,6 +347,7 @@ def main() -> int:
|
||||
root,
|
||||
arguments.max_glibc,
|
||||
forbidden_content_prefixes,
|
||||
arguments.require_debug_info,
|
||||
)
|
||||
except (OSError, ValueError) as error:
|
||||
parser.error(str(error))
|
||||
|
||||
@@ -101,6 +101,8 @@ def load_and_validate(root: Path, expected_version: str | None = None) -> dict:
|
||||
raise ValueError(
|
||||
f"release version mismatch: expected {expected_version!r}, got {version!r}"
|
||||
)
|
||||
if manifest.get("buildType") != "RelWithDebInfo":
|
||||
raise ValueError("release manifest buildType must be RelWithDebInfo")
|
||||
|
||||
entries = manifest.get("files")
|
||||
if not isinstance(entries, list):
|
||||
|
||||
@@ -118,6 +118,7 @@ def main() -> None:
|
||||
"artifactIdentity": expected["artifactIdentity"],
|
||||
"activation": definition["activation"],
|
||||
"dependencies": definition["dependencies"],
|
||||
"buildType": "RelWithDebInfo",
|
||||
}
|
||||
for field, value in required.items():
|
||||
if release.get(field) != value:
|
||||
|
||||
Reference in new issue
Block a user