Release: cut over Echoion 2.0 components
Modular container CI / release-build (push) Has been cancelled

This commit is contained in:
faumaray committed 2026-07-29 20:35:27 +03:00
1 parent 1305d37fae
commit 458dde05a6
169 files changed
+3069 -32261

No files matched your search

+6 -6
View File
@@ -75,7 +75,7 @@ the migration participates in transaction rollback.
Create publishable artifacts from the repository root:
```bash
scripts/release.sh --version 1.2.3
scripts/release.sh --version 2.0.0
```
For a coordinated pre-publication build, add `--void-source ../VoidLibrary`
@@ -87,8 +87,8 @@ The default command uses the version-pinned release toolchain container and
does not start the bot. Installation flags and data layouts are documented in
the root README.
Use `scripts/release.sh --update-url URL` to add an unsigned feed payload to the
release checksums. `scripts/generate-update-feed.py` can additionally produce an
Ed25519-signed envelope from a key held outside the repository. The generator
also accepts `--component core` and `--component plugin --artifact-id ID` for
independently published Core and managed-plugin artifacts.
The official workflow packages all locked components and publishes signed,
channel-separated catalogs through `scripts/publish-component-feeds.py`.
`scripts/generate-update-feed.py` remains available only for an explicit custom
`direct` source; it can produce an Ed25519-signed envelope from a key held
outside the repository.
+126 -2
View File
@@ -342,6 +342,50 @@ systemctl_for() {
fi
}
write_pending_generation() {
local destination=$1
local generation=$2
local previous=$3
local temporary
temporary=$(mktemp --tmpdir="$(dirname -- "$destination")" \
'.pending-install-generation.XXXXXX')
{
printf 'version=%s\n' "$generation"
printf 'previous=%s\n' "$previous"
} >"$temporary"
chmod 0600 "$temporary"
if [[ $mode == system || $register_service == system ]]; then
chown "$SERVICE_USER:$SERVICE_USER" "$temporary"
fi
mv -f -- "$temporary" "$destination"
}
wait_for_service_health() {
local scope=$1
local expected_version=$2
local state=$3
local main_pid deadline observed
main_pid=$(systemctl_for "$scope" show --property MainPID --value \
"$SERVICE_NAME" 2>/dev/null || true)
if [[ ! $main_pid =~ ^[1-9][0-9]*$ ]]; then
warn "systemd did not report a service PID; live readiness will finish on first launch"
return 0
fi
deadline=$((SECONDS + 45))
while ((SECONDS < deadline)); do
observed=
if [[ -f $state/release-health && ! -L $state/release-health ]]; then
IFS= read -r observed <"$state/release-health" || true
fi
if [[ $observed == "$expected_version" ]] &&
systemctl_for "$scope" is-active --quiet "$SERVICE_NAME"; then
return 0
fi
sleep 1
done
return 1
}
safe_recorded_unit_path() {
local scope=$1
local unit=$2
@@ -722,6 +766,7 @@ load_old_record() {
local record=$1
local key value
OLD_PREFIX=
OLD_VERSION=
OLD_SERVICE_SCOPE=none
OLD_SERVICE_UNIT=
OLD_SERVICE_SHA256=
@@ -750,10 +795,12 @@ load_old_record() {
OLD_RELOCATABLE=0
OLD_LAUNCHER=
OLD_LAUNCHER_SHA256=
OLD_LEGACY_ROLLBACK=
[[ -f $record ]] || return 0
while IFS='=' read -r key value; do
case $key in
prefix) OLD_PREFIX=$value ;;
version) OLD_VERSION=$value ;;
service_scope) OLD_SERVICE_SCOPE=$value ;;
service_unit) OLD_SERVICE_UNIT=$value ;;
service_unit_sha256) OLD_SERVICE_SHA256=$value ;;
@@ -782,6 +829,7 @@ load_old_record() {
relocatable) OLD_RELOCATABLE=$value ;;
launcher) OLD_LAUNCHER=$value ;;
launcher_sha256) OLD_LAUNCHER_SHA256=$value ;;
legacy_rollback) OLD_LEGACY_ROLLBACK=$value ;;
esac
done < "$record"
case $OLD_RELOCATABLE in
@@ -1117,6 +1165,7 @@ write_record() {
printf 'state_marker_sha256=%s\n' "$STATE_MARKER_SHA256"
printf 'launcher=%s\n' "$LAUNCHER_RECORD_PATH"
printf 'launcher_sha256=%s\n' "$LAUNCHER_SHA256"
printf 'legacy_rollback=%s\n' "$LEGACY_ROLLBACK_RECORD"
} > "$temporary"
chmod 0600 "$temporary"
mv -f -- "$temporary" "$destination"
@@ -1153,7 +1202,9 @@ write_json_record() {
printf ' "updater": {"executable": "current/bin/echoion-updater", '
printf '"privilegedHelper": "%s", ' \
"$(json_escape "$UPDATER_HELPER_RECORD_PATH")"
printf '"timer": "echoion-updater.timer"}\n'
printf '"timer": "echoion-updater.timer"},\n'
printf ' "legacyRollback": "%s"\n' \
"$(json_escape "$LEGACY_ROLLBACK_RECORD")"
printf '}\n'
} > "$temporary"
chmod 0600 "$temporary"
@@ -1469,6 +1520,9 @@ UPDATER_BUNDLE_CREATED=0
WANT_LAUNCHER=$RELOCATABLE
PLUGIN_BOOTSTRAP_CREATED_PATHS=()
PLUGIN_BOOTSTRAP_TEMPORARY=
LEGACY_MIGRATION=0
LEGACY_ROLLBACK_RECORD=
LEGACY_ARCHIVE_ROOT=
STAGING=
TRANSACTION_BACKUP_DIR=
@@ -1546,6 +1600,12 @@ rollback_install() {
fi
fi
restore_current_link "$old_current"
if [[ -f $TRANSACTION_BACKUP_DIR/pending-install-generation ]]; then
cp -a -- "$TRANSACTION_BACKUP_DIR/pending-install-generation" \
"$pending_generation"
else
rm -f -- "$pending_generation"
fi
if [[ -f $TRANSACTION_BACKUP_DIR/install-record ]]; then
cp -a -- "$TRANSACTION_BACKUP_DIR/install-record" "$record"
else
@@ -1661,6 +1721,18 @@ acquire_prefix_lock "$prefix"
record=$prefix/$RECORD_NAME
json_record=$prefix/$JSON_RECORD_NAME
load_old_record "$record"
if [[ ${OLD_VERSION:-} =~ ^1\.[0-9]+\.[0-9]+([.-].*)?$ &&
$version =~ ^2\. ]]; then
LEGACY_MIGRATION=1
LEGACY_ROLLBACK_RECORD=legacy/v1
LEGACY_ARCHIVE_ROOT=$prefix/$LEGACY_ROLLBACK_RECORD
elif [[ ${OLD_LEGACY_ROLLBACK:-} == legacy/v1 &&
-d $prefix/legacy/v1 && ! -L $prefix/legacy/v1 ]]; then
LEGACY_ROLLBACK_RECORD=$OLD_LEGACY_ROLLBACK
LEGACY_ARCHIVE_ROOT=$prefix/$LEGACY_ROLLBACK_RECORD
elif [[ -n ${OLD_LEGACY_ROLLBACK:-} ]]; then
die "existing install record has an unsafe or missing legacy rollback target"
fi
if [[ -n ${OLD_UPDATER_HELPER:-} ]]; then
verify_recorded_updater_helper "$OLD_UPDATER_HELPER" \
"${OLD_UPDATER_HELPER_SHA256:-}"
@@ -1826,6 +1898,11 @@ if [[ -L $prefix/current ]]; then
elif [[ -e $prefix/current ]]; then
die "current exists but is not a symlink: $prefix/current"
fi
if [[ $LEGACY_MIGRATION -eq 1 ]]; then
[[ $old_current == "versions/$OLD_VERSION" &&
-d $prefix/$old_current && ! -L $prefix/$old_current ]] ||
die "v1 migration requires the recorded complete legacy runtime tree"
fi
unit_path=
unit_hash=
@@ -1985,6 +2062,13 @@ fi
if [[ -f $json_record ]]; then
cp -a -- "$json_record" "$TRANSACTION_BACKUP_DIR/install-json"
fi
pending_generation=$state_dir/updates/pending-install-generation
if [[ -f $pending_generation && ! -L $pending_generation ]]; then
cp -a -- "$pending_generation" \
"$TRANSACTION_BACKUP_DIR/pending-install-generation"
elif [[ -e $pending_generation || -L $pending_generation ]]; then
die "pending generation marker is not a regular file"
fi
if [[ $service_scope_changes -eq 1 ]]; then
cp -a -- "$OLD_SERVICE_UNIT" "$TRANSACTION_BACKUP_DIR/old-scope-unit"
if [[ -n ${OLD_UPDATER_SERVICE_UNIT:-} ]]; then
@@ -2032,6 +2116,44 @@ if [[ ${OLD_SERVICE_SCOPE:-none} != none &&
die "current exists but is not a symlink: $prefix/current"
fi
fi
if [[ $LEGACY_MIGRATION -eq 1 ]]; then
if [[ ${OLD_SERVICE_SCOPE:-none} != none ]]; then
systemctl_for "$OLD_SERVICE_SCOPE" stop "$SERVICE_NAME" ||
die "v1 service must be stopped before modular migration"
fi
if [[ -e $LEGACY_ARCHIVE_ROOT || -L $LEGACY_ARCHIVE_ROOT ]]; then
[[ -d $LEGACY_ARCHIVE_ROOT && ! -L $LEGACY_ARCHIVE_ROOT &&
-f $LEGACY_ARCHIVE_ROOT/rollback.conf &&
-d $LEGACY_ARCHIVE_ROOT/tree ]] ||
die "legacy rollback archive is incomplete: $LEGACY_ARCHIVE_ROOT"
grep -Fx -- "version=$OLD_VERSION" \
"$LEGACY_ARCHIVE_ROOT/rollback.conf" >/dev/null ||
die "legacy rollback archive belongs to another version"
else
legacy_staging=$(mktemp -d --tmpdir="$prefix" '.legacy-v1.XXXXXX')
cp -a --reflink=auto "$prefix/$old_current" "$legacy_staging/tree"
install -d -m 0755 -- "$legacy_staging/service"
if [[ -n ${OLD_SERVICE_UNIT:-} ]]; then
cp -a -- "$OLD_SERVICE_UNIT" "$legacy_staging/service/"
fi
if [[ -n ${OLD_UPDATER_SERVICE_UNIT:-} ]]; then
cp -a -- "$OLD_UPDATER_SERVICE_UNIT" "$legacy_staging/service/"
fi
if [[ -n ${OLD_UPDATER_TIMER_UNIT:-} ]]; then
cp -a -- "$OLD_UPDATER_TIMER_UNIT" "$legacy_staging/service/"
fi
{
printf 'version=%s\n' "$OLD_VERSION"
printf 'current=%s\n' "$old_current"
printf 'service_scope=%s\n' "${OLD_SERVICE_SCOPE:-none}"
printf 'config=%s\n' "$config_file"
printf 'state=%s\n' "$state_dir"
} >"$legacy_staging/rollback.conf"
chmod 0600 "$legacy_staging/rollback.conf"
install -d -m 0755 -- "$(dirname -- "$LEGACY_ARCHIVE_ROOT")"
mv -- "$legacy_staging" "$LEGACY_ARCHIVE_ROOT"
fi
fi
TRANSACTION_ACTIVE=1
if [[ $CONFIG_MIGRATION_ARMED -eq 1 ]]; then
@@ -2079,6 +2201,7 @@ new_link_directory=$(mktemp -d --tmpdir="$prefix" '.current-link.XXXXXX')
ln -s -- "versions/$version" "$new_link_directory/current"
mv -Tf -- "$new_link_directory/current" "$prefix/current"
rmdir -- "$new_link_directory"
write_pending_generation "$pending_generation" "$version" "$old_current"
if [[ $register_service != none ]]; then
systemctl_for "$register_service" daemon-reload || die "systemd rejected the installed service unit"
@@ -2088,7 +2211,8 @@ if [[ $register_service != none ]]; then
if ! systemctl_for "$register_service" enable "$SERVICE_NAME" "$UPDATER_TIMER_NAME" ||
! systemctl_for "$register_service" restart "$SERVICE_NAME" ||
! systemctl_for "$register_service" start "$UPDATER_TIMER_NAME" ||
! systemctl_for "$register_service" is-active --quiet "$SERVICE_NAME"; then
! systemctl_for "$register_service" is-active --quiet "$SERVICE_NAME" ||
! wait_for_service_health "$register_service" "$version" "$state_dir"; then
warn "new service failed health validation; restoring previous release and unit"
die "service failed to start"
fi
+37
View File
@@ -762,6 +762,43 @@ printf '# changed privileged updater helper in 1.2.4\n' >> \
python3 "$PACKAGING_DIR/../scripts/generate-release-manifest.py" \
--root "$upgrade_payload" --version 1.2.4
v2_payload=$TEST_ROOT/v2-payload
cp -a -- "$upgrade_payload" "$v2_payload"
sed -i 's/"version": "1.2.4"/"version": "2.0.0"/' \
"$v2_payload/manifest.json"
python3 "$PACKAGING_DIR/../scripts/generate-release-manifest.py" \
--root "$v2_payload" --version 2.0.0
legacy_migration_prefix=$TEST_ROOT/legacy-migration
legacy_config_home=$TEST_ROOT/legacy-home
XDG_CONFIG_HOME=$legacy_config_home \
"$payload/install.sh" --mode portable --prefix "$legacy_migration_prefix" \
--register-service user --non-interactive >/dev/null
printf 'preserved database bytes\n' \
>"$legacy_migration_prefix/state/echoion.db"
legacy_tree_hash=$(sha256sum -- \
"$legacy_migration_prefix/current/bin/echoiond")
legacy_tree_hash=${legacy_tree_hash%% *}
: >"$SYSTEMCTL_LOG"
XDG_CONFIG_HOME=$legacy_config_home \
"$v2_payload/install.sh" --mode portable --prefix "$legacy_migration_prefix" \
--register-service user --non-interactive >/dev/null
[[ $(readlink -- "$legacy_migration_prefix/current") == versions/2.0.0 ]] ||
fail 'v1 migration did not activate the initial v2 generation'
assert_file "$legacy_migration_prefix/legacy/v1/tree/bin/echoiond"
archived_tree_hash=$(sha256sum -- \
"$legacy_migration_prefix/legacy/v1/tree/bin/echoiond")
archived_tree_hash=${archived_tree_hash%% *}
[[ $archived_tree_hash == "$legacy_tree_hash" ]] ||
fail 'v1 migration did not preserve the complete legacy executable tree'
assert_file "$legacy_migration_prefix/legacy/v1/service/echoion.service"
assert_file \
"$legacy_migration_prefix/state/updates/pending-install-generation"
assert_file "$legacy_migration_prefix/state/echoion.db"
assert_contains "$legacy_migration_prefix/.echoion-install" \
'legacy_rollback=legacy/v1'
assert_contains "$SYSTEMCTL_LOG" '--user stop echoion.service'
"$legacy_migration_prefix/uninstall.sh" --purge --non-interactive >/dev/null
bootstrap_upgrade_prefix=$TEST_ROOT/bootstrap-upgrade
"$payload/install.sh" --mode portable --prefix "$bootstrap_upgrade_prefix" \
--register-service none --non-interactive >/dev/null
-239
View File
@@ -1,239 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
if [[ $# != 2 ]]; then
echo "usage: $0 ECHOION_UPDATER SOURCE_ROOT" >&2
exit 2
fi
updater=$(realpath -e -- "$1")
source_root=$(realpath -e -- "$2")
temporary=$(mktemp -d "${TMPDIR:-/tmp}/echoion-updater-test.XXXXXX")
trap 'rm -rf -- "$temporary"' EXIT
root=$temporary/root
stable_helper=$root/libexec/updater/installer/bin/echoion-updater
mkdir -p "$root/versions" "$root/state" "$(dirname -- "$stable_helper")"
install -m 0755 "$updater" "$stable_helper"
stable_helper_sha=$(sha256sum "$stable_helper")
stable_helper_sha=${stable_helper_sha%% *}
make_release() {
local destination=$1
local version=$2
mkdir -p "$destination/bin" "$destination/lib" "$destination/service" \
"$destination/share/echoion/web" "$destination/share/echoion/tools" \
"$destination/share/echoion/certs"
install -m 0755 /bin/true "$destination/bin/echoiond"
install -m 0755 "$updater" "$destination/bin/echoion-updater"
printf 'core %s\n' "$version" >"$destination/lib/Echoion.ts"
install -m 0644 "$source_root/packaging/service/echoion.service.in" \
"$destination/service/echoion.service.in"
install -m 0644 "$source_root/packaging/service/echoion-updater.service.in" \
"$destination/service/echoion-updater.service.in"
install -m 0644 "$source_root/packaging/service/echoion-updater.timer.in" \
"$destination/service/echoion-updater.timer.in"
install -m 0755 "$source_root/scripts/validate-release-manifest.py" \
"$destination/share/echoion/tools/validate-release-manifest.py"
printf '{}\n' >"$destination/share/echoion/config.example.json"
printf '<!doctype html>\n' >"$destination/share/echoion/web/index.html"
printf 'test trust bundle\n' \
>"$destination/share/echoion/certs/ca-certificates.crt"
python3 "$source_root/scripts/generate-release-manifest.py" \
--root "$destination" --version "$version"
}
make_release "$root/versions/1.0.0" 1.0.0
make_release "$root/versions/1.1.0" 1.1.0
ln -s versions/1.1.0 "$root/current"
cat >"$root/.echoion-install" <<EOF
format=1
prefix=$root
version=1.1.0
state_dir=$root/state
EOF
cat >"$root/install.json" <<EOF
{"schemaVersion":1,"version":"1.1.0","stateDir":"$root/state"}
EOF
install -m 0644 /dev/null "$root/.update.lock"
printf 'P 1.0.0\nH 1.0.0\nP 1.1.0\nH 1.1.0\n' >"$root/health.log"
chmod 0644 "$root/health.log"
status=$("$updater" --root "$root" status --json)
[[ $status == *'"current":"1.1.0"'* ]]
[[ $status == *'"1.0.0"'* ]]
make_release "$root/versions/0.9.0" 0.9.0
if "$updater" --root "$root" rollback-runtime --version 0.9.0 \
--retain 2 >/dev/null 2>&1; then
echo "updater accepted a runtime without durable healthy state" >&2
exit 1
fi
[[ $(readlink -- "$root/current") == versions/1.1.0 ]]
rm -rf -- "$root/versions/0.9.0"
history_victim=$temporary/history-victim
printf '%s\n' 'must remain unchanged' >"$history_victim"
chmod 0600 "$history_victim"
mkdir -p "$root/state/updates"
ln -s "$history_victim" "$root/state/updates/history.jsonl"
if "$updater" --root "$root" request rollback-runtime --version 1.0.0 \
--retain 2 --origin test >/dev/null 2>&1; then
echo "updater followed a symlink while opening privileged history" >&2
exit 1
fi
[[ $(<"$history_victim") == 'must remain unchanged' ]]
[[ $(stat -c '%a' -- "$history_victim") == 600 ]]
rm -- "$root/state/updates/history.jsonl"
rm -f -- "$root/state/updates/privileged-requests/"*.json
queue_victim=$temporary/queue-victim
mkdir "$queue_victim"
mv "$root/state/updates/privileged-requests" \
"$root/state/updates/privileged-requests.safe"
ln -s "$queue_victim" "$root/state/updates/privileged-requests"
if "$updater" --root "$root" request rollback-runtime --version 1.0.0 \
--retain 2 --origin test >/dev/null 2>&1; then
echo "updater accepted a symlinked privileged request directory" >&2
exit 1
fi
[[ -z $(find "$queue_victim" -mindepth 1 -print -quit) ]]
rm -- "$root/state/updates/privileged-requests"
mv "$root/state/updates/privileged-requests.safe" \
"$root/state/updates/privileged-requests"
if "$updater" --root "$root" check >/dev/null 2>&1 ||
[[ -e $root/state/updates/requests ]]; then
echo "updater still exposes the dead generic request queue" >&2
exit 1
fi
if "$updater" --root "$root" request rollback-runtime \
--version '../escape' --retain 2 >/dev/null 2>&1; then
echo "updater accepted an unsafe request identifier" >&2
exit 1
fi
if "$updater" --root "$root" request rollback-runtime \
--version 1.0.0 --retain 0 >/dev/null 2>&1; then
echo "updater accepted an out-of-range retention count" >&2
exit 1
fi
candidate=$root/state/updates/staged/runtime-1-2-0
make_release "$candidate" 1.2.0
# Candidate runtime code must never replace the stable privileged helper.
install -m 0755 /bin/false "$candidate/bin/echoion-updater"
python3 "$source_root/scripts/generate-release-manifest.py" \
--root "$candidate" --version 1.2.0
manifest_sha=$(sha256sum "$candidate/manifest.json")
manifest_sha=${manifest_sha%% *}
pending_victim=$temporary/pending-victim
printf '%s\n' 'must remain unchanged' >"$pending_victim"
ln -s "$pending_victim" "$root/state/updates/pending-runtime.json"
privileged=$("$updater" --root "$root" request activate-runtime \
--staging runtime-1-2-0 --version 1.2.0 \
--manifest-sha256 "$manifest_sha" --retain 3 --origin test)
[[ $privileged == "$root/state/updates/privileged-requests/"*.json ]]
if "$updater" --root "$root" consume >/dev/null 2>&1; then
echo "updater accepted a symlinked pending-runtime journal" >&2
exit 1
fi
[[ $(<"$pending_victim") == 'must remain unchanged' ]]
[[ $(readlink -- "$root/current") == versions/1.1.0 ]]
[[ -d $candidate ]]
rm -- "$root/state/updates/pending-runtime.json"
"$updater" --root "$root" consume >/dev/null
[[ $(<"$pending_victim") == 'must remain unchanged' ]]
[[ $(readlink -- "$root/current") == versions/1.2.0 ]]
[[ ! -e $candidate ]]
[[ $(sha256sum "$stable_helper") == "$stable_helper_sha "* ]]
[[ $(sha256sum "$root/current/bin/echoion-updater") != "$stable_helper_sha "* ]]
grep -F '"version": "1.2.0"' "$root/state/updates/activated-runtime.json" >/dev/null
grep -F '"manifestPath": "versions/1.2.0/manifest.json"' \
"$root/state/updates/activated-runtime.json" >/dev/null
grep -F '"retainHealthyVersions": 3' \
"$root/state/updates/activated-runtime.json" >/dev/null
grep -F '"state": "pending"' "$root/state/updates/pending-runtime.json" >/dev/null
grep -F '"retainHealthyVersions": 3' \
"$root/state/updates/pending-runtime.json" >/dev/null
grep -F 'version=1.2.0' "$root/.echoion-install" >/dev/null
grep -F '"version":"1.2.0"' "$root/install.json" >/dev/null
rm -- "$root/state/updates/status.json"
mkdir "$root/state/updates/status.json"
"$updater" --root "$root" request commit-runtime --version 1.2.0 \
--retain 3 --origin daemon >/dev/null
"$updater" --root "$root" consume >/dev/null
[[ $(readlink -- "$root/current") == versions/1.2.0 ]]
[[ ! -e $root/state/updates/pending-runtime.json ]]
[[ -f $root/state/updates/committed-runtime.json ]]
grep -F '"state": "committed"' \
"$root/state/updates/activated-runtime.json" >/dev/null
grep -F 'H 1.2.0' "$root/health.log" >/dev/null
[[ ! -e $root/staging ]]
rmdir "$root/state/updates/status.json"
candidate=$root/state/updates/staged/runtime-1-3-0
make_release "$candidate" 1.3.0
manifest_sha=$(sha256sum "$candidate/manifest.json")
manifest_sha=${manifest_sha%% *}
"$updater" --root "$root" request activate-runtime \
--staging runtime-1-3-0 --version 1.3.0 \
--manifest-sha256 "$manifest_sha" --retain 3 --origin test >/dev/null
"$updater" --root "$root" consume >/dev/null
[[ $(readlink -- "$root/current") == versions/1.3.0 ]]
[[ -f $root/state/updates/pending-runtime.json ]]
# A helper pass inside the durable health grace period must not race the
# daemon's 30-second health confirmation.
"$updater" --root "$root" consume >/dev/null
[[ $(readlink -- "$root/current") == versions/1.3.0 ]]
[[ -f $root/state/updates/pending-runtime.json ]]
# Once the durable deadline has expired, a pass with no matching confirmation
# restores the previous version and records the failed candidate.
sed -i 's/"activatedAt": "[^"]*"/"activatedAt": "2000-01-01T00:00:00Z"/' \
"$root/state/updates/pending-runtime.json"
"$updater" --root "$root" consume >/dev/null
[[ $(readlink -- "$root/current") == versions/1.2.0 ]]
[[ ! -e $root/state/updates/pending-runtime.json ]]
grep -F '"version": "1.3.0"' \
"$root/state/updates/failed-runtime.json" >/dev/null
grep -F '"state": "rolled-back"' \
"$root/state/updates/activated-runtime.json" >/dev/null
grep -F 'F 1.3.0' "$root/health.log" >/dev/null
[[ ! -e $root/versions/1.3.0 ]]
"$updater" --root "$root" request rollback-runtime --version 1.1.0 \
--retain 3 --origin test >/dev/null
"$updater" --root "$root" consume >/dev/null
[[ $(readlink -- "$root/current") == versions/1.1.0 ]]
grep -F '"version": "1.1.0"' "$root/state/updates/activated-runtime.json" >/dev/null
"$updater" --root "$root" rollback-runtime --version 1.0.0 \
--retain 3 >/dev/null
[[ $(readlink -- "$root/current") == versions/1.0.0 ]]
grep -F '"operation":"rollback-runtime"' "$root/state/updates/history.jsonl" >/dev/null
if "$updater" --root "$root" rollback-runtime --version '../../tmp' \
>/dev/null 2>&1; then
echo "updater accepted an unsafe rollback target" >&2
exit 1
fi
[[ $(readlink -- "$root/current") == versions/1.0.0 ]]
"$updater" --root "$root" reconcile >/dev/null
grep -F '"current": "1.0.0"' "$root/state/updates/status.json" >/dev/null
[[ $(sha256sum "$stable_helper") == "$stable_helper_sha "* ]]
# Retention is evaluated only after a committed health confirmation or an
# explicit validated rollback. Active plus one previous healthy version is
# retained; known failed and older healthy versions are eligible for pruning.
"$updater" --root "$root" rollback-runtime --version 1.2.0 \
--retain 1 >/dev/null
[[ $(readlink -- "$root/current") == versions/1.2.0 ]]
[[ -d $root/versions/1.0.0 ]]
[[ ! -e $root/versions/1.1.0 ]]
[[ ! -e $root/versions/1.3.0 ]]
[[ ! -e $root/staging ]]
echo "updater lifecycle tests passed"
-33
View File
@@ -1,33 +0,0 @@
find_package(OpenSSL REQUIRED COMPONENTS Crypto)
add_executable(EchoionUpdater echoion-updater.cpp ReleaseTree.cpp)
target_link_libraries(EchoionUpdater PRIVATE OpenSSL::Crypto Void::Update)
set_target_properties(EchoionUpdater PROPERTIES
OUTPUT_NAME echoion-updater
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
if(UNIX AND NOT APPLE)
set_target_properties(EchoionUpdater PROPERTIES
INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}"
INSTALL_RPATH_USE_LINK_PATH FALSE)
endif()
install(TARGETS EchoionUpdater
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT Runtime)
if(BUILD_TESTS)
add_executable(EchoionReleaseTreeSecurityTests
ReleaseTreeSecurityTests.cpp
ReleaseTree.cpp)
target_link_libraries(EchoionReleaseTreeSecurityTests PRIVATE OpenSSL::Crypto)
add_test(NAME EchoionReleaseTreeSecurity
COMMAND EchoionReleaseTreeSecurityTests)
add_test(NAME EchoionUpdaterLifecycle
COMMAND bash
"${CMAKE_CURRENT_SOURCE_DIR}/../tests/updater_test.sh"
"$<TARGET_FILE:EchoionUpdater>"
"${CMAKE_SOURCE_DIR}")
endif()
File diff suppressed because it is too large. Load diff
-61
View File
@@ -1,61 +0,0 @@
#pragma once
#include <cstdint>
#include <filesystem>
#include <string>
#include <string_view>
#include <variant>
namespace Echoion::Updater
{
struct RuntimeActivation {
std::string stagingId;
std::string version;
std::string manifestSha256;
std::uint32_t retainHealthyVersions = 2;
};
struct RuntimeRollback {
std::string version;
std::uint32_t retainHealthyVersions = 2;
};
struct RuntimeCommit {
std::string version;
std::uint32_t retainHealthyVersions = 2;
};
struct PendingRuntime {
std::string candidateId;
std::string version;
std::string previousVersion;
std::string manifestSha256;
std::string activatedAt;
std::uint32_t retainHealthyVersions = 2;
};
using PrivilegedRequest =
std::variant<RuntimeActivation, RuntimeRollback, RuntimeCommit>;
[[nodiscard]] RuntimeActivation
parseActivationRequest(std::string_view json);
[[nodiscard]] PrivilegedRequest
parsePrivilegedRequest(std::string_view json);
[[nodiscard]] PendingRuntime parsePendingRuntime(std::string_view json);
[[nodiscard]] std::string sha256File(const std::filesystem::path& path);
void copyAndValidateRelease(int sourceDirectoryDescriptor,
const std::filesystem::path& destination,
const RuntimeActivation& activation);
void removeReleaseTreeAt(int parentDirectoryDescriptor,
std::string_view name);
void validateRelease(const std::filesystem::path& release,
const std::string& expectedVersion,
const std::string& expectedManifestSha256 = {});
void syncReleaseTree(const std::filesystem::path& root);
} // namespace Echoion::Updater
@@ -1,282 +0,0 @@
#include "ReleaseTree.hpp"
#include <cerrno>
#include <cstdint>
#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <functional>
#include <stdexcept>
#include <string>
#include <string_view>
#include <system_error>
#include <vector>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
namespace
{
namespace fs = std::filesystem;
class FileDescriptor final
{
public:
explicit FileDescriptor(const int descriptor) noexcept
: descriptor_{descriptor}
{
}
~FileDescriptor()
{
if (descriptor_ >= 0) {
::close(descriptor_);
}
}
FileDescriptor(const FileDescriptor&) = delete;
FileDescriptor& operator=(const FileDescriptor&) = delete;
FileDescriptor(FileDescriptor&&) = delete;
FileDescriptor& operator=(FileDescriptor&&) = delete;
[[nodiscard]] int get() const noexcept { return descriptor_; }
private:
int descriptor_;
};
class TemporaryDirectory final
{
public:
TemporaryDirectory()
{
const std::string value =
(fs::temp_directory_path() / "echoion-release-tree.XXXXXX")
.string();
std::vector<char> pattern{value.begin(), value.end()};
pattern.push_back('\0');
if (::mkdtemp(pattern.data()) == nullptr) {
throw std::system_error{
errno, std::generic_category(),
"cannot create temporary directory"};
}
path_ = pattern.data();
}
~TemporaryDirectory()
{
std::error_code ignored;
fs::remove_all(path_, ignored);
}
TemporaryDirectory(const TemporaryDirectory&) = delete;
TemporaryDirectory& operator=(const TemporaryDirectory&) = delete;
TemporaryDirectory(TemporaryDirectory&&) = delete;
TemporaryDirectory& operator=(TemporaryDirectory&&) = delete;
[[nodiscard]] const fs::path& path() const noexcept
{
return path_;
}
private:
fs::path path_;
};
void setMode(const fs::path& path, const mode_t mode)
{
if (::chmod(path.c_str(), mode) != 0) {
throw std::system_error{errno, std::generic_category(),
"cannot set test path mode"};
}
}
void createDirectory(const fs::path& path)
{
fs::create_directory(path);
setMode(path, 0755);
}
void createFile(const fs::path& path, const std::string_view bytes)
{
std::ofstream output{path, std::ios::binary | std::ios::trunc};
output.write(bytes.data(), static_cast<std::streamsize>(bytes.size()));
if (!output) {
throw std::runtime_error{"cannot create test file"};
}
output.close();
setMode(path, 0644);
}
[[nodiscard]] FileDescriptor openDirectory(const fs::path& path)
{
const int descriptor = ::open(
path.c_str(), O_RDONLY | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
if (descriptor < 0) {
throw std::system_error{errno, std::generic_category(),
"cannot open test directory"};
}
return FileDescriptor{descriptor};
}
void expectFailure(const std::function<void()>& operation,
const std::string_view expected)
{
try {
operation();
} catch (const std::exception& error) {
if (std::string_view{error.what()}.find(expected) ==
std::string_view::npos) {
throw std::runtime_error{"unexpected failure: " +
std::string{error.what()}};
}
return;
}
throw std::runtime_error{"operation unexpectedly succeeded"};
}
[[nodiscard]] Echoion::Updater::RuntimeActivation activation()
{
return {.stagingId = "security-test",
.version = "security-test",
.manifestSha256 = {}};
}
void testOversizedFileRejectedBeforeCopy()
{
TemporaryDirectory temporary;
const fs::path source = temporary.path() / "source";
const fs::path versions = temporary.path() / "versions";
createDirectory(source);
createDirectory(versions);
const fs::path manifest = source / "manifest.json";
FileDescriptor file{::open(
manifest.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, 0644)};
if (file.get() < 0 ||
::ftruncate(
file.get(),
static_cast<off_t>(3ULL * 1024ULL * 1024ULL * 1024ULL)) != 0) {
throw std::system_error{errno, std::generic_category(),
"cannot create sparse oversized file"};
}
const FileDescriptor sourceDescriptor = openDirectory(source);
const fs::path replacement = temporary.path() / "replacement";
createDirectory(replacement);
createFile(replacement / "manifest.json", "replacement\n");
fs::rename(source, temporary.path() / "pinned-source");
fs::create_directory_symlink(replacement, source);
const fs::path destination = versions / ".incoming-oversized";
expectFailure(
[&] {
Echoion::Updater::copyAndValidateRelease(
sourceDescriptor.get(), destination, activation());
},
"file exceeds size limit");
if (fs::symlink_status(destination).type() !=
fs::file_type::not_found) {
throw std::runtime_error{
"failed oversized copy left a destination tree"};
}
}
void testManifestSymlinkIsNeverFollowed()
{
TemporaryDirectory temporary;
const fs::path source = temporary.path() / "source";
const fs::path versions = temporary.path() / "versions";
const fs::path secret = temporary.path() / "secret";
createDirectory(source);
createDirectory(versions);
createFile(secret, "must-not-be-copied\n");
fs::create_symlink(secret, source / "manifest.json");
const FileDescriptor sourceDescriptor = openDirectory(source);
const fs::path destination = versions / ".incoming-symlink";
expectFailure(
[&] {
Echoion::Updater::copyAndValidateRelease(
sourceDescriptor.get(), destination, activation());
},
"cannot open staged release file");
if (fs::symlink_status(destination).type() !=
fs::file_type::not_found) {
throw std::runtime_error{
"failed symlink copy left a destination tree"};
}
}
void testExcessiveDepthRejected()
{
TemporaryDirectory temporary;
const fs::path source = temporary.path() / "source";
const fs::path versions = temporary.path() / "versions";
createDirectory(source);
createDirectory(versions);
createFile(source / "manifest.json", "{}\n");
for (const std::string_view root : {"bin", "lib", "service", "share"}) {
createDirectory(source / root);
}
fs::path nested = source / "bin";
for (std::size_t depth{}; depth < 70U; ++depth) {
nested /= "d";
createDirectory(nested);
}
const FileDescriptor sourceDescriptor = openDirectory(source);
const fs::path destination = versions / ".incoming-deep";
expectFailure(
[&] {
Echoion::Updater::copyAndValidateRelease(
sourceDescriptor.get(), destination, activation());
},
"maximum directory depth");
if (fs::symlink_status(destination).type() !=
fs::file_type::not_found) {
throw std::runtime_error{
"failed deep copy left a destination tree"};
}
}
void testDescriptorRelativeCleanupDoesNotFollowSymlink()
{
TemporaryDirectory temporary;
const fs::path parent = temporary.path() / "parent";
const fs::path victim = temporary.path() / "victim";
createDirectory(parent);
createDirectory(victim);
createFile(victim / "sentinel", "unchanged\n");
fs::create_symlink(victim, parent / "candidate");
const FileDescriptor parentDescriptor = openDirectory(parent);
expectFailure(
[&] {
Echoion::Updater::removeReleaseTreeAt(parentDescriptor.get(),
"../victim");
},
"unsafe path component");
Echoion::Updater::removeReleaseTreeAt(parentDescriptor.get(),
"candidate");
if (fs::symlink_status(parent / "candidate").type() !=
fs::file_type::not_found ||
!fs::is_regular_file(victim / "sentinel")) {
throw std::runtime_error{
"descriptor-relative cleanup followed a symlink"};
}
}
} // namespace
int main()
{
testOversizedFileRejectedBeforeCopy();
testManifestSymlinkIsNeverFollowed();
testExcessiveDepthRejected();
testDescriptorRelativeCleanupDoesNotFollowSymlink();
}
File diff suppressed because it is too large. Load diff