dbus_bridge
dbus_bridge
¶
D-Bus event bridge for interactive NFLOG sessions.
Translates between :class:InteractiveSession's JSON-lines protocol and
D-Bus org.terok.Shield1 signals/methods. Each bridge serves one
container; MPRIS-style per-container bus names
(org.terok.Shield1.Container_<short_id>) allow unlimited coexistence.
The bridge does not own the bus name — the caller (standalone CLI or orchestrator) acquires the name and passes the connected bus. This lets a single orchestrator manage multiple bridges on one bus connection.
Requires optional dependencies dbus-fast and terok-dbus.
Install via poetry install --with dbus.
BUS_NAME_PREFIX = 'org.terok.Shield1.Container_'
module-attribute
¶
Per-container bus name prefix. Suffixed with the short container ID.
ShieldBridge(*, state_dir, container, bus)
¶
D-Bus bridge for one container's interactive NFLOG session.
Spawns InteractiveSession (JSON-lines mode) as a subprocess that
enters the container's network namespace via nsenter. Translates
JSON-lines events to D-Bus Shield1 signals and routes verdicts
from D-Bus method calls back to the subprocess's stdin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_dir
|
Path
|
Per-container state directory. |
required |
container
|
str
|
Container name (used for nsenter and signal payloads). |
required |
bus
|
MessageBus
|
Connected |
required |
Initialise the bridge with state directory, container name, and bus.
Source code in src/terok_shield/lib/dbus_bridge.py
container_id
property
¶
Short container ID read from state_dir/container.id.
bus_name
property
¶
Per-container well-known bus name.
start()
async
¶
Spawn the interactive subprocess and begin the event relay loop.
Exports the Shield1 interface on the bus at
/org/terok/Shield1, then reads JSON lines from the subprocess
stdout and emits D-Bus signals for each event.
Source code in src/terok_shield/lib/dbus_bridge.py
submit_verdict(request_id, action)
async
¶
Write a verdict command to the subprocess stdin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request_id
|
str
|
Compound ID |
required |
action
|
str
|
|
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in src/terok_shield/lib/dbus_bridge.py
stop()
async
¶
Terminate the subprocess and clean up resources.
Runs cleanup to completion even if the caller's task is
cancelled, then re-raises CancelledError.
Source code in src/terok_shield/lib/dbus_bridge.py
bus_name_for_container(short_id)
¶
Derive the per-container well-known bus name.
D-Bus bus name segments must start with [A-Za-z_], so hex IDs
(which may start with a digit) are prefixed with Container_.