_setup
_setup
¶
Sandbox-wide setup orchestration — the phases _handle_sandbox_setup runs.
Each phase is self-contained and idempotent:
- Prereq probes are report-only. A missing
nftorpodmanlater fails the relevant service with a clearer message; reporting here lets the operator spot the root cause before scrolling past install noise. - Service install phases do the full stop → uninstall → install →
verify cycle so a re-run after
pipx install terok-sandboxguarantees the running unit picks up the new code, not just the rewritten on-disk unit file. - The clearance phase is optional — headless servers that skip the desktop bridge still get a working shield+vault+gate install.
Stage-line output routes through terok_sandbox._stage (re-exported
via the package's public surface) so frontends (terok, terok-executor)
that mix their own stage lines in the same log share one renderer and
one colour palette. Kept internal (underscore-prefixed module) because
every public entry point goes through commands._handle_sandbox_setup.
EXIT_MANUAL_STEP_NEEDED = 5
module-attribute
¶
__all__ = ['EXIT_MANUAL_STEP_NEEDED']
module-attribute
¶
run_prereq_report(cfg)
¶
Print host prerequisites and return the SELinux check result.
The result lets the caller decide whether to fail the setup or
re-surface the install hint at the end of output — sandbox#854's
fix for the install command getting buried mid-output. Purely
informational for the binary checks; never blocks on those.
cfg.experimental gates the krun-only probes (currently ip).
Source code in src/terok_sandbox/_setup.py
print_selinux_install_hint(result)
¶
Print the SELinux install command + TCP-mode alternative at end of setup output.
No-op when the SELinux state doesn't require operator action
(OK, NOT_APPLICABLE_*). Renders the two alternatives on
their own lines so the operator can copy-paste either without
surrounding output bleeding in.
Called after all install phases finish so the hint is the last thing the operator sees — sandbox#854's complaint was that the install command landed mid-output and scrolled out of view by the time the install banner printed at the bottom.
Source code in src/terok_sandbox/_setup.py
print_apparmor_install_hint()
¶
Print the AppArmor addendum install command at end of setup, if needed.
No-op unless the dnsmasq profile addendum is missing. Rendered last (alongside the SELinux hint) so the command isn't scrolled away.
Source code in src/terok_sandbox/_setup.py
run_supervisor_install_phase()
¶
Install the OCI supervisor hook + wrapper under state_root().
Lays down (with state_root() resolved from paths.root —
the operator's single configured root):
<state_root>/hooks/supervisor_hook.py+_supervisor_state.py— the OCI hook entrypoint and its stdlib-only ballast.<state_root>/hooks/terok-sandbox-supervisor-<stage>.json— one OCI hook descriptor per stage (createRuntime + poststop).containers.confis patched at install time to liststate_root() / "hooks"inhooks_dirso podman scans the canonical terok-owned directory.<state_root>/supervisor_wrapper.py— the restart-loop the hook spawns, with theterok-sandboxargv baked in at install time.
Idempotent: re-running overwrites the installed files with the
current package's copies. Soft-fails on a missing
terok-sandbox entry point (degraded install — operator hasn't
sourced the venv yet).
Source code in src/terok_sandbox/_setup.py
run_supervisor_uninstall_phase()
¶
Remove every file run_supervisor_install_phase would write.
Idempotent — missing files are tolerated. Leaves any per- container PID files / log files alone; the operator can sweep those manually if a wrapper crashed in a way that left state behind (the wrapper's PID file is unlinked at poststop in the happy path).
Source code in src/terok_sandbox/_setup.py
run_shield_install_phase()
¶
Install shield OCI hooks into the canonical terok-owned dir.
Source code in src/terok_sandbox/_setup.py
run_shield_uninstall_phase()
¶
Remove shield OCI hooks from the canonical terok-owned dir.
Source code in src/terok_sandbox/_setup.py
run_legacy_install_cleanup_phase()
¶
Sweep systemd units / sockets / install paths left by pre-supervisor versions.
One-way cleanup. Idempotent — every step soft-fails so a missing
systemctl, an absent unit, or a stale socket cannot abort the
rest of the sweep. Runs once during terok-sandbox setup; the
per-container supervisor lifecycle never invokes it.
Sweeps:
- the legacy clearance trio (
terok-clearance-hub.service,terok-clearance-verdict.service,terok-clearance-notifier.service) from the W5 layout; - the legacy vault systemd units
(
terok-vault.service/terok-vault.socket/terok-vault-socket.service); - the legacy gate systemd units
(
terok-gate.socket/terok-gate@.service/terok-gate-socket.service) now that the gate lives in the per-container supervisor; - any
terok-clearance-*.service/terok-vault-*/terok-gate*files lingering in the user's systemd unit directory (catches renamed variants from prior alphas); - the legacy global shield-events socket
(
$XDG_RUNTIME_DIR/terok-shield-events.sock) from the single-hub-socket era.
Operators upgrading from a pre-supervisor install lose access to old tasks (per the hard rule: no state preservation across the refactor); the cleanup is purely about removing the host-side machinery that would fight a fresh setup for sockets / unit names.