Skip to content
Documentation

Local interfaces: IPC, CLI and JSONL outputs

This page is published from the agent repository. Edit on GitHub View source

Besides the control plane, the agent talks to two local audiences: administrators on the host, through a local control channel used by cli (and later the endpoint UI), and files on disk that other tools read (the alert log, the optional raw event capture). This page explains both.

Local control channel

The ipc crate implements a small request/response protocol over a Unix domain socket (Linux, macOS) or a named pipe (Windows). The agent hosts the server (ipc_handler.rs); cli and agent apply-content-manifest are clients.

ModuleResponsibility
streamOS-native Listener/Stream and the peer-credential read; the only place with cfg(target_family) code.
frameJSON-lines framing with a 1 MiB per-message cap.
protocolWire types: ClientHello, ServerHello, Request, Response, WireError.
serverAccept loop, per-connection task, dispatch to a Handler.
clientConnect, handshake, typed calls; maps errors to messages an operator can act on.

Connection lifecycle

sequenceDiagram
  participant C as cli
  participant S as agent (ipc Server)
  C->>S: connect (socket / pipe)
  S->>S: read peer credentials, check_authorized
  alt not privileged
    S-->>C: WireError::Unauthorized, then EOF
  end
  C->>S: ClientHello {version, client_name}
  alt version != PROTOCOL_VERSION
    S-->>C: WireError::UnsupportedVersion, then EOF
  end
  S-->>C: ServerHello {version, agent_version}
  loop one request at a time
    C->>S: Request
    S-->>C: Response (or Response::Error)
  end
  • Peer authentication (PeerCreds::check_authorized) happens before a byte of the handshake is read: uid == 0 on Unix (SO_PEERCRED, or LOCAL_PEERCRED on macOS), an elevated token on Windows (TokenElevation of the client process). Elevation, not group membership, is what an administrator running cli passes. The check is in code rather than in a pipe security descriptor so that a non-elevated client still connects and gets an explicit refusal. client_name is informational only.
  • Versioning is strict equality on PROTOCOL_VERSION (currently 3). A new request variant bumps the version; additive fields on existing variants do not.
  • Serial per connection, parallel across connections. One tokio task per client; there are no correlation IDs because only one request is in flight per connection. A slow handler blocks its own connection, not the server. A failed accept is logged and the loop continues.
  • Framing (read_message): one UTF-8 JSON object per line. JSON escapes newlines inside strings, so the delimiter is unambiguous. A line over MAX_MESSAGE_BYTES (1 MiB, newline included) or not valid UTF-8 ends the connection; the reader enforces the cap itself, since tokio's read_line has none. JSON lines were chosen so the wire is readable with standard tools and matches every other artifact the project writes.
  • Endpoints. ipc.endpoint in agent.toml: an absolute socket path such as /var/run/synthaea/agent.sock, or \\.\pipe\synthaea-agent. On Unix a stale socket file is removed before binding, so a restart after a crash does not fail with "address in use".

Requests

RequestEffectNotes
Statusversion, start time, pipeline health, active suppressions
SensorHealthper-sensor state
RecentDetections { limit }the most recent detections, oldest firstclamped to RECENT_DETECTIONS_HARD_LIMIT (256), no error
PolicyVersionapplied policy metadata
ReloadContentre-read Sigma/YARA content and swap it into the running pipelinesent by apply-content-manifest after it has verified and written content
SuppressVerdict / UnsuppressVerdictsilence or restore one technique on one entity (ppid, comm) in the fused verdictreversible, audited, never touches the alert log

The channel is read-mostly by design. The three mutating requests are exceptions because they act only on the agent's own state: ReloadContent loads content that was already signature-checked over the mTLS channel, and suppressions change only the agent's verdict view. Commands that act on other processes or files (kill, quarantine, isolate) are not on this channel; they need a per-capability authorization model first.

A handler error becomes Response::Error(WireError::HandlerFailed) and the connection stays open; authentication, version and framing failures close it.

Client errors

Client::connect separates "the agent is not there" (ClientError::Connect) from "the agent said no" (ClientError::Refused). Permission denied on the socket, Windows error 5, and an Unauthorized reply are all reported as access denied rather than as a missing agent; a pipe closed during the handshake is reported as such. There is no connection pool and no reconnect: clients are short-lived.

cli

cli holds no privileges of its own; it is a pure client of the IPC channel (installed on Linux as /usr/bin/synthaea-ctl).

CommandDoes
config init [--force]Write the default agent.toml template to the discovered path; refuses to overwrite without --force.
config check, config pathValidate the configuration, print where it was found. No network.
status, health, detections [--limit 20], policyIPC reads.
suppress PPID COMM TECHNIQUE, unsuppress ...IPC suppressions.

Configuration discovery: --config, then SYNTHAEA_CONFIG, then the OS default path. Every IPC command accepts --json (one line of JSON) and exits non-zero with a copy-pasteable message when the agent is unreachable or refuses.

JSONL outputs

The sinks crate writes local JSON Lines. The agent speaks only neutral formats; vendor SIEM connectors belong to the control plane's export, not to each agent.

  • JsonlWriter: one Mutex<BufWriter<File>> opened in append mode, one serialized value per line, flushed per line (the files are tailed while the agent runs, and losing buffered lines on a crash costs more than the syscall). A write error is ignored: a missed local log line must not stop capture.
  • Torn-tail repair. On open, if the file is non-empty and does not end in a newline (a crash mid-write), a newline is appended first, so the first new record does not fuse with the torn line and make both unreadable.
  • Escaping is serde_json's: a process renamed to contain quotes or control bytes still yields valid JSON (tested in tests.rs).
  • JsonlEventSink writes every normalized event in the schema's canonical serialization, unfiltered; used by agent capture-events and by the optional raw event log of agent run. AlertRecord is the alert-log record shape.

In agent run the raw event log is written by the enrichment worker, after redaction, never by a capture thread, and is off unless requested: it grows without bound and only labs and ML calibration need it (DetectionSink::new).

Syslog/CEF and OCSF/ECS mappings are planned additions to this crate.

Testing

TestWhat it proves
crates/ipc/tests/e2e.rsA real server and client round-trip every request; a wrong version is refused. Run privileged in CI (see Development).
Unit tests in stream.rs, frame.rs, client.rsAuthorization policy, framing limits, error classification.
crates/sinks/src/tests.rsRound trip, hostile strings, append across reopen, torn-tail repair.

cli has no tests of its own; its IPC calls are covered by the ipc tests.