server
server
¶
The clearance hub — varlink server + reader ingester + verdict exec.
Fans reader-emitted events (blocks, container lifecycle, shield state)
out to every connected clearance client, and applies verdicts the
clients send back by shelling out to terok-shield allow|deny. The
only D-Bus in sight is what individual clients choose to use on their
own (the desktop notifier reaches for org.freedesktop.Notifications
out-of-band); the hub itself speaks plain unix-socket varlink.
Authorisation is structural: the socket is mode 0600 (same-UID only),
and every Verdict call must cite a (container, request_id, dest)
triple the hub actually emitted via connection_blocked. The
triple is recorded at emit time and dropped on verdict or lifecycle
change; anything that doesn't match is a UnknownRequest or
VerdictTupleMismatch refusal.
ClearanceHub(*, clearance_socket=None, reader_socket=None, verdict_client=None, socket_context=None)
¶
Server for the org.terok.Clearance1 interface.
Owns three pieces of state:
_subscribers— a set of bounded per-connection queues; the hub puts aClearanceEventon each one every time the reader ingester delivers an event. Slow clients see their oldest events dropped; fast clients aren't affected._live_verdicts— therequest_id → (container, dest)map theVerdictmethod checks for the authz binding.- An
EventIngesterbound to the canonical reader socket.
Lifecycle: start brings everything up; stop tears
it down under individual timeouts so a flaky bus or a stuck
subscriber can't stall the per-container supervisor's teardown.
Configure the two sockets and the verdict-helper client.
verdict_client is injected so tests can stub out shield exec
without spawning the helper process. Production callers leave
it defaulted — a fresh VerdictClient pointing at the
canonical helper socket.
socket_context — optional zero-arg callable returning a context
manager around the varlink bind() (forwarded to
bind_hardened).
terok-sandbox passes its SELinux setsockcreatecon helper here
so the hub socket is labelled terok_socket_t and confined
containers can connectto it.
Source code in src/terok_clearance/hub/server.py
start()
async
¶
Bring the ingester + varlink server online and accept clients.
Transactional: if the varlink bind fails after the ingester is already listening, the ingester is stopped before the exception propagates so a half-started hub doesn't leak a live reader-side socket on systemd restart paths.
Source code in src/terok_clearance/hub/server.py
stop()
async
¶
Close the varlink server + ingester; drain subscriber queues.
Source code in src/terok_clearance/hub/server.py
serve()
async
¶
Run the hub service until SIGINT/SIGTERM.
The entry point terok-clearance-hub serve hands off here. Blocks forever
on a signal-set asyncio.Event; the first SIGINT/SIGTERM
flips it, then stop
tears down the server under a timeout.