Documentation
¶
Overview ¶
Package containerbridge runs external CLI tools inside Docker containers and surfaces their output as Go values. It is the shared substrate for the urh_*, firmware_extract, and fap_build Spec families — any Spec that wants to hand work off to a maintained third-party CLI without reimplementing it in Go.
Why Docker ¶
Each external tool ships its own dependency graph (urh-ng wants Python + PyQt + scientific Python; ufbt wants the Flipper SDK + a pinned Python/clang chain; unblob wants ~30 extractor binaries). Pinning these on the host runs counter to PromptZero's "bring your own toolchain" posture. Docker images give a hermetic, version-pinned runtime that the operator can mirror to a private registry for air-gapped engagements.
Concurrency ¶
Each Run spawns a fresh container; multiple parallel calls are safe. The package keeps no shared state — config-by-call.
Failure modes ¶
Run returns:
- a *RunError with .ExitCode != 0 when the container ran but the containerised tool exited non-zero (i.e. the Spec should report a tool error to the agent);
- a wrapped error when Docker itself failed (binary missing, image pull required network, daemon unreachable). Spec handlers should surface these distinctly so the operator can fix the host toolchain.
Index ¶
Constants ¶
This section is empty.
Variables ¶
ErrDockerUnavailable is returned when the docker binary cannot be invoked. Distinct from a tool-level error so callers can surface a helpful "install Docker" hint rather than a generic exec failure.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Image is the docker image reference (e.g. "ghcr.io/onekey-sec/unblob:latest").
// Required.
Image string
// Args are the entrypoint arguments passed to the container.
Args []string
// Env is the environment exposed to the container.
Env map[string]string
// Mounts are bind mounts from the host into the container.
Mounts []Mount
// Stdin streams into the container's stdin. Nil means no stdin.
Stdin io.Reader
// Network controls --network. Empty defaults to "none" — most tool
// runs do not need network and the safe default avoids data
// exfiltration risk.
Network string
// Timeout caps the entire run. Zero defaults to 5 minutes.
Timeout time.Duration
// User runs the container as a specific UID:GID. Empty leaves it
// at the image's default. Set to e.g. "1000:1000" to match the
// host operator and simplify volume-mounted output.
User string
// WorkDir sets the container working directory.
WorkDir string
// Sandbox extras — read-only rootfs, drop capabilities. Set true
// for tools that don't need to mutate the rootfs (most parsers).
ReadOnlyRootfs bool
// AllocateTTY forces -t. Generally not needed — only set true for
// tools that misbehave without one.
AllocateTTY bool
}
Config describes one containerised invocation.
All fields are optional except Image. Stdin is delivered via the container's stdin pipe; large inputs are fine (the bridge does not buffer the input — it streams). Output is captured into a byte buffer to make it convenient for the calling Spec; if the tool generates hundreds of MB the caller should switch to volume-mounted output paths rather than stdout capture.
type RunResult ¶
type RunResult struct {
Stdout []byte
Stderr []byte
// ExitCode is 0 when the tool exited successfully, non-zero
// otherwise. Always populated, even on RunError.
ExitCode int
// Duration is the wall-clock time the container ran.
Duration time.Duration
}
RunResult captures the stdout/stderr of a containerised invocation.