Skip to main content

terok-clearance

terok-clearance

PyPI License: Apache-2.0 REUSE status Quality Gate Status

Live allow/deny prompts for the terok-shield firewall — desktop notifications, varlink hub, verdict helper.

When a hardened terok container hits a blocked outbound destination, the operator sees a desktop notification with Allow and Deny buttons; the chosen verdict is written into the running container's nftables ruleset.

terok ecosystem — terok-clearance turns blocked-traffic events into operator decisions

What is the clearance system

The clearance system is the operator-in-the-loop decision path for terok's egress firewall. It is built from a hub and verdict pair that talk over a varlink Unix socket and surface decisions through the freedesktop Notifications D-Bus interface:

sequenceDiagram
    participant C as Container
    participant S as terok-shield<br/>(nftables)
    participant H as clearance-hub
    participant U as Operator (desktop)
    participant V as clearance-verdict

    C->>S: outbound packet to api.example.com
    S-->>C: REJECT (default-deny)
    S->>H: blocked-connection event<br/>(NFLOG → varlink)
    H->>U: desktop notification<br/>"Allow api.example.com?"
    U->>H: clicks "Allow"
    H->>V: Apply(container, dest, allow)
    V->>S: terok-shield allow … api.example.com
    S-->>S: nft add element …
    S-->>C: subsequent packets pass

The hub and the verdict server are composed in-process by the per-container supervisor that terok-sandbox's OCI hook spawns — one supervisor (and therefore one hub socket) per container. The hub fans events out to whichever operator UIs are subscribed (the terok-clearance-hub clearance terminal tool, the embedded terok-tui screen, a DbusNotifier posting popups on the D-Bus session bus). The verdict server is the only piece that execs terok-shield (which reaches into the container's network namespace), so it sits behind the hub's authz boundary and keeps the privileged exec path isolated.

What it provides

  • Async-first Python API — create_notifier(), Notifier protocol, DbusNotifier, CallbackNotifier, NullNotifier
  • Varlink hub — ClearanceHub, ClearanceClient, EventSubscriber — the subscriber API operator UIs build on (the TUI renders live verdicts through it)
  • Multi-socket subscriber — MultiSocketSubscriber multiplexes the per-container hub sockets at $XDG_RUNTIME_DIR/terok/clearance/<short_id>/hub.sock so a single UI sees the union of every supervisor's event stream
  • Embeddable verdict server — VerdictServer for the per-container supervisor to compose alongside the hub
  • Graceful degradation — NullNotifier is returned when no D-Bus session bus is available, so headless hosts can still run the rest of the stack

Where it sits in the stack

terok-clearance is the user-in-the-loop side-rail of the terok ecosystem. Above it, terok's TUI subscribes to every per-container hub socket to display verdicts in-band; on a desktop session the same events fire freedesktop popups. Below it, the verdict server reaches into terok-shield to mutate the running ruleset. Lifecycle is owned by terok-sandbox's per-container supervisor, which composes the hub and verdict server in-process for every container it watches.

The notification API (create_notifier(), the Notifier protocol) is usable standalone for generic desktop-notification needs.

Requirements

  • Linux with a D-Bus session bus (any desktop environment with a notification daemon) — the package degrades cleanly to a no-op notifier when no bus is reachable
  • Python 3.12+

Installation

pip install terok-clearance

For most users this dependency is pulled in transitively by terok-sandbox. Install it directly only when embedding the API in your own tooling.

Quick start

Send a notification

import asyncio
from terok_clearance import create_notifier


async def main():
    notifier = await create_notifier(app_name="terok")
    action_received = asyncio.Event()

    def on_action(action_key):
        print(action_key)
        action_received.set()

    nid = await notifier.notify(
        "Clearance request",
        "Task alpha wants access to api.github.com:443",
        actions=[("allow", "Allow"), ("deny", "Deny")],
    )
    await notifier.on_action(nid, on_action)

    await action_received.wait()
    await notifier.disconnect()


asyncio.run(main())

CLI tool (development / testing)

terok-clearance-hub notify "Title" "Body"   # one-shot desktop notification
terok-clearance-hub serve                   # run a clearance hub
terok-clearance-hub serve-verdict           # run the verdict helper
terok-clearance-hub clearance               # interactive terminal UI

License

Apache-2.0 — see LICENSES/Apache-2.0.txt.

Metadata

Release files for terok-clearance 0.8.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for terok-clearance 0.8.1
File Size Uploaded
terok_clearance-0.8.1.tar.gz 218.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for terok-clearance 0.8.1
File Interpreter ABI Platform
terok_clearance-0.8.1-py3-none-any.whl Python 3 none any Details

Total release size: 295.4 kB

Release files / terok_clearance-0.8.1.tar.gz

Download URL terok_clearance-0.8.1.tar.gz
Size 218.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d4efd8755d31cc48766af4778f7df554991b6afcc8af7c1340452ac653072c16
BLAKE2b-256 checksum
How to use checksums
aee0a398e932527407e451e7cc96b11ea2786faa7ba9e36ef070ce38a5564908
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 29, 2026.

Transparency log

Release files / terok_clearance-0.8.1-py3-none-any.whl

Download URL terok_clearance-0.8.1-py3-none-any.whl
Size 76.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e2cd4e3ee089db4a1799923b78facabb373ceb8b37adb1602fe0284470b0e5b7
BLAKE2b-256 checksum
How to use checksums
cbad6b1f12370b85481c929d19bd6a32d792bc02400a58a86f163cbb912eac04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 29, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.8.1 This release

2 release files

0.8.0

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page