feat(broker): audit connections and requests refused before the gate
Problem
A Broker audited only the requests its gate decided. What it refused before the gate left no event:
- a peer it doesn't admit
- a connection past
max_connections - a connection it couldn't start a thread for
- a request that breaks the protocol
RFC 0011, accepted in #73, makes each of those an event.
Change
connect events. Each connection Broker::serve_with accepts is one event. It's allow with ok, or deny with peer_refused, connection_limit, or no_thread. A refusal is emitted on the accepting thread, before the connection closes. An allow is emitted on the connection's thread before its first read, so it comes before every other event for that connection. That placement is now written into the RFC: it had said all connect events come from the accepting thread.
request events. A request that breaks the protocol is one deny event:
frame_too_largefor a length prefix over 1 MiBmalformed_framefor bytes past the declared length, an attached descriptor, or a truncated control messagemalformed_requestfor a frame that isn't a request
read_frame now carries a private FramingError inside the io::Error it returns, with the reason, so the broker classifies the error by type, not by its message. The error kind and message don't change for any caller.
peer_uid. A new key and field holds the peer's uid on connect events and on request events from serve_with connections. It's null on serve_conn connections and on every other operation. serve_with now reads the uid for every accepted connection, including under any_peer.
AuditOp gains Connect and Request. AuditReason gains the six reasons, and AuditEvent gains peer_uid. All three types are #[non_exhaustive], so the additions are compatible.
Safety and compatibility
- Auditing is still observation only. No decision changes, and a gate without a sink behaves as before.
- JSON lines gain a
peer_uidkey and newop/reasonvalues within format version 1, as RFC 0002 allows. fsgate-brokerhas no audit option outside--experimental-intercept, so this reaches library embedders that set a sink on the broker's gate.
Verification
New tests in tests/broker_serve.rs use real sockets and a recording sink:
a_refused_peer_is_audited_with_its_uidan_admitted_connection_is_audited_before_its_requestsa_connection_past_the_limit_is_auditeda_request_that_breaks_the_protocol_is_audited: four cases, each with no answer, no gate event, and no file createda_connection_given_to_serve_conn_is_audited_without_a_uida_connection_without_a_thread_is_audited: Linux only, in a process of its own that lowers its ownRLIMIT_NPROC
With broker.rs swapped back to main's and the new types kept, the five that run on macOS fail. With this change, they pass.
Locally on macOS:
cargo fmt --all --checkpassed.cargo clippy --all-targets -- -D warningspassed, for the host, forx86_64-unknown-linux-gnu, and for that target withexperimental-intercept.cargo doc -p fsgate --no-depspassed with no warnings.cargo test --lockedpassed 109 tests and failed 0.
On Linux, the first CI run, on eea4be5, passed all 9 checks. a_connection_without_a_thread_is_audited passed in each Linux job:
- three times in
check: the checkout,experimental-intercept, and the packaged crate - twice in
msrv - once each on Linux 6.6 and 7.3 in
kernels
macOS doesn't build that test.
After #67, #68, and #69 merged, main was merged in, with conflicts only in the broker_serve.rs imports and two threat-model rows. Locally after that merge, cargo test --locked passed 111 tests and failed 0.
Documentation and release
- The changelog gets an
### Addedentry. - RFC 0002 gets the new values, the key, and updated examples.
- RFC 0007's decision 3 points to RFC 0011.
- RFC 0011's design and testing text are updated to match the implementation.
- The threat model's broker rows and audit section cite the tests.
- The README gets a status sentence.
- The roadmap item is ticked, with evidence.