proto becomes bxcore, the one shared crate (M5b task 00)

Done the way the owner asked and the spike mapped: the crate and the
manifests renamed, then what the build reported fixed. Layers: 138
"proto unresolved" errors across 169 files; cargo fmt reordering
imports; six fixture paths built as strings in brokerd's and bxctl's
tests, which the compiler cannot see, and comments naming
crates/proto/; the crate-dependency check and its self-test. One more
the spike did not reach: a `\nproto =` key inside a printf format in
the self-test, which a word-boundary replacement skips because `n` and
`p` are both word characters.

make gate: gate: ok, 944 tests; no new entry in /tmp.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-26 01:48:38 -07:00
co-authored by Claude Opus 5.5
parent 727e027fcf
commit 2b3ae080b4
311 changed files with 426 additions and 410 deletions
Generated
+18 -18
View File
@@ -12,7 +12,7 @@ checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
name = "brokerd" name = "brokerd"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"proto", "bxcore",
"serde", "serde",
"serde_json", "serde_json",
"toml", "toml",
@@ -24,11 +24,22 @@ version = "3.20.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649"
[[package]]
name = "bxcore"
version = "0.1.0"
dependencies = [
"emsha",
"humantime",
"serde",
"serde_json",
"toml",
]
[[package]] [[package]]
name = "bxctl" name = "bxctl"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"proto", "bxcore",
"serde_json", "serde_json",
] ]
@@ -104,7 +115,7 @@ checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
name = "gatewayd" name = "gatewayd"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"proto", "bxcore",
"rustls", "rustls",
"rustls-native-certs", "rustls-native-certs",
"serde", "serde",
@@ -171,7 +182,7 @@ dependencies = [
name = "inferproxy" name = "inferproxy"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"proto", "bxcore",
] ]
[[package]] [[package]]
@@ -211,7 +222,7 @@ dependencies = [
name = "loopd" name = "loopd"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"proto", "bxcore",
"serde", "serde",
"serde_json", "serde_json",
"toml", "toml",
@@ -227,7 +238,7 @@ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
name = "memoryd" name = "memoryd"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"proto", "bxcore",
"rusqlite", "rusqlite",
"serde", "serde",
"serde_json", "serde_json",
@@ -261,17 +272,6 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "proto"
version = "0.1.0"
dependencies = [
"emsha",
"humantime",
"serde",
"serde_json",
"toml",
]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.47" version = "1.0.47"
@@ -560,7 +560,7 @@ checksum = "7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2"
name = "toolkit" name = "toolkit"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"proto", "bxcore",
"serde", "serde",
"serde_json", "serde_json",
] ]
+2 -2
View File
@@ -1,7 +1,7 @@
[workspace] [workspace]
resolver = "3" resolver = "3"
members = [ members = [
"crates/proto", "crates/bxcore",
"crates/loopd", "crates/loopd",
"crates/brokerd", "crates/brokerd",
"crates/gatewayd", "crates/gatewayd",
@@ -20,7 +20,7 @@ publish = false
unsafe_code = "forbid" unsafe_code = "forbid"
[workspace.dependencies] [workspace.dependencies]
proto = { path = "crates/proto" } bxcore = { path = "crates/bxcore" }
serde = { version = "1.0.229", features = ["derive"] } serde = { version = "1.0.229", features = ["derive"] }
serde_json = "1.0.151" serde_json = "1.0.151"
humantime = "2.4.0" humantime = "2.4.0"
+1 -1
View File
@@ -9,7 +9,7 @@ publish.workspace = true
workspace = true workspace = true
[dependencies] [dependencies]
proto.workspace = true bxcore.workspace = true
serde.workspace = true serde.workspace = true
serde_json.workspace = true serde_json.workspace = true
toml.workspace = true toml.workspace = true
+1 -1
View File
@@ -7,7 +7,7 @@ use crate::approvals::Entry;
use crate::broker::{Broker, forbid, read_request, send}; use crate::broker::{Broker, forbid, read_request, send};
use crate::grants; use crate::grants;
use crate::ledger::{Answer, Answered}; use crate::ledger::{Answer, Answered};
use proto::{ use bxcore::{
ApprovalList, Approve, ApproveResult, DecisionRecord, DenyReason, Empty, ErrorCode, ApprovalList, Approve, ApproveResult, DecisionRecord, DenyReason, Empty, ErrorCode,
GrantsReport, Message, Refuse, Timestamp, WireError, GrantsReport, Message, Refuse, Timestamp, WireError,
}; };
+1 -1
View File
@@ -2,7 +2,7 @@
//! gone. In memory only. //! gone. In memory only.
use crate::policy::{Ask, Decision}; use crate::policy::{Ask, Decision};
use proto::{DecisionRecord, DenyReason, PendingApproval, Timestamp}; use bxcore::{DecisionRecord, DenyReason, PendingApproval, Timestamp};
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::sync::mpsc::{Receiver, Sender, channel}; use std::sync::mpsc::{Receiver, Sender, channel};
use std::sync::{Mutex, MutexGuard}; use std::sync::{Mutex, MutexGuard};
+4 -4
View File
@@ -4,8 +4,8 @@
//! path, a host or a URL is well formed. The module is pure: no I/O, no clock. Everything it reads //! path, a host or a URL is well formed. The module is pure: no I/O, no clock. Everything it reads
//! was written by the model, so it is treated as hostile. //! was written by the model, so it is treated as hostile.
use proto::tools::{HttpFetchArgs, ReadFileArgs, ShellArgs, WriteFileArgs}; use bxcore::tools::{HttpFetchArgs, ReadFileArgs, ShellArgs, WriteFileArgs};
use proto::{MemoryArgs, RecallArgs}; use bxcore::{MemoryArgs, RecallArgs};
use std::fmt; use std::fmt;
/// Maximum length, in bytes, of a path. /// Maximum length, in bytes, of a path.
@@ -295,8 +295,8 @@ pub fn inside(grant_path: &str, path: &str) -> bool {
} }
} }
/// Moved to `proto::hosts` in M3b, so `toolkit` checks hosts with the same rules. /// Moved to `bxcore::hosts` in M3b, so `toolkit` checks hosts with the same rules.
pub use proto::hosts::{host_matches, valid_host, valid_host_pattern}; pub use bxcore::hosts::{host_matches, valid_host, valid_host_pattern};
/// A character that may appear in a host name. /// A character that may appear in a host name.
fn host_char(c: char) -> bool { fn host_char(c: char) -> bool {
+1 -1
View File
@@ -10,7 +10,7 @@ use std::io::Write;
use std::os::unix::fs::{DirBuilderExt, OpenOptionsExt}; use std::os::unix::fs::{DirBuilderExt, OpenOptionsExt};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use proto::{ use bxcore::{
AuditEvent, AuditRecord, ChainFailure, ChainReport, ChainVerifier, Hash32, Timestamp, AuditEvent, AuditRecord, ChainFailure, ChainReport, ChainVerifier, Hash32, Timestamp,
is_audit_log_name, sha256, is_audit_log_name, sha256,
}; };
+2 -2
View File
@@ -9,7 +9,7 @@ use std::sync::Mutex;
use std::sync::mpsc::{Receiver, RecvTimeoutError}; use std::sync::mpsc::{Receiver, RecvTimeoutError};
use std::time::Duration; use std::time::Duration;
use proto::{ use bxcore::{
DenyReason, Envelope, ErrorCode, FrameError, Message, PROTOCOL_VERSION, PendingApproval, DenyReason, Envelope, ErrorCode, FrameError, Message, PROTOCOL_VERSION, PendingApproval,
Timestamp, ToolResponse, WireError, read_frame, write_frame, Timestamp, ToolResponse, WireError, read_frame, write_frame,
}; };
@@ -37,7 +37,7 @@ pub struct Broker {
table: Table, table: Table,
runtime: Box<dyn Runtime>, runtime: Box<dyn Runtime>,
log: Log, log: Log,
printed: Mutex<Option<Vec<proto::GrantProblem>>>, printed: Mutex<Option<Vec<bxcore::GrantProblem>>>,
} }
impl Broker { impl Broker {
+1 -1
View File
@@ -2,7 +2,7 @@
//! is what an agent is, so no grant file can turn it off or put questions in front of it; the //! is what an agent is, so no grant file can turn it off or put questions in front of it; the
//! prompt is protected by `memoryd`, which lets only clean sessions edit identity. //! prompt is protected by `memoryd`, which lets only clean sessions edit identity.
use proto::{Grant, GrantProblem, sha256}; use bxcore::{Grant, GrantProblem, sha256};
use crate::grants::LoadedGrant; use crate::grants::LoadedGrant;
+1 -1
View File
@@ -8,7 +8,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{self, Receiver, RecvTimeoutError}; use std::sync::mpsc::{self, Receiver, RecvTimeoutError};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use proto::{ use bxcore::{
ApprovalOutcome, ApprovalReply, ApprovalRequest, DecisionRecord, DenyReason, Envelope, ApprovalOutcome, ApprovalReply, ApprovalRequest, DecisionRecord, DenyReason, Envelope,
FrameError, GatewayOutcome, Message, PendingApproval, Timestamp, read_frame, FrameError, GatewayOutcome, Message, PendingApproval, Timestamp, read_frame,
}; };
+3 -3
View File
@@ -8,7 +8,7 @@
use std::path::Path; use std::path::Path;
use crate::args::{ToolName, valid_host_pattern, valid_path}; use crate::args::{ToolName, valid_host_pattern, valid_path};
use proto::{DataClass, Grant, GrantProblem, Mode, sha256}; use bxcore::{DataClass, Grant, GrantProblem, Mode, sha256};
/// Where the owner reads the rules behind a rejected set. /// Where the owner reads the rules behind a rejected set.
pub const RUNBOOK: &str = "see docs/runbook.md#grants-invalid"; pub const RUNBOOK: &str = "see docs/runbook.md#grants-invalid";
@@ -17,8 +17,8 @@ pub const RUNBOOK: &str = "see docs/runbook.md#grants-invalid";
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct LoadedGrant { pub struct LoadedGrant {
pub id: String, // the file stem pub id: String, // the file stem
pub grant: proto::Grant, pub grant: bxcore::Grant,
pub sha256: proto::Hash32, // of the file's bytes as read pub sha256: bxcore::Hash32, // of the file's bytes as read
} }
/// A set that passed every rule, in id order. Its field is private: `from_grants` and `load` are /// A set that passed every rule, in id order. Its field is private: `from_grants` and `load` are
+6 -6
View File
@@ -2,7 +2,7 @@
use std::sync::MutexGuard; use std::sync::MutexGuard;
use proto::{ApprovalAnswer, AuditEvent, DataClass, DenyReason, Timestamp, ToolResponse}; use bxcore::{ApprovalAnswer, AuditEvent, DataClass, DenyReason, Timestamp, ToolResponse};
use super::{Answer, Answered, Call, Grants, Inner, Ledger}; use super::{Answer, Answered, Call, Grants, Inner, Ledger};
use crate::approvals::Verdict; use crate::approvals::Verdict;
@@ -107,16 +107,16 @@ impl Ledger {
guard: &mut MutexGuard<'_, Inner>, guard: &mut MutexGuard<'_, Inner>,
call: &Call, call: &Call,
now: Timestamp, now: Timestamp,
status: proto::ResultStatus, status: bxcore::ResultStatus,
taint_after: DataClass, taint_after: DataClass,
response: &ToolResponse, response: &ToolResponse,
) -> ToolResponse { ) -> ToolResponse {
let (sha256, bytes) = match response { let (sha256, bytes) = match response {
ToolResponse::Result { content, .. } => match proto::sha256(content.as_bytes()) { ToolResponse::Result { content, .. } => match bxcore::sha256(content.as_bytes()) {
Ok(sha) => (sha, u64::try_from(content.len()).unwrap_or(u64::MAX)), Ok(sha) => (sha, u64::try_from(content.len()).unwrap_or(u64::MAX)),
Err(_) => return Self::not_recorded(), Err(_) => return Self::not_recorded(),
}, },
ToolResponse::Failed { message } => match proto::sha256(message.as_bytes()) { ToolResponse::Failed { message } => match bxcore::sha256(message.as_bytes()) {
Ok(sha) => (sha, u64::try_from(message.len()).unwrap_or(u64::MAX)), Ok(sha) => (sha, u64::try_from(message.len()).unwrap_or(u64::MAX)),
Err(_) => return Self::not_recorded(), Err(_) => return Self::not_recorded(),
}, },
@@ -182,7 +182,7 @@ impl Ledger {
&mut guard, &mut guard,
call, call,
now, now,
proto::ResultStatus::Result, bxcore::ResultStatus::Result,
raised.taint, raised.taint,
&response, &response,
) )
@@ -197,7 +197,7 @@ impl Ledger {
&mut guard, &mut guard,
call, call,
now, now,
proto::ResultStatus::Failed, bxcore::ResultStatus::Failed,
taint_after, taint_after,
&response, &response,
) )
+1 -1
View File
@@ -6,7 +6,7 @@ mod answer;
use std::sync::{Mutex, MutexGuard}; use std::sync::{Mutex, MutexGuard};
use proto::{ use bxcore::{
AuditEvent, CallId, DataClass, DecisionRecord, DenyReason, GrantProblem, Mode, SessionId, AuditEvent, CallId, DataClass, DecisionRecord, DenyReason, GrantProblem, Mode, SessionId,
Timestamp, ToolRequest, ToolResponse, Timestamp, ToolRequest, ToolResponse,
}; };
+1 -1
View File
@@ -6,7 +6,7 @@ use std::os::unix::net::UnixStream;
use std::path::PathBuf; use std::path::PathBuf;
use std::time::Duration; use std::time::Duration;
use proto::{ use bxcore::{
Envelope, MemoryCall, Message, PROTOCOL_VERSION, ToolRequest, ToolResponse, read_frame, Envelope, MemoryCall, Message, PROTOCOL_VERSION, ToolRequest, ToolResponse, read_frame,
write_frame, write_frame,
}; };
+1 -1
View File
@@ -6,7 +6,7 @@
use crate::config::Runner; use crate::config::Runner;
use crate::runner::RunSpec; use crate::runner::RunSpec;
use proto::{CallId, SessionId}; use bxcore::{CallId, SessionId};
use std::ffi::OsString; use std::ffi::OsString;
use std::path::Path; use std::path::Path;
+1 -1
View File
@@ -3,7 +3,7 @@
use super::{Label, Matched, SessionState}; use super::{Label, Matched, SessionState};
use crate::args::{ToolArgs, host_matches, inside}; use crate::args::{ToolArgs, host_matches, inside};
use crate::grants::GrantSet; use crate::grants::GrantSet;
use proto::{DataClass, Grant, Hash32, Mode, Timestamp}; use bxcore::{DataClass, Grant, Hash32, Mode, Timestamp};
/// The grants left after matching, and the two flags that pick the denial reason when none are /// The grants left after matching, and the two flags that pick the denial reason when none are
/// left. /// left.
+14 -14
View File
@@ -6,9 +6,9 @@
//! constructor is exposed. //! constructor is exposed.
//! //!
//! ```compile_fail //! ```compile_fail
//! let request = proto::ToolRequest { //! let request = bxcore::ToolRequest {
//! session: proto::SessionId::new("s1").unwrap(), //! session: bxcore::SessionId::new("s1").unwrap(),
//! call: proto::CallId(1), //! call: bxcore::CallId(1),
//! tool: "shell".to_string(), //! tool: "shell".to_string(),
//! arguments: r#"{"command":"ls"}"#.to_string(), //! arguments: r#"{"command":"ls"}"#.to_string(),
//! }; //! };
@@ -33,9 +33,9 @@
//! The same three hold for `Ask`. //! The same three hold for `Ask`.
//! //!
//! ```compile_fail //! ```compile_fail
//! let request = proto::ToolRequest { //! let request = bxcore::ToolRequest {
//! session: proto::SessionId::new("s1").unwrap(), //! session: bxcore::SessionId::new("s1").unwrap(),
//! call: proto::CallId(1), //! call: bxcore::CallId(1),
//! tool: "shell".to_string(), //! tool: "shell".to_string(),
//! arguments: r#"{"command":"ls"}"#.to_string(), //! arguments: r#"{"command":"ls"}"#.to_string(),
//! }; //! };
@@ -60,15 +60,15 @@
//! ``` //! ```
//! fn needs_clone<T: Clone>() {} //! fn needs_clone<T: Clone>() {}
//! fn needs_decoding<T: serde::de::DeserializeOwned>() {} //! fn needs_decoding<T: serde::de::DeserializeOwned>() {}
//! needs_clone::<proto::ToolRequest>(); //! needs_clone::<bxcore::ToolRequest>();
//! needs_decoding::<proto::ToolRequest>(); //! needs_decoding::<bxcore::ToolRequest>();
//! let request = proto::ToolRequest { //! let request = bxcore::ToolRequest {
//! session: proto::SessionId::new("s1").unwrap(), //! session: bxcore::SessionId::new("s1").unwrap(),
//! call: proto::CallId(1), //! call: bxcore::CallId(1),
//! tool: "shell".to_string(), //! tool: "shell".to_string(),
//! arguments: r#"{"command":"ls"}"#.to_string(), //! arguments: r#"{"command":"ls"}"#.to_string(),
//! }; //! };
//! let now = proto::Timestamp::from_unix_millis(0).unwrap(); //! let now = bxcore::Timestamp::from_unix_millis(0).unwrap();
//! match brokerd::policy::decide( //! match brokerd::policy::decide(
//! request, //! request,
//! &brokerd::grants::GrantSet::default(), //! &brokerd::grants::GrantSet::default(),
@@ -76,7 +76,7 @@
//! now, //! now,
//! ) { //! ) {
//! brokerd::policy::Outcome::Denied(denial) => { //! brokerd::policy::Outcome::Denied(denial) => {
//! assert_eq!(denial.reason, proto::DenyReason::NoGrant); //! assert_eq!(denial.reason, bxcore::DenyReason::NoGrant);
//! } //! }
//! other => panic!("expected a denial, got {other:?}"), //! other => panic!("expected a denial, got {other:?}"),
//! } //! }
@@ -86,8 +86,8 @@ mod matching;
use crate::args::{self, ToolArgs, ToolName}; use crate::args::{self, ToolArgs, ToolName};
use crate::grants::GrantSet; use crate::grants::GrantSet;
use bxcore::{DataClass, DenyReason, Hash32, Mode, Timestamp, ToolRequest};
use matching::{MatchResult, build_matched, match_grants, winner}; use matching::{MatchResult, build_matched, match_grants, winner};
use proto::{DataClass, DenyReason, Hash32, Mode, Timestamp, ToolRequest};
/// The session's taint, and whether its results are untrusted. Only `taint` shapes a decision. /// The session's taint, and whether its results are untrusted. Only `taint` shapes a decision.
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
+4 -4
View File
@@ -5,8 +5,8 @@
//! //!
//! ```compile_fail //! ```compile_fail
//! let _ = brokerd::runner::RunSpec { //! let _ = brokerd::runner::RunSpec {
//! session: proto::SessionId::new("s1").unwrap(), //! session: bxcore::SessionId::new("s1").unwrap(),
//! call: proto::CallId(1), //! call: bxcore::CallId(1),
//! tool: brokerd::args::ToolName::Shell, //! tool: brokerd::args::ToolName::Shell,
//! arguments: todo!(), //! arguments: todo!(),
//! mounts: Vec::new(), //! mounts: Vec::new(),
@@ -22,7 +22,7 @@
use crate::args::{ToolArgs, ToolName}; use crate::args::{ToolArgs, ToolName};
use crate::policy::{Decision, Label, SessionState}; use crate::policy::{Decision, Label, SessionState};
use proto::{CallId, SessionId, ToolResponse}; use bxcore::{CallId, SessionId, ToolResponse};
/// A directory mounted for one call: a path and whether the runtime may write to it. /// A directory mounted for one call: a path and whether the runtime may write to it.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
@@ -111,7 +111,7 @@ pub const REFUSING: &str = "no tool runner is configured: brokerd.toml has no [r
/// Turn an allowed call into a `RunSpec`, run it, and answer. A `RunError`'s text reaches the /// Turn an allowed call into a `RunSpec`, run it, and answer. A `RunError`'s text reaches the
/// model unchanged, so a runtime may only put a fixed sentence in it. /// model unchanged, so a runtime may only put a fixed sentence in it.
pub fn run(decision: Decision, runtime: &dyn Runtime) -> proto::ToolResponse { pub fn run(decision: Decision, runtime: &dyn Runtime) -> bxcore::ToolResponse {
let label = decision.label(); let label = decision.label();
let args = decision.args(); let args = decision.args();
let (mounts, egress) = match args { let (mounts, egress) = match args {
+1 -1
View File
@@ -16,7 +16,7 @@ use crate::config::Config;
use crate::ledger::Ledger; use crate::ledger::Ledger;
use crate::runner::Runtime; use crate::runner::Runtime;
use crate::state::StateStore; use crate::state::StateStore;
use proto::{ChainFailure, Timestamp}; use bxcore::{ChainFailure, Timestamp};
/// A failure while `brokerd serve` is starting up. /// A failure while `brokerd serve` is starting up.
#[derive(Debug)] #[derive(Debug)]
+1 -1
View File
@@ -5,7 +5,7 @@
//! The file's format is private (`StateFile`), so `SessionState` stays free of serde. //! The file's format is private (`StateFile`), so `SessionState` stays free of serde.
use crate::policy::{Label, SessionState}; use crate::policy::{Label, SessionState};
use proto::{DataClass, SessionId}; use bxcore::{DataClass, SessionId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fs; use std::fs;
use std::io::{self, Write}; use std::io::{self, Write};
+2 -2
View File
@@ -19,11 +19,11 @@ use std::time::{Duration, Instant};
use brokerd::admin; use brokerd::admin;
use brokerd::broker::{self, Broker}; use brokerd::broker::{self, Broker};
use brokerd::policy::Label; use brokerd::policy::Label;
use client::{Serve, next, open}; use bxcore::{
use proto::{
ApprovalAnswer, Approve, AuditEvent, DataClass, DecisionRecord, DenyReason, Empty, ErrorCode, ApprovalAnswer, Approve, AuditEvent, DataClass, DecisionRecord, DenyReason, Empty, ErrorCode,
Message, Refuse, SessionId, Timestamp, ToolResponse, Message, Refuse, SessionId, Timestamp, ToolResponse,
}; };
use client::{Serve, next, open};
use rig::{Rig, grant_text, request}; use rig::{Rig, grant_text, request};
use runtime::Recording; use runtime::Recording;
+1 -1
View File
@@ -9,7 +9,7 @@ use std::sync::{Arc, Barrier};
use brokerd::approvals::{Table, Verdict}; use brokerd::approvals::{Table, Verdict};
use brokerd::policy::{Ask, Outcome, SessionState, decide}; use brokerd::policy::{Ask, Outcome, SessionState, decide};
use build::{grant, now, read, set, ts}; use build::{grant, now, read, set, ts};
use proto::{CallId, DataClass, DenyReason, Mode, PendingApproval, SessionId, Timestamp}; use bxcore::{CallId, DataClass, DenyReason, Mode, PendingApproval, SessionId, Timestamp};
fn ask() -> Ask { fn ask() -> Ask {
let grants = set(vec![grant("n", "read_file", Mode::Ask).paths(&["/n"])]); let grants = set(vec![grant("n", "read_file", Mode::Ask).paths(&["/n"])]);
+1 -1
View File
@@ -8,7 +8,7 @@ use std::os::unix::fs::PermissionsExt;
use audit_dir::{D1, D2, TempDir, denied, lines, ts}; use audit_dir::{D1, D2, TempDir, denied, lines, ts};
use brokerd::audit::{AuditError, RECOVERED_NOTICE, Writer, verify_dir}; use brokerd::audit::{AuditError, RECOVERED_NOTICE, Writer, verify_dir};
use proto::{AuditRecord, Hash32, sha256}; use bxcore::{AuditRecord, Hash32, sha256};
fn mode(path: &std::path::Path) -> u32 { fn mode(path: &std::path::Path) -> u32 {
std::fs::metadata(path).unwrap().permissions().mode() & 0o777 std::fs::metadata(path).unwrap().permissions().mode() & 0o777
+1 -1
View File
@@ -6,7 +6,7 @@ mod audit_dir;
use audit_dir::{D1, D2, TempDir, denied, lines, ts}; use audit_dir::{D1, D2, TempDir, denied, lines, ts};
use brokerd::audit::{Writer, verify_dir}; use brokerd::audit::{Writer, verify_dir};
use proto::{AuditRecord, Hash32}; use bxcore::{AuditRecord, Hash32};
/// A kill between creating the day's file and writing its first record leaves it empty. It must /// A kill between creating the day's file and writing its first record leaves it empty. It must
/// open like an empty log, not panic. /// open like an empty log, not panic.
+2 -2
View File
@@ -1,13 +1,13 @@
//! What `Writer::open` does with the log it finds: refuse a broken chain, recover a torn tail, //! What `Writer::open` does with the log it finds: refuse a broken chain, recover a torn tail,
//! accept a break when told to. Do not edit. The fixture logs are in //! accept a break when told to. Do not edit. The fixture logs are in
//! `crates/proto/tests/fixtures/audit/`; each test works on a copy. //! `crates/bxcore/tests/fixtures/audit/`; each test works on a copy.
#[path = "support/audit_dir.rs"] #[path = "support/audit_dir.rs"]
mod audit_dir; mod audit_dir;
use audit_dir::{D1, D2, TempDir, denied, lines, snapshot}; use audit_dir::{D1, D2, TempDir, denied, lines, snapshot};
use brokerd::audit::{AuditError, Writer, verify_dir}; use brokerd::audit::{AuditError, Writer, verify_dir};
use proto::{AuditEvent, AuditRecord, Location, Timestamp}; use bxcore::{AuditEvent, AuditRecord, Location, Timestamp};
type Case = ( type Case = (
&'static str, &'static str,
+3 -3
View File
@@ -20,18 +20,18 @@ use std::sync::Arc;
use brokerd::broker; use brokerd::broker;
use brokerd::ledger::NOT_RECORDED; use brokerd::ledger::NOT_RECORDED;
use brokerd::runner::{REFUSING, RunError}; use brokerd::runner::{REFUSING, RunError};
use client::{Serve, call, next, open}; use bxcore::{
use proto::{
ApprovalList, Approve, ApproveResult, AuditEvent, DataClass, DecisionRecord, DenyReason, Empty, ApprovalList, Approve, ApproveResult, AuditEvent, DataClass, DecisionRecord, DenyReason, Empty,
Envelope, ErrorCode, GrantsReport, Message, Refuse, ResultStatus, SessionId, ToolResponse, Envelope, ErrorCode, GrantsReport, Message, Refuse, ResultStatus, SessionId, ToolResponse,
Turn, TurnDone, TurnEvent, Usage, WireError, Turn, TurnDone, TurnEvent, Usage, WireError,
}; };
use client::{Serve, call, next, open};
use rig::{Rig, grant_text, request}; use rig::{Rig, grant_text, request};
use runtime::Recording; use runtime::Recording;
const NOTES: &str = r#"{"path":"/n/a"}"#; const NOTES: &str = r#"{"path":"/n/a"}"#;
fn read_notes(call_id: u64) -> proto::ToolRequest { fn read_notes(call_id: u64) -> bxcore::ToolRequest {
request("s1", call_id, "read_file", NOTES) request("s1", call_id, "read_file", NOTES)
} }
+3 -3
View File
@@ -18,11 +18,11 @@ use std::time::{Duration, Instant};
use brokerd::broker::{self, Broker, GONE}; use brokerd::broker::{self, Broker, GONE};
use brokerd::ledger::Answer; use brokerd::ledger::Answer;
use client::{Serve, next, open}; use bxcore::{
use proto::{
AuditEvent, DataClass, DecisionRecord, DenyReason, Message, ResultStatus, Timestamp, AuditEvent, DataClass, DecisionRecord, DenyReason, Message, ResultStatus, Timestamp,
ToolResponse, ToolResponse,
}; };
use client::{Serve, next, open};
use rig::{Rig, grant_text, request}; use rig::{Rig, grant_text, request};
use runtime::Recording; use runtime::Recording;
@@ -220,7 +220,7 @@ fn a_requester_gone_at_the_last_look_runs_nothing_and_closes_the_call() {
.. ..
} => { } => {
assert_eq!((*status, *decision), (ResultStatus::Failed, 0)); assert_eq!((*status, *decision), (ResultStatus::Failed, 0));
assert_eq!(*sha256, proto::sha256(GONE.as_bytes()).unwrap()); assert_eq!(*sha256, bxcore::sha256(GONE.as_bytes()).unwrap());
assert_eq!(*bytes, GONE.len() as u64); assert_eq!(*bytes, GONE.len() as u64);
} }
other => panic!("{other:?}"), other => panic!("{other:?}"),
+2 -2
View File
@@ -20,11 +20,11 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::time::Duration; use std::time::Duration;
use brokerd::ledger::Answer; use brokerd::ledger::Answer;
use client::{Serve, call}; use bxcore::{
use proto::{
AuditEvent, AuditRecord, CallId, DataClass, DecisionRecord, Message, SessionId, Timestamp, AuditEvent, AuditRecord, CallId, DataClass, DecisionRecord, Message, SessionId, Timestamp,
ToolResponse, ToolResponse,
}; };
use client::{Serve, call};
use rig::{Rig, grant_text, request}; use rig::{Rig, grant_text, request};
use runtime::Recording; use runtime::Recording;
+1 -1
View File
@@ -15,8 +15,8 @@ use brokerd::container::{
use brokerd::policy::{Outcome, SessionState, decide}; use brokerd::policy::{Outcome, SessionState, decide};
use brokerd::runner::run; use brokerd::runner::run;
use build::{grant, now, read, request, set}; use build::{grant, now, read, request, set};
use bxcore::{DataClass, Mode, ToolRequest, ToolResponse};
use fake_podman::{Fake, Lines, serial}; use fake_podman::{Fake, Lines, serial};
use proto::{DataClass, Mode, ToolRequest, ToolResponse};
fn call(podman: &Podman, req: ToolRequest, grants: Vec<build::Build>) -> ToolResponse { fn call(podman: &Podman, req: ToolRequest, grants: Vec<build::Build>) -> ToolResponse {
let decision = match decide(req, &set(grants), SessionState::default(), now()) { let decision = match decide(req, &set(grants), SessionState::default(), now()) {
+1 -1
View File
@@ -14,8 +14,8 @@ use brokerd::container::{CANNOT_START, Podman, RUNBOOK, TIMED_OUT};
use brokerd::policy::{Outcome, SessionState, decide}; use brokerd::policy::{Outcome, SessionState, decide};
use brokerd::runner::run; use brokerd::runner::run;
use build::{fetch, grant, now, set}; use build::{fetch, grant, now, set};
use bxcore::{Mode, ToolResponse};
use fake_podman::{Fake, Lines, path, serial}; use fake_podman::{Fake, Lines, path, serial};
use proto::{Mode, ToolResponse};
/// For `run -d` (the proxy): make the socket file in the mounted directory, as the proxy does. /// For `run -d` (the proxy): make the socket file in the mounted directory, as the proxy does.
const PROXY_OK: &str = r#"for a in "$@"; do case "$a" in --volume=*:/run/egress:rw) v=${a#--volume=}; v=${v%:/run/egress:rw};; esac; done"#; const PROXY_OK: &str = r#"for a in "$@"; do case "$a" in --volume=*:/run/egress:rw) v=${a#--volume=}; v=${v%:/run/egress:rw};; esac; done"#;
+1 -1
View File
@@ -15,8 +15,8 @@ use brokerd::pipes::GRACE;
use brokerd::policy::{Outcome, SessionState, decide}; use brokerd::policy::{Outcome, SessionState, decide};
use brokerd::runner::run; use brokerd::runner::run;
use build::{grant, now, read, set}; use build::{grant, now, read, set};
use bxcore::{Mode, ToolResponse};
use fake_podman::{Fake, Lines, serial}; use fake_podman::{Fake, Lines, serial};
use proto::{Mode, ToolResponse};
fn call(fake: &Fake, extra: &str, log: &Lines) -> (ToolResponse, Duration) { fn call(fake: &Fake, extra: &str, log: &Lines) -> (ToolResponse, Duration) {
let podman = Podman::new(fake.runner(extra), fake.dir.join("egress"), log.sink()); let podman = Podman::new(fake.runner(extra), fake.dir.join("egress"), log.sink());
+1 -1
View File
@@ -11,8 +11,8 @@ use brokerd::container::{CANNOT_START, COULD_NOT_RUN, Podman, UNEXPECTED};
use brokerd::policy::{Outcome, SessionState, decide}; use brokerd::policy::{Outcome, SessionState, decide};
use brokerd::runner::run; use brokerd::runner::run;
use build::{fetch, grant, now, read, set}; use build::{fetch, grant, now, read, set};
use bxcore::{Mode, ToolRequest, ToolResponse};
use fake_podman::{Fake, Lines, serial}; use fake_podman::{Fake, Lines, serial};
use proto::{Mode, ToolRequest, ToolResponse};
const FORGED: &str = "real line\nbrokerd: forged\nsee docs/runbook.md#grants-invalid"; const FORGED: &str = "real line\nbrokerd: forged\nsee docs/runbook.md#grants-invalid";
+3 -3
View File
@@ -23,12 +23,12 @@ use brokerd::broker::{self, Broker};
use brokerd::config::Gateway; use brokerd::config::Gateway;
use brokerd::courier::{self, Timing}; use brokerd::courier::{self, Timing};
use brokerd::ledger::Answer; use brokerd::ledger::Answer;
use client::{Serve, next, open}; use bxcore::{
use fake_gateway::{FakeGateway, KYLE, POST};
use proto::{
ApprovalAnswer, ApprovalReply, AuditEvent, DenyReason, GatewayOutcome, Message, Timestamp, ApprovalAnswer, ApprovalReply, AuditEvent, DenyReason, GatewayOutcome, Message, Timestamp,
ToolResponse, ToolResponse,
}; };
use client::{Serve, next, open};
use fake_gateway::{FakeGateway, KYLE, POST};
use rig::{Rig, grant_text, request}; use rig::{Rig, grant_text, request};
use runtime::Recording; use runtime::Recording;
+3 -3
View File
@@ -7,7 +7,7 @@
mod tmp; mod tmp;
use brokerd::grants::{GrantSet, LoadedGrant, RUNBOOK, load, render, valid_id}; use brokerd::grants::{GrantSet, LoadedGrant, RUNBOOK, load, render, valid_id};
use proto::{Constraints, DataClass, Grant, GrantProblem, Hash32, Mode}; use bxcore::{Constraints, DataClass, Grant, GrantProblem, Hash32, Mode};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use tmp::TempDir; use tmp::TempDir;
@@ -66,8 +66,8 @@ fn the_valid_fixture_loads_in_id_order_with_file_hashes() {
assert!(!notes.grant.untrusted); assert!(!notes.grant.untrusted);
assert_eq!(notes.grant.constraints.paths, ["/home/kyle/notes"]); assert_eq!(notes.grant.constraints.paths, ["/home/kyle/notes"]);
let bytes = std::fs::read(fixture("valid").join("notes-read.toml")).unwrap(); let bytes = std::fs::read(fixture("valid").join("notes-read.toml")).unwrap();
assert_eq!(notes.sha256, proto::sha256(&bytes).unwrap()); assert_eq!(notes.sha256, bxcore::sha256(&bytes).unwrap());
// Defaults from `proto::Grant`. // Defaults from `bxcore::Grant`.
let scratch = &set.grants()[3]; let scratch = &set.grants()[3];
assert_eq!(scratch.grant.result_class, DataClass::Private); assert_eq!(scratch.grant.result_class, DataClass::Private);
assert!(scratch.grant.untrusted); assert!(scratch.grant.untrusted);
+4 -4
View File
@@ -16,7 +16,7 @@ use std::panic::AssertUnwindSafe;
use brokerd::ledger::{Call, Decided, Grants, NOT_RECORDED, POISONED, STOPPED}; use brokerd::ledger::{Call, Decided, Grants, NOT_RECORDED, POISONED, STOPPED};
use brokerd::policy::{Label, SessionState}; use brokerd::policy::{Label, SessionState};
use build::{grant, now, read, set}; use build::{grant, now, read, set};
use proto::{ use bxcore::{
AuditEvent, CallId, DataClass, DecisionRecord, DenyReason, GrantProblem, Mode, ResultStatus, AuditEvent, CallId, DataClass, DecisionRecord, DenyReason, GrantProblem, Mode, ResultStatus,
SessionId, ToolResponse, SessionId, ToolResponse,
}; };
@@ -80,7 +80,7 @@ fn an_allowed_call_is_recorded_in_full() {
arguments, arguments,
outcome: DecisionRecord::Allowed {}, outcome: DecisionRecord::Allowed {},
grant: Some("n".to_string()), grant: Some("n".to_string()),
grant_sha256: Some(proto::sha256(b"n").unwrap()), grant_sha256: Some(bxcore::sha256(b"n").unwrap()),
taint: DataClass::Private, taint: DataClass::Private,
untrusted: false, untrusted: false,
} }
@@ -270,7 +270,7 @@ fn a_result_raises_the_state_then_is_recorded() {
untrusted: true, untrusted: true,
truncated: false, truncated: false,
bytes: 3, bytes: 3,
sha256: proto::sha256(b"key").unwrap(), sha256: bxcore::sha256(b"key").unwrap(),
taint_after: DataClass::Secret, taint_after: DataClass::Secret,
}] }]
); );
@@ -327,7 +327,7 @@ fn a_failure_changes_no_state_and_is_recorded_by_its_message() {
"the label the result would have had" "the label the result would have had"
); );
assert_eq!(*bytes, 18); assert_eq!(*bytes, 18);
assert_eq!(*sha256, proto::sha256(b"the tool timed out").unwrap()); assert_eq!(*sha256, bxcore::sha256(b"the tool timed out").unwrap());
assert_eq!(*taint_after, DataClass::Private, "the taint before"); assert_eq!(*taint_after, DataClass::Private, "the taint before");
} }
other => panic!("{other:?}"), other => panic!("{other:?}"),
+1 -1
View File
@@ -14,7 +14,7 @@ use brokerd::approvals::Verdict;
use brokerd::ledger::{Answer, Answered, Decided, Grants, Ledger}; use brokerd::ledger::{Answer, Answered, Decided, Grants, Ledger};
use brokerd::policy::{Ask, Label}; use brokerd::policy::{Ask, Label};
use build::{grant, now, read, set}; use build::{grant, now, read, set};
use proto::{ use bxcore::{
ApprovalAnswer, AuditEvent, CallId, DataClass, DecisionRecord, DenyReason, Mode, SessionId, ApprovalAnswer, AuditEvent, CallId, DataClass, DecisionRecord, DenyReason, Mode, SessionId,
}; };
use rig::Rig; use rig::Rig;
+1 -1
View File
@@ -15,7 +15,7 @@ mod tmp;
use brokerd::ledger::Call; use brokerd::ledger::Call;
use brokerd::policy::{Label, SessionState}; use brokerd::policy::{Label, SessionState};
use build::now; use build::now;
use proto::{AuditEvent, CallId, DataClass, SessionId, ToolResponse}; use bxcore::{AuditEvent, CallId, DataClass, SessionId, ToolResponse};
use rig::Rig; use rig::Rig;
fn label(class: DataClass, untrusted: bool) -> Label { fn label(class: DataClass, untrusted: bool) -> Label {
+1 -1
View File
@@ -14,7 +14,7 @@ use brokerd::approvals::Table;
use brokerd::ledger::{Answer, Decided, Grants, Ledger}; use brokerd::ledger::{Answer, Decided, Grants, Ledger};
use brokerd::policy::Ask; use brokerd::policy::Ask;
use build::{grant, now, read, set}; use build::{grant, now, read, set};
use proto::{ApprovalAnswer, AuditEvent, CallId, DataClass, Mode, PendingApproval, SessionId}; use bxcore::{ApprovalAnswer, AuditEvent, CallId, DataClass, Mode, PendingApproval, SessionId};
use rig::Rig; use rig::Rig;
const KYLE: &str = "k0000000000000000000000000"; const KYLE: &str = "k0000000000000000000000000";
+2 -2
View File
@@ -21,11 +21,11 @@ use brokerd::memory_port::{MemoryPort, Routed, UNREACHABLE};
use brokerd::policy::{Outcome, SessionState, decide}; use brokerd::policy::{Outcome, SessionState, decide};
use brokerd::runner::run; use brokerd::runner::run;
use build::{grant, now, read, request, set}; use build::{grant, now, read, request, set};
use fake_podman::{Fake, Lines, serial}; use bxcore::{
use proto::{
DataClass, Envelope, MemoryCall, Message, Mode, ToolRequest, ToolResponse, read_frame, DataClass, Envelope, MemoryCall, Message, Mode, ToolRequest, ToolResponse, read_frame,
write_frame, write_frame,
}; };
use fake_podman::{Fake, Lines, serial};
use runtime::{Recording, Shared}; use runtime::{Recording, Shared};
use tmp::TempDir; use tmp::TempDir;
+1 -1
View File
@@ -11,7 +11,7 @@ use brokerd::builtin::{BUILT_IN, MEMORY, RECALL};
use brokerd::grants::{GrantSet, load}; use brokerd::grants::{GrantSet, load};
use brokerd::policy::{Label, Outcome, decide}; use brokerd::policy::{Label, Outcome, decide};
use build::{allowed, grant, now, private, request, secret, set}; use build::{allowed, grant, now, private, request, secret, set};
use proto::{DataClass, DenyReason, Mode, sha256}; use bxcore::{DataClass, DenyReason, Mode, sha256};
use tmp::TempDir; use tmp::TempDir;
#[test] #[test]
+1 -1
View File
@@ -14,7 +14,7 @@ use brokerd::podman::{container_name, egress_args, tool_args};
use brokerd::policy::{Outcome, SessionState, decide}; use brokerd::policy::{Outcome, SessionState, decide};
use brokerd::runner::{RunError, RunOutput, RunSpec, Runtime, run}; use brokerd::runner::{RunError, RunOutput, RunSpec, Runtime, run};
use build::{fetch, grant, now, read, request, set, shell, write}; use build::{fetch, grant, now, read, request, set, shell, write};
use proto::{CallId, Mode, SessionId, ToolRequest}; use bxcore::{CallId, Mode, SessionId, ToolRequest};
const IMAGE: &str = "localhost/boxmaker-tools@sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"; const IMAGE: &str = "localhost/boxmaker-tools@sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
+1 -1
View File
@@ -7,7 +7,7 @@ mod build;
use brokerd::policy::decide; use brokerd::policy::decide;
use build::{allowed, fetch, grant, now, private, read, reason, request, set, shell, write}; use build::{allowed, fetch, grant, now, private, read, reason, request, set, shell, write};
use proto::{DenyReason, Mode}; use bxcore::{DenyReason, Mode};
#[test] #[test]
fn no_grants_means_no_grant() { fn no_grants_means_no_grant() {
+2 -2
View File
@@ -8,7 +8,7 @@ use brokerd::policy::{Label, decide};
use build::{ use build::{
allowed, asked, denied, fetch, grant, now, private, read, reason, request, secret, set, shell, allowed, asked, denied, fetch, grant, now, private, read, reason, request, secret, set, shell,
}; };
use proto::{DataClass, DenyReason, Mode}; use bxcore::{DataClass, DenyReason, Mode};
#[test] #[test]
fn the_most_restrictive_mode_wins_among_three_matching_grants() { fn the_most_restrictive_mode_wins_among_three_matching_grants() {
@@ -348,7 +348,7 @@ fn a_decision_and_an_ask_carry_what_the_broker_and_the_runner_need() {
r#"{"path":"/home/kyle/scratch/a.txt","content":"hello"}"# r#"{"path":"/home/kyle/scratch/a.txt","content":"hello"}"#
); );
assert_eq!(ask.grant(), "asks"); assert_eq!(ask.grant(), "asks");
assert_eq!(ask.grant_sha256(), proto::sha256(b"asks").unwrap()); assert_eq!(ask.grant_sha256(), bxcore::sha256(b"asks").unwrap());
assert_eq!(ask.matched_path(), Some("/home/kyle/scratch")); assert_eq!(ask.matched_path(), Some("/home/kyle/scratch"));
assert_eq!(ask.paths(), ["/home/kyle/scratch"]); assert_eq!(ask.paths(), ["/home/kyle/scratch"]);
assert!(ask.hosts().is_empty()); assert!(ask.hosts().is_empty());
+1 -1
View File
@@ -13,8 +13,8 @@ mod oracle;
use brokerd::grants::{GrantSet, LoadedGrant}; use brokerd::grants::{GrantSet, LoadedGrant};
use brokerd::policy::{Outcome, SessionState, decide, redecide}; use brokerd::policy::{Outcome, SessionState, decide, redecide};
use bxcore::{DataClass, DenyReason, Mode, Timestamp};
use oracle::{CLASSES, Expected, NOW_MS, Rng, oracle, some_grant, some_grants, some_request}; use oracle::{CLASSES, Expected, NOW_MS, Rng, oracle, some_grant, some_grants, some_request};
use proto::{DataClass, DenyReason, Mode, Timestamp};
const SEEDS: [u64; 5] = [1, 2, 3, 0xB0C5, 20_260_918]; const SEEDS: [u64; 5] = [1, 2, 3, 0xB0C5, 20_260_918];
+6 -3
View File
@@ -7,7 +7,7 @@ mod build;
use brokerd::grants::GrantSet; use brokerd::grants::GrantSet;
use brokerd::policy::{Ask, Label, Outcome, decide, redecide}; use brokerd::policy::{Ask, Label, Outcome, decide, redecide};
use build::{grant, now, private, read, secret, set}; use build::{grant, now, private, read, secret, set};
use proto::{DataClass, DenyReason, Mode}; use bxcore::{DataClass, DenyReason, Mode};
const PATH: &str = "/home/kyle/notes/a.md"; const PATH: &str = "/home/kyle/notes/a.md";
@@ -49,7 +49,10 @@ fn auto_now_lets_the_call_run_under_the_grant_that_matches_now() {
]); ]);
let decision = redecide(pending(), &grants, private(), now()).unwrap(); let decision = redecide(pending(), &grants, private(), now()).unwrap();
assert_eq!(decision.grant(), "now-auto"); assert_eq!(decision.grant(), "now-auto");
assert_eq!(decision.grant_sha256(), proto::sha256(b"now-auto").unwrap()); assert_eq!(
decision.grant_sha256(),
bxcore::sha256(b"now-auto").unwrap()
);
assert_eq!(decision.matched_path(), Some("/home/kyle")); assert_eq!(decision.matched_path(), Some("/home/kyle"));
assert_eq!(decision.paths(), ["/home/kyle"]); assert_eq!(decision.paths(), ["/home/kyle"]);
assert_eq!( assert_eq!(
@@ -103,7 +106,7 @@ fn a_deny_grant_was_added_while_the_approval_waited() {
assert_eq!(denial.grant.as_deref(), Some("no-notes")); assert_eq!(denial.grant.as_deref(), Some("no-notes"));
assert_eq!( assert_eq!(
denial.grant_sha256, denial.grant_sha256,
Some(proto::sha256(b"no-notes").unwrap()) Some(bxcore::sha256(b"no-notes").unwrap())
); );
} }
+1 -1
View File
@@ -10,7 +10,7 @@ use brokerd::args::{ToolArgs, ToolName};
use brokerd::policy::{Decision, Outcome, SessionState, decide}; use brokerd::policy::{Decision, Outcome, SessionState, decide};
use brokerd::runner::{Mount, REFUSING, Refusing, RunError, RunOutput, run}; use brokerd::runner::{Mount, REFUSING, Refusing, RunError, RunOutput, run};
use build::{grant, now, read, request, set}; use build::{grant, now, read, request, set};
use proto::{DataClass, Mode, ToolRequest, ToolResponse}; use bxcore::{DataClass, Mode, ToolRequest, ToolResponse};
use runtime::Recording; use runtime::Recording;
fn allowed(grants: Vec<build::Build>, request: ToolRequest) -> Decision { fn allowed(grants: Vec<build::Build>, request: ToolRequest) -> Decision {
+9 -5
View File
@@ -11,7 +11,7 @@ use std::time::{Duration, Instant};
use brokerd::audit::RECOVERED_NOTICE; use brokerd::audit::RECOVERED_NOTICE;
use brokerd::runner::REFUSING; use brokerd::runner::REFUSING;
use proto::{ use bxcore::{
AuditEvent, CallId, DenyReason, Empty, Envelope, ErrorCode, Message, PROTOCOL_VERSION, AuditEvent, CallId, DenyReason, Empty, Envelope, ErrorCode, Message, PROTOCOL_VERSION,
ResultStatus, SessionId, ToolRequest, ToolResponse, ResultStatus, SessionId, ToolRequest, ToolResponse,
}; };
@@ -100,7 +100,11 @@ impl Home {
.flat_map(|n| { .flat_map(|n| {
let text = std::fs::read_to_string(dir.join(n)).unwrap(); let text = std::fs::read_to_string(dir.join(n)).unwrap();
text.lines() text.lines()
.map(|l| serde_json::from_str::<proto::AuditRecord>(l).unwrap().event) .map(|l| {
serde_json::from_str::<bxcore::AuditRecord>(l)
.unwrap()
.event
})
.collect::<Vec<_>>() .collect::<Vec<_>>()
}) })
.collect() .collect()
@@ -143,10 +147,10 @@ fn exchange(socket: &Path, id: u64, msg: Message) -> Vec<Envelope> {
r#final: true, r#final: true,
msg, msg,
}; };
proto::write_frame(&mut stream, &env).unwrap(); bxcore::write_frame(&mut stream, &env).unwrap();
let mut frames = Vec::new(); let mut frames = Vec::new();
loop { loop {
let env = proto::read_frame(&mut stream).unwrap(); let env = bxcore::read_frame(&mut stream).unwrap();
let last = env.r#final; let last = env.r#final;
frames.push(env); frames.push(env);
if last { if last {
@@ -296,7 +300,7 @@ fn an_approval_nobody_answers_expires() {
fn copy_case(home: &Home, case: &str, only: &[&str]) { fn copy_case(home: &Home, case: &str, only: &[&str]) {
let from = format!( let from = format!(
"{}/../proto/tests/fixtures/audit/{case}", "{}/../bxcore/tests/fixtures/audit/{case}",
env!("CARGO_MANIFEST_DIR") env!("CARGO_MANIFEST_DIR")
); );
std::fs::create_dir_all(home.path("audit")).unwrap(); std::fs::create_dir_all(home.path("audit")).unwrap();
+1 -1
View File
@@ -58,7 +58,7 @@ fn a_break_is_accepted_and_the_next_plain_start_serves() {
std::fs::create_dir_all(&audit).unwrap(); std::fs::create_dir_all(&audit).unwrap();
std::fs::create_dir_all(dir.path().join("grants")).unwrap(); std::fs::create_dir_all(dir.path().join("grants")).unwrap();
let fixture = let fixture =
Path::new(env!("CARGO_MANIFEST_DIR")).join("../proto/tests/fixtures/audit/changed-byte"); Path::new(env!("CARGO_MANIFEST_DIR")).join("../bxcore/tests/fixtures/audit/changed-byte");
// The damage is in the first file; an ordinary start checks only the latest, so copy that one // The damage is in the first file; an ordinary start checks only the latest, so copy that one
// alone, as `audit_startup.rs` does. // alone, as `audit_startup.rs` does.
std::fs::copy( std::fs::copy(
+2 -2
View File
@@ -10,11 +10,11 @@ use std::path::Path;
use std::process::{Child, Command, Stdio}; use std::process::{Child, Command, Stdio};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use fake_podman::{Fake, IMAGE, serial}; use bxcore::{
use proto::{
CallId, DataClass, Envelope, Message, PROTOCOL_VERSION, SessionId, ToolRequest, ToolResponse, CallId, DataClass, Envelope, Message, PROTOCOL_VERSION, SessionId, ToolRequest, ToolResponse,
read_frame, write_frame, read_frame, write_frame,
}; };
use fake_podman::{Fake, IMAGE, serial};
struct Running(Child); struct Running(Child);
+1 -1
View File
@@ -5,7 +5,7 @@ mod tmp;
use brokerd::policy::{Label, SessionState}; use brokerd::policy::{Label, SessionState};
use brokerd::state::{RUNBOOK, StateError, StateStore}; use brokerd::state::{RUNBOOK, StateError, StateStore};
use proto::{DataClass, SessionId}; use bxcore::{DataClass, SessionId};
use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::PermissionsExt;
use tmp::TempDir; use tmp::TempDir;
+4 -4
View File
@@ -6,7 +6,7 @@ use std::collections::BTreeMap;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicU32, Ordering}; use std::sync::atomic::{AtomicU32, Ordering};
use proto::{AuditEvent, CallId, DataClass, DecisionRecord, SessionId, Timestamp}; use bxcore::{AuditEvent, CallId, DataClass, DecisionRecord, SessionId, Timestamp};
pub const D1: &str = "2026-09-17.jsonl"; pub const D1: &str = "2026-09-17.jsonl";
pub const D2: &str = "2026-09-18.jsonl"; pub const D2: &str = "2026-09-18.jsonl";
@@ -28,14 +28,14 @@ impl TempDir {
TempDir { path } TempDir { path }
} }
/// A copy of the fixture log `case` from `crates/proto/tests/fixtures/audit/`. With `only`, /// A copy of the fixture log `case` from `crates/bxcore/tests/fixtures/audit/`. With `only`,
/// just those files: damage in an older file is not seen by an ordinary start, so tests of /// just those files: damage in an older file is not seen by an ordinary start, so tests of
/// the startup check copy the damaged file alone. /// the startup check copy the damaged file alone.
pub fn case(case: &str, only: Option<&[&str]>) -> TempDir { pub fn case(case: &str, only: Option<&[&str]>) -> TempDir {
let dir = TempDir::unmade(case); let dir = TempDir::unmade(case);
std::fs::create_dir_all(&dir.path).unwrap(); std::fs::create_dir_all(&dir.path).unwrap();
let from = format!( let from = format!(
"{}/../proto/tests/fixtures/audit/{case}", "{}/../bxcore/tests/fixtures/audit/{case}",
env!("CARGO_MANIFEST_DIR") env!("CARGO_MANIFEST_DIR")
); );
let mut copied = 0; let mut copied = 0;
@@ -88,7 +88,7 @@ pub fn denied(call: u64) -> AuditEvent {
tool: "read_file".to_string(), tool: "read_file".to_string(),
arguments: r#"{"path":"/etc/hosts"}"#.to_string(), arguments: r#"{"path":"/etc/hosts"}"#.to_string(),
outcome: DecisionRecord::Denied { outcome: DecisionRecord::Denied {
reason: proto::DenyReason::NoGrant, reason: bxcore::DenyReason::NoGrant,
}, },
grant: None, grant: None,
grant_sha256: None, grant_sha256: None,
+2 -2
View File
@@ -6,7 +6,7 @@
use brokerd::grants::{GrantSet, LoadedGrant}; use brokerd::grants::{GrantSet, LoadedGrant};
use brokerd::policy::{Ask, Decision, Denial, Outcome, SessionState}; use brokerd::policy::{Ask, Decision, Denial, Outcome, SessionState};
use proto::{ use bxcore::{
CallId, Constraints, DataClass, DenyReason, Grant, Mode, SessionId, Timestamp, ToolRequest, CallId, Constraints, DataClass, DenyReason, Grant, Mode, SessionId, Timestamp, ToolRequest,
}; };
@@ -39,7 +39,7 @@ pub fn grant(id: &str, tool: &str, mode: Mode) -> Build {
constraints: Constraints::default(), constraints: Constraints::default(),
}, },
// Stands in for the file's hash, and differs from grant to grant. // Stands in for the file's hash, and differs from grant to grant.
sha256: proto::sha256(id.as_bytes()).unwrap(), sha256: bxcore::sha256(id.as_bytes()).unwrap(),
}) })
} }
+3 -3
View File
@@ -11,7 +11,7 @@ use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use brokerd::broker::{self, Broker}; use brokerd::broker::{self, Broker};
use proto::{Envelope, Message, PROTOCOL_VERSION, ToolRequest}; use bxcore::{Envelope, Message, PROTOCOL_VERSION, ToolRequest};
use crate::rig::Rig; use crate::rig::Rig;
use crate::runtime::{Recording, Shared}; use crate::runtime::{Recording, Shared};
@@ -49,7 +49,7 @@ pub fn open(
r#final: true, r#final: true,
msg, msg,
}; };
proto::write_frame(&mut client, &env).unwrap(); bxcore::write_frame(&mut client, &env).unwrap();
client client
} }
@@ -60,7 +60,7 @@ pub fn next(stream: &mut UnixStream) -> Envelope {
let peer_closed = cfg!(target_vendor = "apple") && e.raw_os_error() == Some(22); let peer_closed = cfg!(target_vendor = "apple") && e.raw_os_error() == Some(22);
assert!(peer_closed, "set_read_timeout: {e}"); assert!(peer_closed, "set_read_timeout: {e}");
} }
proto::read_frame(stream).unwrap() bxcore::read_frame(stream).unwrap()
} }
/// Sends a tool request to `broker::handle` and reads every frame up to the final one. /// Sends a tool request to `broker::handle` and reads every frame up to the final one.
+5 -2
View File
@@ -8,7 +8,7 @@ use std::path::{Path, PathBuf};
use std::sync::mpsc::{self, Receiver}; use std::sync::mpsc::{self, Receiver};
use std::time::Duration; use std::time::Duration;
use proto::{ use bxcore::{
ApprovalPosted, ApprovalReply, Envelope, ErrorCode, GatewayOutcome, Message, PROTOCOL_VERSION, ApprovalPosted, ApprovalReply, Envelope, ErrorCode, GatewayOutcome, Message, PROTOCOL_VERSION,
PendingApproval, WireError, read_frame, write_frame, PendingApproval, WireError, read_frame, write_frame,
}; };
@@ -141,7 +141,10 @@ impl Conn {
/// Did the courier close the connection within `wait`, without sending anything? /// Did the courier close the connection within `wait`, without sending anything?
pub fn closed_within(&mut self, wait: Duration) -> bool { pub fn closed_within(&mut self, wait: Duration) -> bool {
self.stream.set_read_timeout(Some(wait)).unwrap(); self.stream.set_read_timeout(Some(wait)).unwrap();
matches!(read_frame(&mut self.stream), Err(proto::FrameError::Closed)) matches!(
read_frame(&mut self.stream),
Err(bxcore::FrameError::Closed)
)
} }
pub fn close(self) { pub fn close(self) {
+2 -2
View File
@@ -10,7 +10,7 @@
use brokerd::grants::LoadedGrant; use brokerd::grants::LoadedGrant;
use brokerd::policy::SessionState; use brokerd::policy::SessionState;
use proto::{ use bxcore::{
CallId, Constraints, DataClass, DenyReason, Grant, Mode, SessionId, Timestamp, ToolRequest, CallId, Constraints, DataClass, DenyReason, Grant, Mode, SessionId, Timestamp, ToolRequest,
}; };
@@ -119,7 +119,7 @@ pub fn some_grant(rng: &mut Rng, id: usize) -> LoadedGrant {
secret: None, secret: None,
constraints, constraints,
}, },
sha256: proto::sha256(format!("file {id}").as_bytes()).unwrap(), sha256: bxcore::sha256(format!("file {id}").as_bytes()).unwrap(),
} }
} }
+1 -1
View File
@@ -12,7 +12,7 @@ use brokerd::audit::Writer;
use brokerd::config::{Approvals, Config, Paths, Sockets}; use brokerd::config::{Approvals, Config, Paths, Sockets};
use brokerd::ledger::Ledger; use brokerd::ledger::Ledger;
use brokerd::state::StateStore; use brokerd::state::StateStore;
use proto::{AuditEvent, AuditRecord, CallId, SessionId, ToolRequest}; use bxcore::{AuditEvent, AuditRecord, CallId, SessionId, ToolRequest};
use crate::sink::{Flaky, Lines, Switch}; use crate::sink::{Flaky, Lines, Switch};
use crate::tmp::TempDir; use crate::tmp::TempDir;
+1 -1
View File
@@ -9,7 +9,7 @@ use std::sync::{Arc, Mutex};
use brokerd::audit::{AuditError, Writer}; use brokerd::audit::{AuditError, Writer};
use brokerd::ledger::AuditSink; use brokerd::ledger::AuditSink;
use proto::{AuditEvent, Timestamp}; use bxcore::{AuditEvent, Timestamp};
/// Switches shared between a test and its `Flaky` sink. /// Switches shared between a test and its `Flaky` sink.
#[derive(Clone, Default)] #[derive(Clone, Default)]
@@ -1,5 +1,5 @@
[package] [package]
name = "proto" name = "bxcore"
version = "0.1.0" version = "0.1.0"
edition.workspace = true edition.workspace = true
rust-version.workspace = true rust-version.workspace = true
@@ -1,7 +1,7 @@
//! Tests for the admin messages of `admin.sock` and the two new error codes, against byte-exact //! Tests for the admin messages of `admin.sock` and the two new error codes, against byte-exact
//! fixtures. Do not edit these or the fixtures. //! fixtures. Do not edit these or the fixtures.
use proto::{ use bxcore::{
ApprovalList, Approve, ApproveResult, CallId, DataClass, DecisionRecord, DenyReason, Empty, ApprovalList, Approve, ApproveResult, CallId, DataClass, DecisionRecord, DenyReason, Empty,
Envelope, ErrorCode, GrantProblem, GrantsReport, Message, PendingApproval, Refuse, SessionId, Envelope, ErrorCode, GrantProblem, GrantsReport, Message, PendingApproval, Refuse, SessionId,
Timestamp, WireError, Timestamp, WireError,
@@ -4,7 +4,7 @@
//! Every fixture is a small audit directory. `good` is an undamaged two-day log; the others are //! Every fixture is a small audit directory. `good` is an undamaged two-day log; the others are
//! `good` with one thing done to it, named by the directory. //! `good` with one thing done to it, named by the directory.
use proto::{AuditRecord, ChainReport, ChainVerifier, Hash32, Location, sha256}; use bxcore::{AuditRecord, ChainReport, ChainVerifier, Hash32, Location, sha256};
const D1: &str = "2026-09-17.jsonl"; const D1: &str = "2026-09-17.jsonl";
const D2: &str = "2026-09-18.jsonl"; const D2: &str = "2026-09-18.jsonl";
@@ -1,9 +1,9 @@
//! Tests for `proto::escape`: text the model wrote is printed as data. Do not edit. //! Tests for `bxcore::escape`: text the model wrote is printed as data. Do not edit.
//! //!
//! The expected escapes are built by `esc`, never spelled out, so that nothing that handles this //! The expected escapes are built by `esc`, never spelled out, so that nothing that handles this
//! file can turn one into the character it stands for. //! file can turn one into the character it stands for.
use proto::escape::{escape_json_text, escape_model_text}; use bxcore::escape::{escape_json_text, escape_model_text};
const BACKSLASH: char = '\\'; const BACKSLASH: char = '\\';

Some files were not shown because too many files have changed in this diff Show More