interface
interface
¶
The org.terok.Clearance1 varlink interface — events out, verdicts in.
Subscribers call Subscribe() with more=true and receive a stream
of ClearanceEvent records until
the connection closes. Verdict clients call Verdict() as a regular
RPC; the hub validates the (container, request_id, dest) triple
against its live-pending state before shelling out to terok-shield.
The whole surface is typed-Python → asyncvarlink derives the
varlink IDL from these annotations, so there's no hand-authored
.varlink file to drift from the code. varlinkctl can still
introspect the service at runtime via the standard
org.varlink.service.GetInterfaceDescription method.
CLEARANCE_INTERFACE_NAME = 'org.terok.Clearance1'
module-attribute
¶
Clearance1Interface(event_stream_factory, apply_verdict, set_mute, mutes)
¶
Bases: VarlinkInterface
Varlink interface served by the clearance hub.
The hub's behaviour is injected as callables so the state machine stays testable without a live varlink connection:
event_stream_factory— returns a freshAsyncIteratoryieldingClearanceEventinstances. The hub owns one per connected subscriber so backpressure is local to the slow client.apply_verdict— validates the triple and, on success, shells out toterok-shield. Raises a typed varlink error for any refusal path; returnsTrueonly when the shield invocation itself succeeded.set_mute— stops (or resumes) the prompts for one container. Mute is about who is asked, never about what the shield does: the connection was already refused before the hub saw it.mutes— reads the mute set back, so a UI can show the state the hub actually holds instead of the last thing it asked for.
Containers are addressed by the key their events carry in
ClearanceEvent.container: under the terok supervisor, the 12-char
short container id — never the podman name or a task name.
Bind the event stream factory and the verdict, mute and mute-query callables.
Source code in src/terok_clearance/wire/interface.py
Subscribe()
async
¶
Stream hub events to this caller until the connection closes.
Every yield is forwarded immediately with continues=true;
the stream ends only when the client disconnects. A buffered
(delay_generator=True) stream would hold the first event
until a second arrives, breaking the "something just happened"
liveness contract operators expect from a notification channel.
Source code in src/terok_clearance/wire/interface.py
Verdict(*, container, request_id, dest, action)
async
¶
Apply action (allow / deny) to dest for container.
Returns True when terok-shield accepted the verdict.
Raises UnknownRequest,
VerdictTupleMismatch,
InvalidAction, or
ShieldCliFailed on the
four refusal paths — clients get a typed error they can render
without stringly-matching the message.
Once shield has run, every subscriber also sees the outcome as a
verdict_applied event. When shield refused, the event's
reason holds shield's stderr, so each popup can say why.
Source code in src/terok_clearance/wire/interface.py
SetMute(*, container, muted)
async
¶
Stop (muted) or resume prompting for container's refusals.
container is the key the container's events carry — the 12-char
short id under the terok supervisor. A hub that knows which
container it serves refuses any other key with
UnknownContainer
rather than parking it where no event will ever match.
Returns the mute state now in force. Muting suppresses the
connection_blocked prompt only: the connection was refused by the
shield before the hub ever saw it. Nothing is auto-allowed, and
nothing is auto-denied either — a mute changes what an operator is
asked, not what the firewall did.
The mute does not decide whether the refusal is recorded either. The reader still writes it to the container's audit log while the task's shield audit is enabled. With audit off, a muted refusal leaves no record at all: no prompt and no audit line.
Source code in src/terok_clearance/wire/interface.py
Mutes()
async
¶
Return the containers whose prompts this hub is dropping, sorted.
The read-back half of SetMute, in the same keys events carry. A
hub restart returns to its launch default, so a UI that remembered
its own last request would drift; asking the hub cannot. Hubs that
predate this method answer org.varlink.service.MethodNotFound —
callers show that as "unknown", never as "not muted".