1 parent
639362fbf5
commit
bdd69f0aad
101 files changed
+22691
-531
No files matched your search
+66
-2
@@ -1,8 +1,8 @@
|
||||
# Linux installer layout
|
||||
|
||||
`install.sh` and `uninstall.sh` are copied into each Linux release payload.
|
||||
`service/echoion.service.in` is rendered by the installer for user or system
|
||||
systemd scope. `tests/installer_test.sh` exercises portable installation,
|
||||
The installer renders the bot service plus the updater service/timer for user or
|
||||
system systemd scope. `tests/installer_test.sh` exercises portable installation,
|
||||
service opt-in, rollback, tamper protection, preservation, and purge behavior.
|
||||
System-scoped payloads are normalized to root ownership. Registered-service
|
||||
prefixes require a trusted path not writable by other identities. Purge uses
|
||||
@@ -14,12 +14,76 @@ Self-contained portable installs add a managed `echoion` launcher and relative
|
||||
install metadata, allowing a service-free tree to be moved and uninstalled as
|
||||
one directory.
|
||||
|
||||
The default installed tree is:
|
||||
|
||||
```text
|
||||
<prefix>/
|
||||
current -> versions/<version>
|
||||
versions/<version>/
|
||||
bin/ echoiond and echoion-updater
|
||||
lib/ Core and dynamic dependency closure
|
||||
service/ service templates
|
||||
share/echoion/ web, config template, licenses, validation tool
|
||||
bootstrap-plugins/ immutable first-party plugin artifacts
|
||||
manifest.json
|
||||
libexec/updater/<installer-version>/
|
||||
bin/echoion-updater stable installer-managed privileged helper
|
||||
lib/ private dynamic dependency closure
|
||||
config/
|
||||
plugins.d/ per-plugin JSON configuration, preserved on upgrade
|
||||
state/
|
||||
plugins/.managed/ versioned managed plugins and current links
|
||||
plugins/data/ plugin-owned persistent data, preserved on upgrade
|
||||
cache/ logs/ incoming/
|
||||
install.json .echoion-install
|
||||
install.sh uninstall.sh
|
||||
echoion portable launcher (portable mode)
|
||||
```
|
||||
|
||||
Payload validation is data-only: the installer runs the bundled Python manifest
|
||||
validator and never executes the daemon, Core, plugins, or updater. The updater
|
||||
also never performs network I/O or starts a service. It consumes bounded typed
|
||||
requests written below `state/updates`, with a root-owned system timer providing
|
||||
the privileged activation boundary. The timer executes only a fixed versioned
|
||||
helper and private library closure in `libexec`, never candidate code or
|
||||
libraries below `current`. Runtime activation remains
|
||||
pending until a daemon health commit. Helper passes inside the durable grace
|
||||
period preserve it and prioritize a matching commit; after the deadline an
|
||||
unconfirmed candidate is rolled back. Retention counts only committed healthy
|
||||
versions in addition to the active release.
|
||||
|
||||
First-party URL shorteners ship as immutable bootstrap artifacts in each
|
||||
release. During installation they are copied into
|
||||
`state/plugins/.managed/<id>/versions/<plugin-version>/` and a missing
|
||||
`current` link is initialized. Upgrades add new immutable plugin versions
|
||||
without replacing an existing `current` selection, per-plugin configuration,
|
||||
or plugin data. The
|
||||
operation is idempotent and participates in installer rollback. The service and
|
||||
portable launcher expose only the active release's bundled shared-library
|
||||
directory through `LD_LIBRARY_PATH`; release builds keep `BUILD_SHARED_LIBS=ON`
|
||||
and `ECHOION_STATIC_LINK=OFF`. Installed configurations use the relocatable
|
||||
`./share/echoion/web` asset path; systemd units and the portable launcher set
|
||||
the active release as their working directory. An upgrade rewrites only the
|
||||
exact legacy installer default `./web`; custom web roots remain untouched and
|
||||
the migration participates in transaction rollback.
|
||||
|
||||
Create publishable artifacts from the repository root:
|
||||
|
||||
```bash
|
||||
scripts/release.sh --version 1.2.3
|
||||
```
|
||||
|
||||
For a coordinated pre-publication build, add `--void-source ../VoidLibrary`
|
||||
and `--void-teamspeak-source ../VoidTeamspeak`. Container builds mount these
|
||||
explicit source overrides read-only; published releases use the pinned remote
|
||||
versions.
|
||||
|
||||
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.
|
||||
+813
-28
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,13 @@
|
||||
[Unit]
|
||||
Description=Publish locally staged Echoion runtime updates
|
||||
After=local-fs.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
@SERVICE_IDENTITY@
|
||||
@UPDATER_WORKING_DIRECTORY@
|
||||
@UPDATER_EXEC_START@
|
||||
@UPDATER_HARDENING@
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
UMask=0077
|
||||
@@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=Process staged Echoion runtime update requests
|
||||
|
||||
[Timer]
|
||||
OnBootSec=2m
|
||||
OnUnitActiveSec=5m
|
||||
RandomizedDelaySec=30s
|
||||
Persistent=true
|
||||
Unit=echoion-updater.service
|
||||
|
||||
[Install]
|
||||
@INSTALL_TARGET@
|
||||
@@ -9,7 +9,9 @@ Type=simple
|
||||
@WORKING_DIRECTORY@
|
||||
@ENVIRONMENT_HOME@
|
||||
@ENVIRONMENT_CORE@
|
||||
@ENVIRONMENT_LIBRARY_PATH@
|
||||
@ENVIRONMENT_STATE@
|
||||
@ENVIRONMENT_INCOMING@
|
||||
@EXEC_START@
|
||||
Restart=on-failure
|
||||
RestartSec=5s
|
||||
|
||||
@@ -36,32 +36,28 @@ assert_not_contains() {
|
||||
|
||||
make_payload() {
|
||||
local root=$1
|
||||
install -d -- "$root/bin" "$root/lib" "$root/share/echoion/web" "$root/service"
|
||||
install -d -- "$root/bin" "$root/lib" "$root/share/echoion/web" \
|
||||
"$root/share/echoion/tools" "$root/service" \
|
||||
"$root/share/echoion/bootstrap-plugins/url-shortener-internal/1.0.0" \
|
||||
"$root/share/echoion/bootstrap-plugins/url-shortener-external/1.0.0"
|
||||
install -m 0755 -- "$PACKAGING_DIR/install.sh" "$root/install.sh"
|
||||
install -m 0755 -- "$PACKAGING_DIR/uninstall.sh" "$root/uninstall.sh"
|
||||
install -m 0644 -- "$PACKAGING_DIR/service/echoion.service.in" "$root/service/echoion.service.in"
|
||||
cat > "$root/manifest.json" <<'EOF'
|
||||
{
|
||||
"schemaVersion": 2,
|
||||
"version": "1.2.3",
|
||||
"files": [
|
||||
{"path": "bin/echoiond"}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
install -m 0644 -- "$PACKAGING_DIR/service/echoion-updater.service.in" \
|
||||
"$root/service/echoion-updater.service.in"
|
||||
install -m 0644 -- "$PACKAGING_DIR/service/echoion-updater.timer.in" \
|
||||
"$root/service/echoion-updater.timer.in"
|
||||
install -m 0755 -- "$PACKAGING_DIR/../scripts/validate-release-manifest.py" \
|
||||
"$root/share/echoion/tools/validate-release-manifest.py"
|
||||
cat > "$root/bin/echoiond" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
if [[ ${1:-} == --validate-install && -n ${2:-} ]]; then
|
||||
printf '%s\n' "$2" >> "${VALIDATOR_LOG:?}"
|
||||
if [[ -n ${VALIDATOR_FAIL_PATH:-} && $2 == "$VALIDATOR_FAIL_PATH" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
if [[ ${ALLOW_DAEMON_RUN:-0} == 1 ]]; then
|
||||
printf 'ECHOION_HOME=%s\n' "${ECHOION_HOME:-}" >> "${DAEMON_LOG:?}"
|
||||
printf 'ECHOION_CORE_PATH=%s\n' "${ECHOION_CORE_PATH:-}" >> "$DAEMON_LOG"
|
||||
printf 'ECHOION_STATE_DIR=%s\n' "${ECHOION_STATE_DIR:-}" >> "$DAEMON_LOG"
|
||||
printf 'ECHOION_INCOMING_DIR=%s\n' "${ECHOION_INCOMING_DIR:-}" >> "$DAEMON_LOG"
|
||||
printf 'LD_LIBRARY_PATH=%s\n' "${LD_LIBRARY_PATH:-}" >> "$DAEMON_LOG"
|
||||
printf 'PWD=%s\n' "$PWD" >> "$DAEMON_LOG"
|
||||
argument_index=0
|
||||
for argument in "$@"; do
|
||||
printf 'ARG_%d=%s\n' "$argument_index" "$argument" >> "$DAEMON_LOG"
|
||||
@@ -73,6 +69,12 @@ printf 'daemon unexpectedly ran\n' >> "${DAEMON_LOG:?}"
|
||||
exit 1
|
||||
EOF
|
||||
chmod 0755 "$root/bin/echoiond"
|
||||
cat > "$root/bin/echoion-updater" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
printf 'updater unexpectedly ran\n' >> "${DAEMON_LOG:?}"
|
||||
exit 1
|
||||
EOF
|
||||
chmod 0755 "$root/bin/echoion-updater"
|
||||
printf 'fake dynamic core\n' > "$root/lib/Echoion.ts"
|
||||
cat > "$root/share/echoion/config.example.json" <<'EOF'
|
||||
{
|
||||
@@ -83,6 +85,12 @@ EOF
|
||||
}
|
||||
EOF
|
||||
printf '<!doctype html>\n' > "$root/share/echoion/web/index.html"
|
||||
printf 'fake internal shortener plugin 1.0.0\n' > \
|
||||
"$root/share/echoion/bootstrap-plugins/url-shortener-internal/1.0.0/url-shortener-internal.so"
|
||||
printf 'fake external shortener plugin 1.0.0\n' > \
|
||||
"$root/share/echoion/bootstrap-plugins/url-shortener-external/1.0.0/url-shortener-external.so"
|
||||
python3 "$PACKAGING_DIR/../scripts/generate-release-manifest.py" \
|
||||
--root "$root" --version 1.2.3
|
||||
}
|
||||
|
||||
fake_bin=$TEST_ROOT/fake-bin
|
||||
@@ -96,6 +104,10 @@ printf '%s\n' "$*" >> "${SYSTEMCTL_LOG:?}"
|
||||
if [[ ${SYSTEMCTL_FAIL_RESTART:-0} == 1 && " $* " == *' restart '* ]]; then
|
||||
exit 1
|
||||
fi
|
||||
if [[ ${SYSTEMCTL_FAIL_UPDATER_STOP:-0} == 1 &&
|
||||
" $* " == *' stop echoion-updater.service '* ]]; then
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
EOF
|
||||
chmod 0755 "$fake_bin/systemctl"
|
||||
@@ -114,16 +126,52 @@ export PATH=$fake_bin:$PATH
|
||||
export HOME=$home
|
||||
export XDG_CONFIG_HOME=$home/.config
|
||||
export XDG_STATE_HOME=$home/.state
|
||||
export XDG_CACHE_HOME=$home/.cache
|
||||
export SYSTEMCTL_LOG=$TEST_ROOT/systemctl.log
|
||||
export DAEMON_LOG=$TEST_ROOT/daemon.log
|
||||
export VALIDATOR_LOG=$TEST_ROOT/validator.log
|
||||
: > "$SYSTEMCTL_LOG"
|
||||
: > "$DAEMON_LOG"
|
||||
: > "$VALIDATOR_LOG"
|
||||
|
||||
bash -n "$PACKAGING_DIR/install.sh"
|
||||
bash -n "$PACKAGING_DIR/uninstall.sh"
|
||||
|
||||
escaped_systemd_path=$(
|
||||
# shellcheck source=../install.sh
|
||||
source "$PACKAGING_DIR/install.sh"
|
||||
systemd_path_escape '/srv/echoion path/%/dollar$'
|
||||
)
|
||||
[[ $escaped_systemd_path == '/srv/echoion\x20path/%%/dollar$' ]] ||
|
||||
fail 'systemd path escaping did not preserve space, percent, and dollar characters'
|
||||
escaped_systemd_path_controls=$(
|
||||
# shellcheck source=../install.sh
|
||||
source "$PACKAGING_DIR/install.sh"
|
||||
systemd_path_escape $'/srv/line\ncarriage\rtab\tend'
|
||||
)
|
||||
[[ $escaped_systemd_path_controls == \
|
||||
'/srv/line\x0acarriage\x0dtab\x09end' ]] ||
|
||||
fail 'systemd path escaping emitted a raw control character'
|
||||
escaped_systemd_setting_controls=$(
|
||||
# shellcheck source=../install.sh
|
||||
source "$PACKAGING_DIR/install.sh"
|
||||
systemd_setting_escape $'line\ncarriage\rtab\tend'
|
||||
)
|
||||
[[ $escaped_systemd_setting_controls == 'line\ncarriage\rtab\tend' ]] ||
|
||||
fail 'systemd setting escaping emitted a raw control character'
|
||||
escaped_systemd_exec_dollar=$(
|
||||
# shellcheck source=../install.sh
|
||||
source "$PACKAGING_DIR/install.sh"
|
||||
systemd_exec_escape "/srv/\$HOME/path"
|
||||
)
|
||||
[[ $escaped_systemd_exec_dollar == "/srv/\$\$HOME/path" ]] ||
|
||||
fail 'systemd executable escaping did not protect a literal dollar variable'
|
||||
escaped_json_controls=$(
|
||||
# shellcheck source=../install.sh
|
||||
source "$PACKAGING_DIR/install.sh"
|
||||
json_escape $'line\ncarriage\rtab\tend'
|
||||
)
|
||||
[[ $escaped_json_controls == 'line\ncarriage\rtab\tend' ]] ||
|
||||
fail 'JSON escaping emitted a raw control character'
|
||||
|
||||
trusted_parent=$TEST_ROOT/trusted-parent
|
||||
trusted_prefix=$trusted_parent/echoion
|
||||
install -d -m 0700 -- "$trusted_prefix"
|
||||
@@ -242,13 +290,13 @@ chmod 0640 "$metadata_config/config.json"
|
||||
config_metadata_before=$(stat -c '%u:%g:%a' -- "$metadata_config")
|
||||
state_metadata_before=$(stat -c '%u:%g:%a' -- "$metadata_state")
|
||||
file_metadata_before=$(stat -c '%u:%g:%a' -- "$metadata_config/config.json")
|
||||
export VALIDATOR_FAIL_PATH=$metadata_prefix/versions/1.2.3
|
||||
export RECORD_COMMIT_FAIL=1
|
||||
if "$payload/install.sh" --mode portable --prefix "$metadata_prefix" \
|
||||
--config-dir "$metadata_config" --state-dir "$metadata_state" \
|
||||
--register-service none --non-interactive >/dev/null 2>&1; then
|
||||
fail 'installer accepted injected post-metadata validation failure'
|
||||
fail 'installer accepted injected post-metadata record failure'
|
||||
fi
|
||||
unset VALIDATOR_FAIL_PATH
|
||||
unset RECORD_COMMIT_FAIL
|
||||
config_metadata_after=$(stat -c '%u:%g:%a' -- "$metadata_config")
|
||||
state_metadata_after=$(stat -c '%u:%g:%a' -- "$metadata_state")
|
||||
file_metadata_after=$(stat -c '%u:%g:%a' -- "$metadata_config/config.json")
|
||||
@@ -295,18 +343,39 @@ self_prefix=$TEST_ROOT/self-contained
|
||||
--data-layout self-contained --register-service none --non-interactive
|
||||
[[ $(readlink -- "$self_prefix/current") == versions/1.2.3 ]] || fail 'wrong current target'
|
||||
assert_file "$self_prefix/versions/1.2.3/bin/echoiond"
|
||||
assert_file "$self_prefix/versions/1.2.3/bin/echoion-updater"
|
||||
assert_file "$self_prefix/libexec/updater/1.2.3/bin/echoion-updater"
|
||||
[[ -d $self_prefix/libexec/updater/1.2.3/lib ]] ||
|
||||
fail 'privileged updater has no private dynamic library closure'
|
||||
assert_file "$self_prefix/config/config.json"
|
||||
assert_file "$self_prefix/state/plugins/.managed/url-shortener-internal/versions/1.0.0/url-shortener-internal.so"
|
||||
assert_file "$self_prefix/state/plugins/.managed/url-shortener-external/versions/1.0.0/url-shortener-external.so"
|
||||
[[ -d $self_prefix/state/plugins/.managed/url-shortener-internal/staging ]] ||
|
||||
fail 'internal shortener managed staging directory was not created'
|
||||
[[ $(readlink -- "$self_prefix/state/plugins/.managed/url-shortener-internal/current") == versions/1.0.0 ]] ||
|
||||
fail 'internal shortener bootstrap did not select its bundled version'
|
||||
[[ $(readlink -- "$self_prefix/state/plugins/.managed/url-shortener-external/current") == versions/1.0.0 ]] ||
|
||||
fail 'external shortener bootstrap did not select its bundled version'
|
||||
[[ -d $self_prefix/config/plugins.d ]] ||
|
||||
fail 'per-plugin configuration directory was not created'
|
||||
assert_file "$self_prefix/install.json"
|
||||
[[ -d $self_prefix/state && -d $self_prefix/cache && -d $self_prefix/logs &&
|
||||
-d $self_prefix/incoming ]] || fail 'single-root mutable layout is incomplete'
|
||||
[[ -x $self_prefix/echoion ]] || fail 'portable launcher is not executable'
|
||||
assert_contains "$self_prefix/.echoion-install" 'relocatable=1'
|
||||
assert_contains "$self_prefix/.echoion-install" 'prefix=.'
|
||||
assert_contains "$self_prefix/.echoion-install" 'config_dir=config'
|
||||
assert_contains "$self_prefix/.echoion-install" 'state_dir=data'
|
||||
assert_contains "$self_prefix/.echoion-install" 'state_dir=state'
|
||||
assert_contains "$self_prefix/.echoion-install" 'launcher=echoion'
|
||||
assert_contains "$self_prefix/config/config.json" '"webRoot": "./web"'
|
||||
assert_contains "$self_prefix/.echoion-install" \
|
||||
'updater_helper=libexec/updater/1.2.3/bin/echoion-updater'
|
||||
assert_contains "$self_prefix/install.json" \
|
||||
'"privilegedHelper": "libexec/updater/1.2.3/bin/echoion-updater"'
|
||||
assert_contains "$self_prefix/config/config.json" \
|
||||
'"webRoot": "./share/echoion/web"'
|
||||
assert_not_contains "$self_prefix/config/config.json" "$self_prefix/current"
|
||||
[[ ! -s $SYSTEMCTL_LOG ]] || fail 'service command ran for register-service none'
|
||||
[[ ! -s $DAEMON_LOG ]] || fail 'daemon ran during installation'
|
||||
assert_contains "$VALIDATOR_LOG" "$self_prefix/versions/1.2.3"
|
||||
self_moved_prefix=$TEST_ROOT/self-contained-moved
|
||||
mv -- "$self_prefix" "$self_moved_prefix"
|
||||
assert_not_exists "$self_prefix"
|
||||
@@ -314,11 +383,15 @@ assert_not_exists "$self_prefix"
|
||||
ALLOW_DAEMON_RUN=1 "$self_moved_prefix/echoion" --probe 'two words'
|
||||
assert_contains "$DAEMON_LOG" "ECHOION_HOME=$self_moved_prefix/current"
|
||||
assert_contains "$DAEMON_LOG" "ECHOION_CORE_PATH=$self_moved_prefix/current/lib/Echoion.ts"
|
||||
assert_contains "$DAEMON_LOG" "ECHOION_STATE_DIR=$self_moved_prefix/data"
|
||||
assert_contains "$DAEMON_LOG" "ECHOION_STATE_DIR=$self_moved_prefix/state"
|
||||
assert_contains "$DAEMON_LOG" "ECHOION_INCOMING_DIR=$self_moved_prefix/incoming"
|
||||
assert_contains "$DAEMON_LOG" \
|
||||
"LD_LIBRARY_PATH=$self_moved_prefix/current/lib"
|
||||
assert_contains "$DAEMON_LOG" "PWD=$self_moved_prefix/current"
|
||||
assert_contains "$DAEMON_LOG" 'ARG_0=--config'
|
||||
assert_contains "$DAEMON_LOG" "ARG_1=$self_moved_prefix/config/config.json"
|
||||
assert_contains "$DAEMON_LOG" 'ARG_2=--state-dir'
|
||||
assert_contains "$DAEMON_LOG" "ARG_3=$self_moved_prefix/data"
|
||||
assert_contains "$DAEMON_LOG" "ARG_3=$self_moved_prefix/state"
|
||||
assert_contains "$DAEMON_LOG" 'ARG_4=--probe'
|
||||
assert_contains "$DAEMON_LOG" 'ARG_5=two words'
|
||||
: > "$DAEMON_LOG"
|
||||
@@ -370,49 +443,250 @@ assert_not_exists "$custom_prefix"
|
||||
assert_not_exists "$custom_config"
|
||||
assert_not_exists "$custom_state"
|
||||
|
||||
unit=$XDG_CONFIG_HOME/systemd/user/echoion.service
|
||||
updater_unit=$XDG_CONFIG_HOME/systemd/user/echoion-updater.service
|
||||
updater_timer=$XDG_CONFIG_HOME/systemd/user/echoion-updater.timer
|
||||
self_service_prefix=$TEST_ROOT/portable-self-contained-service
|
||||
: > "$SYSTEMCTL_LOG"
|
||||
: > "$DAEMON_LOG"
|
||||
"$payload/install.sh" --mode portable --prefix "$self_service_prefix" \
|
||||
--data-layout self-contained --register-service user --non-interactive
|
||||
assert_file "$unit"
|
||||
assert_file "$updater_unit"
|
||||
assert_file "$updater_timer"
|
||||
assert_file "$self_service_prefix/config/config.json"
|
||||
[[ -d $self_service_prefix/state && -d $self_service_prefix/cache &&
|
||||
-d $self_service_prefix/logs && -d $self_service_prefix/incoming ]] ||
|
||||
fail 'self-contained service mutable layout escaped the portable prefix'
|
||||
assert_contains "$unit" "WorkingDirectory=$self_service_prefix/current"
|
||||
assert_contains "$unit" "Environment=\"ECHOION_STATE_DIR=$self_service_prefix/state\""
|
||||
assert_contains "$unit" \
|
||||
"Environment=\"ECHOION_INCOMING_DIR=$self_service_prefix/incoming\""
|
||||
assert_contains "$unit" \
|
||||
"Environment=\"LD_LIBRARY_PATH=$self_service_prefix/current/lib\""
|
||||
assert_contains "$unit" \
|
||||
"--config \"$self_service_prefix/config/config.json\" --state-dir \"$self_service_prefix/state\""
|
||||
assert_contains "$updater_unit" \
|
||||
"WorkingDirectory=$self_service_prefix"
|
||||
assert_contains "$SYSTEMCTL_LOG" '--user daemon-reload'
|
||||
assert_contains "$SYSTEMCTL_LOG" '--user stop echoion-updater.service'
|
||||
assert_contains "$SYSTEMCTL_LOG" \
|
||||
'--user disable --now echoion.service echoion-updater.timer'
|
||||
if grep -E -- '(^| )(enable|restart|start)( |$)' "$SYSTEMCTL_LOG" >/dev/null; then
|
||||
fail 'self-contained portable service was activated without --start'
|
||||
fi
|
||||
[[ ! -s $DAEMON_LOG ]] ||
|
||||
fail 'daemon or updater ran during self-contained service registration'
|
||||
"$self_service_prefix/uninstall.sh" --purge --non-interactive >/dev/null
|
||||
assert_not_exists "$unit"
|
||||
assert_not_exists "$updater_unit"
|
||||
assert_not_exists "$updater_timer"
|
||||
assert_not_exists "$self_service_prefix"
|
||||
|
||||
service_prefix="$TEST_ROOT/portable path % dollar\$"
|
||||
: > "$SYSTEMCTL_LOG"
|
||||
"$payload/install.sh" --mode portable --prefix "$service_prefix" \
|
||||
--data-layout standard --register-service user --non-interactive
|
||||
unit=$XDG_CONFIG_HOME/systemd/user/echoion.service
|
||||
assert_file "$unit"
|
||||
assert_contains "$unit" 'WorkingDirectory="'
|
||||
assert_contains "$unit" 'portable path %% dollar$/current"'
|
||||
assert_file "$updater_unit"
|
||||
assert_file "$updater_timer"
|
||||
assert_contains "$unit" 'WorkingDirectory='
|
||||
assert_not_contains "$unit" 'WorkingDirectory="'
|
||||
assert_contains "$unit" 'portable\x20path\x20%%\x20dollar$/current'
|
||||
assert_contains "$unit" 'ExecStart="'
|
||||
assert_contains "$unit" 'portable path %% dollar$$/current/bin/echoiond"'
|
||||
assert_contains "$unit" 'Environment="ECHOION_HOME='
|
||||
assert_contains "$unit" 'Environment="ECHOION_CORE_PATH='
|
||||
assert_contains "$unit" 'Environment="ECHOION_STATE_DIR='
|
||||
assert_contains "$unit" 'Environment="ECHOION_INCOMING_DIR='
|
||||
assert_contains "$unit" 'Environment="LD_LIBRARY_PATH='
|
||||
assert_contains "$unit" '--config "'
|
||||
assert_contains "$unit" '--state-dir "'
|
||||
assert_contains "$updater_unit" \
|
||||
'portable path %% dollar$$/libexec/updater/1.2.3/bin/echoion-updater"'
|
||||
assert_not_contains "$updater_unit" '/current/bin/echoion-updater'
|
||||
assert_contains "$updater_unit" \
|
||||
'WorkingDirectory='"$TEST_ROOT"'/portable\x20path\x20%%\x20dollar$'
|
||||
assert_not_contains "$updater_unit" 'WorkingDirectory="'
|
||||
if grep -E '@[A-Z_]+@' "$unit" >/dev/null; then
|
||||
fail 'generated systemd unit contains an unresolved template marker'
|
||||
fi
|
||||
if grep -E '@[A-Z_]+@' "$updater_unit" "$updater_timer" >/dev/null; then
|
||||
fail 'generated updater unit contains an unresolved template marker'
|
||||
fi
|
||||
if command -v systemd-analyze >/dev/null 2>&1; then
|
||||
verify_log=$TEST_ROOT/systemd-verify.log
|
||||
if ! systemd-analyze verify "$unit" 2> "$verify_log" &&
|
||||
grep -E 'echoion\.service:|Failed to load unit' "$verify_log" >/dev/null; then
|
||||
if ! systemd-analyze verify "$unit" "$updater_unit" "$updater_timer" \
|
||||
2> "$verify_log" &&
|
||||
grep -E 'not absolute|Unknown escape|Failed to parse|Invalid argument|fatal error|bad unit file setting|Failed to load unit' \
|
||||
"$verify_log" >/dev/null; then
|
||||
cat "$verify_log" >&2
|
||||
fail 'generated systemd unit did not verify'
|
||||
fail 'generated systemd units did not verify'
|
||||
fi
|
||||
fi
|
||||
assert_contains "$SYSTEMCTL_LOG" '--user daemon-reload'
|
||||
assert_contains "$SYSTEMCTL_LOG" '--user stop echoion-updater.service'
|
||||
assert_contains "$SYSTEMCTL_LOG" '--user disable --now echoion.service'
|
||||
if grep -E -- '(^| )enable( |$)|(^| )restart( |$)' "$SYSTEMCTL_LOG" >/dev/null; then
|
||||
fail 'service was activated without --start'
|
||||
fi
|
||||
[[ ! -s $DAEMON_LOG ]] || fail 'daemon ran during service registration'
|
||||
|
||||
command -v fakeroot >/dev/null 2>&1 ||
|
||||
fail 'fakeroot is required for rootless system-service installer coverage'
|
||||
system_fake_bin=$TEST_ROOT/system-fake-bin
|
||||
system_payload=$TEST_ROOT/system-payload
|
||||
system_service_prefix="$TEST_ROOT/portable system % dollar\$"
|
||||
system_unit_root=$TEST_ROOT/systemd/system
|
||||
install -d -- "$system_fake_bin" "$system_service_prefix" "$system_unit_root"
|
||||
make_payload "$system_payload"
|
||||
sed -i "s#/etc/systemd/system#$system_unit_root#g" \
|
||||
"$system_payload/install.sh"
|
||||
python3 "$PACKAGING_DIR/../scripts/generate-release-manifest.py" \
|
||||
--root "$system_payload" --version 1.2.3
|
||||
|
||||
REAL_CHOWN=$(command -v chown)
|
||||
REAL_CP=$(command -v cp)
|
||||
REAL_GETENT=$(command -v getent)
|
||||
REAL_ID=$(command -v id)
|
||||
export REAL_CHOWN REAL_CP REAL_GETENT REAL_ID
|
||||
export SYSTEM_SERVICE_PREFIX=$system_service_prefix
|
||||
cat > "$system_fake_bin/chown" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
arguments=()
|
||||
for argument in "$@"; do
|
||||
case $argument in
|
||||
echoion:echoion) arguments+=(4242:4242) ;;
|
||||
root:echoion) arguments+=(0:4242) ;;
|
||||
*) arguments+=("$argument") ;;
|
||||
esac
|
||||
done
|
||||
"${REAL_CHOWN:?}" "${arguments[@]}" 2>/dev/null || true
|
||||
EOF
|
||||
cat > "$system_fake_bin/cp" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
arguments=()
|
||||
for argument in "$@"; do
|
||||
if [[ $argument == -a ]]; then
|
||||
arguments+=(-R --preserve=mode,timestamps,links)
|
||||
else
|
||||
arguments+=("$argument")
|
||||
fi
|
||||
done
|
||||
exec "${REAL_CP:?}" "${arguments[@]}"
|
||||
EOF
|
||||
cat > "$system_fake_bin/getent" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
case ${1:-}:${2:-} in
|
||||
passwd:echoion) printf 'echoion:x:4242:4242::/nonexistent:/usr/sbin/nologin\n' ;;
|
||||
group:echoion) printf 'echoion:x:4242:\n' ;;
|
||||
*) exec "${REAL_GETENT:?}" "$@" ;;
|
||||
esac
|
||||
EOF
|
||||
cat > "$system_fake_bin/id" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
case ${1:-}:${2:-} in
|
||||
-u:echoion | -g:echoion) printf '4242\n' ;;
|
||||
*) exec "${REAL_ID:?}" "$@" ;;
|
||||
esac
|
||||
EOF
|
||||
cat > "$system_fake_bin/runuser" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
[[ ${1:-} == -u && ${2:-} == echoion && ${3:-} == -- ]] || exit 64
|
||||
shift 3
|
||||
if [[ ${1:-} == find ]]; then
|
||||
exit 0
|
||||
fi
|
||||
if [[ ${1:-} == test && ${2:-} == -w ]]; then
|
||||
case ${3:-} in
|
||||
"${SYSTEM_SERVICE_PREFIX:?}/state" | "${SYSTEM_SERVICE_PREFIX:?}/state"/* | \
|
||||
"${SYSTEM_SERVICE_PREFIX:?}/cache" | "${SYSTEM_SERVICE_PREFIX:?}/logs" | \
|
||||
"${SYSTEM_SERVICE_PREFIX:?}/incoming") exit 0 ;;
|
||||
*) exit 1 ;;
|
||||
esac
|
||||
fi
|
||||
exec "$@"
|
||||
EOF
|
||||
chmod 0755 "$system_fake_bin/chown" "$system_fake_bin/cp" \
|
||||
"$system_fake_bin/getent" "$system_fake_bin/id" "$system_fake_bin/runuser"
|
||||
|
||||
: > "$SYSTEMCTL_LOG"
|
||||
: > "$DAEMON_LOG"
|
||||
# shellcheck disable=SC2016 # Expanded by the fakeroot child shell.
|
||||
SYSTEM_PAYLOAD=$system_payload PATH=$system_fake_bin:$PATH fakeroot -- \
|
||||
bash -euo pipefail -c '
|
||||
current=${SYSTEM_SERVICE_PREFIX:?}
|
||||
while :; do
|
||||
chown root:root -- "$current"
|
||||
[[ $current == / ]] && break
|
||||
current=$(dirname -- "$current")
|
||||
done
|
||||
"${SYSTEM_PAYLOAD:?}/install.sh" --mode portable \
|
||||
--prefix "$SYSTEM_SERVICE_PREFIX" --data-layout self-contained \
|
||||
--register-service system --non-interactive
|
||||
'
|
||||
system_unit=$system_unit_root/echoion.service
|
||||
system_updater_unit=$system_unit_root/echoion-updater.service
|
||||
system_updater_timer=$system_unit_root/echoion-updater.timer
|
||||
assert_file "$system_unit"
|
||||
assert_file "$system_updater_unit"
|
||||
assert_file "$system_updater_timer"
|
||||
assert_contains "$system_unit" 'User=echoion'
|
||||
assert_contains "$system_unit" 'Group=echoion'
|
||||
assert_contains "$system_unit" 'WantedBy=multi-user.target'
|
||||
assert_contains "$system_unit" \
|
||||
'portable\x20system\x20%%\x20dollar$/current'
|
||||
assert_not_contains "$system_unit" 'WorkingDirectory="'
|
||||
assert_contains "$system_updater_unit" \
|
||||
'WorkingDirectory='"$TEST_ROOT"'/portable\x20system\x20%%\x20dollar$'
|
||||
assert_contains "$system_updater_unit" 'ReadWritePaths='
|
||||
assert_contains "$system_updater_unit" \
|
||||
'portable\x20system\x20%%\x20dollar$'
|
||||
assert_not_contains "$system_updater_unit" 'ReadWritePaths="'
|
||||
assert_contains "$SYSTEMCTL_LOG" 'daemon-reload'
|
||||
assert_contains "$SYSTEMCTL_LOG" 'stop echoion-updater.service'
|
||||
assert_contains "$SYSTEMCTL_LOG" \
|
||||
'disable --now echoion.service echoion-updater.timer'
|
||||
assert_not_contains "$SYSTEMCTL_LOG" '--user'
|
||||
if grep -E -- '(^| )(enable|restart|start)( |$)' "$SYSTEMCTL_LOG" >/dev/null; then
|
||||
fail 'portable system service was activated without --start'
|
||||
fi
|
||||
[[ ! -s $DAEMON_LOG ]] ||
|
||||
fail 'daemon or updater ran during portable system service registration'
|
||||
if command -v systemd-analyze >/dev/null 2>&1; then
|
||||
verify_log=$TEST_ROOT/system-systemd-verify.log
|
||||
if ! systemd-analyze verify "$system_unit" "$system_updater_unit" \
|
||||
"$system_updater_timer" 2> "$verify_log" &&
|
||||
grep -E 'not absolute|Unknown escape|Failed to parse|Invalid argument|fatal error|bad unit file setting|Failed to load unit' \
|
||||
"$verify_log" >/dev/null; then
|
||||
cat "$verify_log" >&2
|
||||
fail 'generated system-scope systemd units did not verify'
|
||||
fi
|
||||
fi
|
||||
|
||||
: > "$SYSTEMCTL_LOG"
|
||||
"$payload/install.sh" --mode portable --prefix "$service_prefix" \
|
||||
--data-layout standard --register-service user --start --non-interactive
|
||||
assert_contains "$SYSTEMCTL_LOG" '--user enable echoion.service'
|
||||
assert_contains "$SYSTEMCTL_LOG" 'echoion-updater.timer'
|
||||
assert_contains "$SYSTEMCTL_LOG" '--user restart echoion.service'
|
||||
assert_contains "$SYSTEMCTL_LOG" '--user start echoion-updater.timer'
|
||||
assert_contains "$SYSTEMCTL_LOG" '--user is-active --quiet echoion.service'
|
||||
|
||||
: > "$SYSTEMCTL_LOG"
|
||||
export SYSTEMCTL_FAIL_UPDATER_STOP=1
|
||||
if "$service_prefix/uninstall.sh" --non-interactive >/dev/null 2>&1; then
|
||||
fail 'uninstaller continued after the updater service could not be stopped'
|
||||
fi
|
||||
unset SYSTEMCTL_FAIL_UPDATER_STOP
|
||||
assert_file "$service_prefix/current/bin/echoiond"
|
||||
assert_file "$unit"
|
||||
: > "$SYSTEMCTL_LOG"
|
||||
"$service_prefix/uninstall.sh" --non-interactive
|
||||
assert_contains "$SYSTEMCTL_LOG" '--user stop echoion-updater.service'
|
||||
assert_not_exists "$unit"
|
||||
assert_not_exists "$updater_unit"
|
||||
assert_not_exists "$updater_timer"
|
||||
assert_not_exists "$service_prefix/versions"
|
||||
assert_file "$XDG_CONFIG_HOME/echoion/config.json"
|
||||
[[ -d $XDG_STATE_HOME/echoion ]] || fail 'state directory was not preserved'
|
||||
@@ -444,12 +718,96 @@ rollback_prefix=$TEST_ROOT/rollback
|
||||
--register-service user --non-interactive >/dev/null
|
||||
old_unit_hash=$(sha256sum -- "$unit")
|
||||
old_unit_hash=${old_unit_hash%% *}
|
||||
old_updater_helper_hash=$(sha256sum -- \
|
||||
"$rollback_prefix/libexec/updater/1.2.3/bin/echoion-updater")
|
||||
old_updater_helper_hash=${old_updater_helper_hash%% *}
|
||||
upgrade_payload=$TEST_ROOT/upgrade-payload
|
||||
cp -a -- "$payload" "$upgrade_payload"
|
||||
sed -i 's/"version": "1.2.3"/"version": "1.2.4"/' "$upgrade_payload/manifest.json"
|
||||
for plugin_id in url-shortener-internal url-shortener-external; do
|
||||
mv -- "$upgrade_payload/share/echoion/bootstrap-plugins/$plugin_id/1.0.0" \
|
||||
"$upgrade_payload/share/echoion/bootstrap-plugins/$plugin_id/1.1.0"
|
||||
printf 'fake %s plugin 1.1.0\n' "$plugin_id" > \
|
||||
"$upgrade_payload/share/echoion/bootstrap-plugins/$plugin_id/1.1.0/$plugin_id.so"
|
||||
done
|
||||
printf '# changed in 1.2.4\n' >> "$upgrade_payload/service/echoion.service.in"
|
||||
printf '# changed installer helper in 1.2.4\n' >> "$upgrade_payload/install.sh"
|
||||
printf '# changed uninstaller helper in 1.2.4\n' >> "$upgrade_payload/uninstall.sh"
|
||||
printf '# changed privileged updater helper in 1.2.4\n' >> \
|
||||
"$upgrade_payload/bin/echoion-updater"
|
||||
python3 "$PACKAGING_DIR/../scripts/generate-release-manifest.py" \
|
||||
--root "$upgrade_payload" --version 1.2.4
|
||||
|
||||
bootstrap_upgrade_prefix=$TEST_ROOT/bootstrap-upgrade
|
||||
"$payload/install.sh" --mode portable --prefix "$bootstrap_upgrade_prefix" \
|
||||
--register-service none --non-interactive >/dev/null
|
||||
install -d -- \
|
||||
"$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-internal/versions/9.0.0" \
|
||||
"$bootstrap_upgrade_prefix/state/plugins/data/url-shortener-internal"
|
||||
printf 'custom internal plugin\n' > \
|
||||
"$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-internal/versions/9.0.0/url-shortener-internal.so"
|
||||
rm -f -- \
|
||||
"$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-internal/current"
|
||||
ln -s -- versions/9.0.0 \
|
||||
"$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-internal/current"
|
||||
printf '{"allowHttp":false}\n' > \
|
||||
"$bootstrap_upgrade_prefix/config/plugins.d/url-shortener-internal.json"
|
||||
printf 'persistent sqlite bytes\n' > \
|
||||
"$bootstrap_upgrade_prefix/state/plugins/data/url-shortener-internal/links.db"
|
||||
"$upgrade_payload/install.sh" --mode portable --prefix "$bootstrap_upgrade_prefix" \
|
||||
--register-service none --non-interactive >/dev/null
|
||||
# Installing the exact release twice must be a no-op for managed plugin state.
|
||||
"$upgrade_payload/install.sh" --mode portable --prefix "$bootstrap_upgrade_prefix" \
|
||||
--register-service none --non-interactive >/dev/null
|
||||
[[ $(readlink -- "$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-internal/current") == versions/9.0.0 ]] ||
|
||||
fail 'upgrade replaced a custom active internal shortener version'
|
||||
[[ $(readlink -- "$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-external/current") == versions/1.0.0 ]] ||
|
||||
fail 'upgrade changed an existing external shortener selection'
|
||||
assert_file "$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-internal/versions/1.1.0/url-shortener-internal.so"
|
||||
assert_file "$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-external/versions/1.1.0/url-shortener-external.so"
|
||||
assert_contains \
|
||||
"$bootstrap_upgrade_prefix/config/plugins.d/url-shortener-internal.json" \
|
||||
'"allowHttp":false'
|
||||
assert_contains \
|
||||
"$bootstrap_upgrade_prefix/state/plugins/data/url-shortener-internal/links.db" \
|
||||
'persistent sqlite bytes'
|
||||
"$bootstrap_upgrade_prefix/uninstall.sh" --purge --non-interactive >/dev/null
|
||||
assert_not_exists "$bootstrap_upgrade_prefix"
|
||||
|
||||
missing_plugin_current_prefix=$TEST_ROOT/missing-plugin-current
|
||||
"$payload/install.sh" --mode portable --prefix "$missing_plugin_current_prefix" \
|
||||
--register-service none --non-interactive >/dev/null
|
||||
rm -f -- \
|
||||
"$missing_plugin_current_prefix/state/plugins/.managed/url-shortener-internal/current"
|
||||
sed -i 's#\./share/echoion/web#./web#' \
|
||||
"$missing_plugin_current_prefix/config/config.json"
|
||||
export RECORD_COMMIT_FAIL=1
|
||||
if "$payload/install.sh" --mode portable --prefix "$missing_plugin_current_prefix" \
|
||||
--register-service none --non-interactive >/dev/null 2>&1; then
|
||||
fail 'missing plugin selection upgrade accepted a failed record commit'
|
||||
fi
|
||||
unset RECORD_COMMIT_FAIL
|
||||
assert_not_exists \
|
||||
"$missing_plugin_current_prefix/state/plugins/.managed/url-shortener-internal/current"
|
||||
assert_contains "$missing_plugin_current_prefix/config/config.json" \
|
||||
'"webRoot": "./web"'
|
||||
"$payload/install.sh" --mode portable --prefix "$missing_plugin_current_prefix" \
|
||||
--register-service none --non-interactive >/dev/null
|
||||
[[ $(readlink -- \
|
||||
"$missing_plugin_current_prefix/state/plugins/.managed/url-shortener-internal/current") == \
|
||||
versions/1.0.0 ]] ||
|
||||
fail 'reinstall did not initialize a missing managed plugin selection'
|
||||
assert_contains "$missing_plugin_current_prefix/config/config.json" \
|
||||
'"webRoot": "./share/echoion/web"'
|
||||
sed -i 's#\./share/echoion/web#/srv/custom-echoion-web#' \
|
||||
"$missing_plugin_current_prefix/config/config.json"
|
||||
"$payload/install.sh" --mode portable --prefix "$missing_plugin_current_prefix" \
|
||||
--register-service none --non-interactive >/dev/null
|
||||
assert_contains "$missing_plugin_current_prefix/config/config.json" \
|
||||
'"webRoot": "/srv/custom-echoion-web"'
|
||||
"$missing_plugin_current_prefix/uninstall.sh" --purge --non-interactive >/dev/null
|
||||
assert_not_exists "$missing_plugin_current_prefix"
|
||||
|
||||
export SYSTEMCTL_FAIL_RESTART=1
|
||||
if "$upgrade_payload/install.sh" --mode portable --prefix "$rollback_prefix" \
|
||||
--register-service user --start --non-interactive >/dev/null 2>&1; then
|
||||
@@ -461,7 +819,14 @@ unset SYSTEMCTL_FAIL_RESTART
|
||||
restored_unit_hash=$(sha256sum -- "$unit")
|
||||
restored_unit_hash=${restored_unit_hash%% *}
|
||||
[[ $restored_unit_hash == "$old_unit_hash" ]] || fail 'failed upgrade did not restore unit bytes'
|
||||
restored_updater_helper_hash=$(sha256sum -- \
|
||||
"$rollback_prefix/libexec/updater/1.2.3/bin/echoion-updater")
|
||||
restored_updater_helper_hash=${restored_updater_helper_hash%% *}
|
||||
[[ $restored_updater_helper_hash == "$old_updater_helper_hash" ]] ||
|
||||
fail 'failed upgrade did not restore the privileged updater helper'
|
||||
assert_contains "$rollback_prefix/.echoion-install" 'version=1.2.3'
|
||||
assert_not_exists \
|
||||
"$rollback_prefix/state/plugins/.managed/url-shortener-internal/versions/1.1.0"
|
||||
"$rollback_prefix/uninstall.sh" --non-interactive >/dev/null
|
||||
|
||||
record_rollback_prefix=$TEST_ROOT/record-rollback
|
||||
@@ -473,6 +838,9 @@ record_old_install_hash=$(sha256sum -- "$record_rollback_prefix/install.sh")
|
||||
record_old_install_hash=${record_old_install_hash%% *}
|
||||
record_old_uninstall_hash=$(sha256sum -- "$record_rollback_prefix/uninstall.sh")
|
||||
record_old_uninstall_hash=${record_old_uninstall_hash%% *}
|
||||
record_old_updater_helper_hash=$(sha256sum -- \
|
||||
"$record_rollback_prefix/libexec/updater/1.2.3/bin/echoion-updater")
|
||||
record_old_updater_helper_hash=${record_old_updater_helper_hash%% *}
|
||||
export RECORD_COMMIT_FAIL=1
|
||||
if "$upgrade_payload/install.sh" --mode portable --prefix "$record_rollback_prefix" \
|
||||
--register-service user --non-interactive >/dev/null 2>&1; then
|
||||
@@ -487,6 +855,8 @@ record_restored_unit_hash=${record_restored_unit_hash%% *}
|
||||
fail 'record-commit failure did not restore unit bytes'
|
||||
assert_contains "$record_rollback_prefix/.echoion-install" 'version=1.2.3'
|
||||
assert_not_exists "$record_rollback_prefix/versions/1.2.4"
|
||||
assert_not_exists \
|
||||
"$record_rollback_prefix/state/plugins/.managed/url-shortener-internal/versions/1.1.0"
|
||||
record_restored_install_hash=$(sha256sum -- "$record_rollback_prefix/install.sh")
|
||||
record_restored_install_hash=${record_restored_install_hash%% *}
|
||||
record_restored_uninstall_hash=$(sha256sum -- "$record_rollback_prefix/uninstall.sh")
|
||||
@@ -495,6 +865,11 @@ record_restored_uninstall_hash=${record_restored_uninstall_hash%% *}
|
||||
fail 'record-commit failure did not restore installer helper bytes'
|
||||
[[ $record_restored_uninstall_hash == "$record_old_uninstall_hash" ]] ||
|
||||
fail 'record-commit failure did not restore uninstaller helper bytes'
|
||||
record_restored_updater_helper_hash=$(sha256sum -- \
|
||||
"$record_rollback_prefix/libexec/updater/1.2.3/bin/echoion-updater")
|
||||
record_restored_updater_helper_hash=${record_restored_updater_helper_hash%% *}
|
||||
[[ $record_restored_updater_helper_hash == "$record_old_updater_helper_hash" ]] ||
|
||||
fail 'record-commit failure did not restore privileged updater helper bytes'
|
||||
"$record_rollback_prefix/uninstall.sh" --non-interactive >/dev/null
|
||||
|
||||
scope_rollback_prefix=$TEST_ROOT/scope-rollback
|
||||
@@ -516,6 +891,8 @@ scope_restored_unit_hash=${scope_restored_unit_hash%% *}
|
||||
[[ $(readlink -- "$scope_rollback_prefix/current") == versions/1.2.3 ]] ||
|
||||
fail 'scope migration failure did not restore current'
|
||||
assert_contains "$scope_rollback_prefix/.echoion-install" 'service_scope=user'
|
||||
assert_not_exists \
|
||||
"$scope_rollback_prefix/state/plugins/.managed/url-shortener-internal/versions/1.1.0"
|
||||
"$scope_rollback_prefix/uninstall.sh" --non-interactive >/dev/null
|
||||
|
||||
tamper_prefix=$TEST_ROOT/tamper
|
||||
@@ -528,6 +905,27 @@ fi
|
||||
assert_file "$unit"
|
||||
rm -f -- "$unit"
|
||||
|
||||
helper_tamper_prefix=$TEST_ROOT/helper-tamper
|
||||
"$payload/install.sh" --mode portable --prefix "$helper_tamper_prefix" \
|
||||
--register-service none --non-interactive >/dev/null
|
||||
printf '# local change\n' >> \
|
||||
"$helper_tamper_prefix/libexec/updater/1.2.3/bin/echoion-updater"
|
||||
if "$helper_tamper_prefix/uninstall.sh" --non-interactive >/dev/null 2>&1; then
|
||||
fail 'uninstaller removed a modified privileged updater helper'
|
||||
fi
|
||||
assert_file "$helper_tamper_prefix/libexec/updater/1.2.3/bin/echoion-updater"
|
||||
|
||||
unrecognized_helper_prefix=$TEST_ROOT/unrecognized-helper
|
||||
install -d -- "$unrecognized_helper_prefix/libexec/updater/1.2.3/bin"
|
||||
printf '#!/bin/sh\nexit 0\n' > \
|
||||
"$unrecognized_helper_prefix/libexec/updater/1.2.3/bin/echoion-updater"
|
||||
chmod 0755 \
|
||||
"$unrecognized_helper_prefix/libexec/updater/1.2.3/bin/echoion-updater"
|
||||
if "$payload/install.sh" --mode portable --prefix "$unrecognized_helper_prefix" \
|
||||
--register-service none --non-interactive >/dev/null 2>&1; then
|
||||
fail 'installer overwrote an unrecognized privileged updater helper'
|
||||
fi
|
||||
|
||||
if "$payload/install.sh" --mode portable --prefix "/tmp/echoion-installer-test-$$" \
|
||||
--register-service user --non-interactive >/dev/null 2>&1; then
|
||||
fail 'temporary portable service prefix was accepted'
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
#!/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"
|
||||
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"
|
||||
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"
|
||||
+92
-4
@@ -3,8 +3,11 @@ set -euo pipefail
|
||||
|
||||
PROGRAM=${0##*/}
|
||||
SERVICE_NAME=echoion.service
|
||||
UPDATER_SERVICE_NAME=echoion-updater.service
|
||||
UPDATER_TIMER_NAME=echoion-updater.timer
|
||||
SERVICE_USER=echoion
|
||||
RECORD_NAME=.echoion-install
|
||||
JSON_RECORD_NAME=install.json
|
||||
MANAGED_MARKER=.echoion-managed
|
||||
|
||||
die() {
|
||||
@@ -54,7 +57,11 @@ safe_unit_path() {
|
||||
[[ $unit == /* && $unit != *'/../'* && $unit != *'/./'* ]] || return 1
|
||||
case $scope:$unit in
|
||||
system:/etc/systemd/system/echoion.service) return 0 ;;
|
||||
system:/etc/systemd/system/echoion-updater.service) return 0 ;;
|
||||
system:/etc/systemd/system/echoion-updater.timer) return 0 ;;
|
||||
user:/*/systemd/user/echoion.service) return 0 ;;
|
||||
user:/*/systemd/user/echoion-updater.service) return 0 ;;
|
||||
user:/*/systemd/user/echoion-updater.timer) return 0 ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
@@ -144,8 +151,17 @@ relocatable=0
|
||||
service_scope=none
|
||||
service_unit=
|
||||
service_unit_sha256=
|
||||
updater_service_unit=
|
||||
updater_service_unit_sha256=
|
||||
updater_timer_unit=
|
||||
updater_timer_unit_sha256=
|
||||
updater_helper=
|
||||
updater_helper_sha256=
|
||||
config_dir=
|
||||
state_dir=
|
||||
cache_dir=
|
||||
logs_dir=
|
||||
incoming_dir=
|
||||
mode=
|
||||
data_layout=
|
||||
launcher=
|
||||
@@ -175,8 +191,17 @@ while IFS='=' read -r key value; do
|
||||
service_scope) service_scope=$value ;;
|
||||
service_unit) service_unit=$value ;;
|
||||
service_unit_sha256) service_unit_sha256=$value ;;
|
||||
updater_service_unit) updater_service_unit=$value ;;
|
||||
updater_service_unit_sha256) updater_service_unit_sha256=$value ;;
|
||||
updater_timer_unit) updater_timer_unit=$value ;;
|
||||
updater_timer_unit_sha256) updater_timer_unit_sha256=$value ;;
|
||||
updater_helper) updater_helper=$value ;;
|
||||
updater_helper_sha256) updater_helper_sha256=$value ;;
|
||||
config_dir) config_dir=$value ;;
|
||||
state_dir) state_dir=$value ;;
|
||||
cache_dir) cache_dir=$value ;;
|
||||
logs_dir) logs_dir=$value ;;
|
||||
incoming_dir) incoming_dir=$value ;;
|
||||
mode) mode=$value ;;
|
||||
data_layout) data_layout=$value ;;
|
||||
launcher) launcher=$value ;;
|
||||
@@ -208,10 +233,17 @@ case $relocatable in
|
||||
1)
|
||||
[[ $record_prefix == . && $mode == portable && $data_layout == self-contained ]] ||
|
||||
die "relocatable install record is incomplete or unsafe"
|
||||
[[ $config_dir == config && $state_dir == data ]] ||
|
||||
[[ $config_dir == config && ( $state_dir == state || $state_dir == data ) ]] ||
|
||||
die "relocatable install record has unsafe mutable paths"
|
||||
config_dir=$prefix/config
|
||||
state_dir=$prefix/data
|
||||
state_dir=$prefix/$state_dir
|
||||
if [[ -n $cache_dir || -n $logs_dir || -n $incoming_dir ]]; then
|
||||
[[ $cache_dir == cache && $logs_dir == logs && $incoming_dir == incoming ]] ||
|
||||
die "relocatable install record has unsafe auxiliary paths"
|
||||
cache_dir=$prefix/cache
|
||||
logs_dir=$prefix/logs
|
||||
incoming_dir=$prefix/incoming
|
||||
fi
|
||||
;;
|
||||
*) die "install record has an invalid relocatable value" ;;
|
||||
esac
|
||||
@@ -236,6 +268,44 @@ if [[ $service_scope != none ]]; then
|
||||
[[ -f $service_unit ]] || die "registered service unit is missing: $service_unit"
|
||||
[[ $(sha256_file "$service_unit") == "$service_unit_sha256" ]] ||
|
||||
die "service unit was modified; refusing to remove it: $service_unit"
|
||||
for updater_record in service timer; do
|
||||
if [[ $updater_record == service ]]; then
|
||||
updater_unit=$updater_service_unit
|
||||
updater_hash=$updater_service_unit_sha256
|
||||
else
|
||||
updater_unit=$updater_timer_unit
|
||||
updater_hash=$updater_timer_unit_sha256
|
||||
fi
|
||||
if [[ -n $updater_unit || -n $updater_hash ]]; then
|
||||
[[ -n $updater_unit && -n $updater_hash ]] ||
|
||||
die "updater $updater_record record is incomplete"
|
||||
safe_unit_path "$service_scope" "$updater_unit" ||
|
||||
die "updater $updater_record record has an unsafe unit path"
|
||||
[[ -f $updater_unit ]] ||
|
||||
die "registered updater unit is missing: $updater_unit"
|
||||
[[ $(sha256_file "$updater_unit") == "$updater_hash" ]] ||
|
||||
die "updater unit was modified; refusing to remove it: $updater_unit"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
updater_helper_path=
|
||||
updater_bundle_path=
|
||||
if [[ -n $updater_helper ]]; then
|
||||
[[ $updater_helper =~ ^libexec/updater/[A-Za-z0-9][A-Za-z0-9._-]{0,63}/bin/echoion-updater$ &&
|
||||
$updater_helper_sha256 =~ ^[0-9a-f]{64}$ ]] ||
|
||||
die "privileged updater helper record is incomplete or unsafe"
|
||||
updater_helper_path=$prefix/$updater_helper
|
||||
updater_bundle_path=$prefix/${updater_helper%/bin/echoion-updater}
|
||||
[[ -d $updater_bundle_path && ! -L $updater_bundle_path ]] ||
|
||||
die "recorded privileged updater bundle is missing or unsafe: $updater_bundle_path"
|
||||
[[ -f $updater_helper_path && ! -L $updater_helper_path &&
|
||||
-x $updater_helper_path ]] ||
|
||||
die "recorded privileged updater helper is missing or unsafe: $updater_helper_path"
|
||||
[[ $(sha256_file "$updater_helper_path") == "$updater_helper_sha256" ]] ||
|
||||
die "privileged updater helper was modified; refusing to remove it: $updater_helper_path"
|
||||
elif [[ -n $updater_helper_sha256 ]]; then
|
||||
die "privileged updater helper record is incomplete"
|
||||
fi
|
||||
|
||||
launcher_path=
|
||||
@@ -279,13 +349,21 @@ if [[ $purge -eq 1 && $created_system_user == 1 ]]; then
|
||||
fi
|
||||
|
||||
if [[ $service_scope != none ]]; then
|
||||
if ! systemctl_for "$service_scope" disable --now "$SERVICE_NAME"; then
|
||||
service_names=("$SERVICE_NAME")
|
||||
[[ -z $updater_timer_unit ]] || service_names+=("$UPDATER_TIMER_NAME")
|
||||
if [[ -n $updater_service_unit ]] &&
|
||||
! systemctl_for "$service_scope" stop "$UPDATER_SERVICE_NAME"; then
|
||||
die "could not stop $UPDATER_SERVICE_NAME; runtime was not removed"
|
||||
fi
|
||||
if ! systemctl_for "$service_scope" disable --now "${service_names[@]}"; then
|
||||
die "could not stop and disable $SERVICE_NAME; runtime was not removed"
|
||||
fi
|
||||
fi
|
||||
|
||||
rm -f -- "$prefix/current"
|
||||
rm -rf -- "$prefix/versions"
|
||||
[[ -z $updater_bundle_path ]] || rm -rf -- "$updater_bundle_path"
|
||||
rmdir -- "$prefix/libexec/updater" "$prefix/libexec" 2>/dev/null || true
|
||||
|
||||
if [[ $purge -eq 1 ]]; then
|
||||
if [[ $config_dir == "$state_dir" ]]; then
|
||||
@@ -293,6 +371,14 @@ if [[ $purge -eq 1 ]]; then
|
||||
else
|
||||
rm -rf -- "$config_dir" "$state_dir"
|
||||
fi
|
||||
if [[ $data_layout == self-contained ]]; then
|
||||
for auxiliary in "$cache_dir" "$logs_dir" "$incoming_dir"; do
|
||||
[[ -z $auxiliary || $auxiliary == "$prefix/cache" ||
|
||||
$auxiliary == "$prefix/logs" || $auxiliary == "$prefix/incoming" ]] ||
|
||||
die "refusing unsafe self-contained auxiliary path: '$auxiliary'"
|
||||
[[ -z $auxiliary ]] || rm -rf -- "$auxiliary"
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $purge -eq 1 && $created_system_user == 1 && $service_account_present -eq 1 ]]; then
|
||||
@@ -301,11 +387,13 @@ fi
|
||||
|
||||
if [[ $service_scope != none ]]; then
|
||||
rm -f -- "$service_unit"
|
||||
[[ -z $updater_service_unit ]] || rm -f -- "$updater_service_unit"
|
||||
[[ -z $updater_timer_unit ]] || rm -f -- "$updater_timer_unit"
|
||||
systemctl_for "$service_scope" daemon-reload || warn "systemd daemon-reload failed"
|
||||
fi
|
||||
|
||||
[[ -z $launcher_path ]] || rm -f -- "$launcher_path"
|
||||
rm -f -- "$record" "$prefix/install.sh" "$prefix/uninstall.sh"
|
||||
rm -f -- "$record" "$prefix/$JSON_RECORD_NAME" "$prefix/install.sh" "$prefix/uninstall.sh"
|
||||
rmdir -- "$prefix" 2>/dev/null || true
|
||||
|
||||
printf 'Echoion runtime removed from %s.\n' "$prefix"
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
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
@@ -0,0 +1,61 @@
|
||||
#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
|
||||
@@ -0,0 +1,282 @@
|
||||
#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
Reference in new issue
Block a user