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.
VERDICT_TTL_CONFIG_KEY = 'verdict_ttl'
module-attribute
¶
VerdictTtlParam = float | None | _Unset
module-attribute
¶
ClearanceHub(*, clearance_socket=None, reader_socket=None, verdict_client=None, socket_context=None, verdict_ttl=_UNSET, container=None, aliases=(), muted=())
¶
Server for the org.terok.Clearance1 interface.
Owns four 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._muted— the containers whose prompts are dropped, seeded from the launch default and changed bySetMute.- An
EventIngesterbound to the canonical reader socket.
Wherever the hub keys a container — bindings, mutes, the events it fans out — it uses the key the events carry: the 12-char short id the shield reader stamps on what it emits. A hub built for one container makes that the only key it holds (see the container argument), so a name can never be mistaken for it.
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, the verdict-helper client and the mute state.
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.
verdict_ttl — seconds after which a pending connection_blocked
entry is expired from the authz-binding map. None means no
expiry (backward-compatible). When not passed explicitly, the
value is read from the clearance.verdict_ttl key in the
layered terok config (~/.config/terok/config.yml); absent
falls back to a 24-hour default so long-running containers
don't accumulate unbounded state. Pass verdict_ttl=None
explicitly to disable expiry regardless of the config file.
Config file example::
clearance:
verdict_ttl: 24h # or "never" to disable
container — the one container this hub serves, under the key the
shield reader stamps on its events: the 12-char short id. Pass it
only when reader_socket is per-container, as in the supervisor's
events/<short_id>/ingester.sock layout: every event arriving
there is about this container by construction, so the hub stamps
each one with this key. That matters because producers disagree —
the reader sends the short id while host-side shield_up /
shield_down events arrive under the podman name — and a split
identity lets a shield drop miss the very prompts it should retire.
It also confines every verdict this hub can issue to its own
container. None (the default) keeps a multi-container hub that
relays each event's key as sent. Anything but 12 hex characters
raises ValueError. A podman name or the full id would be
accepted and then become the key on every event, which no
short-id caller could address. The launcher would see nothing
wrong while every mute did nothing.
aliases — other spellings of container that a SetMute
caller or the launch default may use: the full id, the podman name.
They resolve to container; with container set, any other key is
refused with UnknownContainer.
Meaningless without container, so passing them alone raises
ValueError.
muted — containers whose prompts start muted: the launch default.
A launcher that passes it on every construction (the per-container
supervisor builds a fresh hub on each container start) gets a
default that holds across hub restarts, where a runtime SetMute
deliberately does not. It is applied here, before
start binds the
ingester, so no prompt can slip out ahead of it. A key this hub
does not serve is logged and ignored: the container stays audible,
the safe direction for a default that cannot be honoured.
aliases and muted take collections of keys. Passing a single
string raises TypeError: a string is itself iterable, so it
would be split into one key per character and the intended key
would never be used.
Source code in src/terok_clearance/hub/server.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
verdict_ttl
property
¶
Pending-verdict TTL in seconds, or None when expiry is disabled.
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.