Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
654862b
feat(agent): answer requests under /v2/ in the 2.0 encoding
CBenoit Nov 30, 2026
28f738a
feat(agent): answer the 2.0 health and capabilities requests
CBenoit Nov 30, 2026
7e6385d
feat(agent): evaluate 2.0 package requests against the accepted policy
CBenoit Nov 30, 2026
d3da6d3
feat(agent): start, report and cancel operations for 2.0 requests
CBenoit Nov 30, 2026
16d0ee0
feat(agent): read, check and replace the policy through 2.0 requests
CBenoit Nov 30, 2026
524d8a4
feat(agent): answer a 2.0 bypass request with InternalError
CBenoit Nov 30, 2026
2f71530
feat(agent): serve a 2.0 bypass request its token authorizes
CBenoit Nov 30, 2026
4e803a9
fix(agent): record a 2.0 policy replacement the broker refuses for it…
CBenoit Nov 30, 2026
61a3263
fix(agent): answer InternalError when the evaluator refuses a request…
CBenoit Nov 30, 2026
dde046e
fix(agent): name in the 2.0 capabilities every opt-in the broker acts…
CBenoit Nov 30, 2026
c200388
fix(agent): answer the 2.0 requests of a client whose process the bro…
CBenoit Nov 30, 2026
48c5439
fix(agent): send the frames of a 2.0 bypass operation to its owner only
CBenoit Dec 1, 2026
15f5c59
fix(agent): refuse to hold again a 2.0 bypass token a request used up
CBenoit Dec 1, 2026
1577e57
fix(agent): use a 2.0 bypass token up once the broker holds its opera…
CBenoit Dec 1, 2026
619ec65
test(agent): check the capabilities refusal with the other authentica…
CBenoit Dec 1, 2026
3f89b3e
test(agent): check that authentication is decided before the administ…
CBenoit Dec 1, 2026
45f2f9f
test(agent): check the managers the elevated bypass rule leaves out
CBenoit Dec 1, 2026
d7936a9
test(agent): check that a manager capability names at least one opera…
CBenoit Dec 1, 2026
57f0ef2
fix(agent): identify the client of a 2.0 bypass event channel as soon…
CBenoit Dec 1, 2026
cb0e49e
fix(agent): close the queue of a 2.0 bypass event channel that gives …
CBenoit Dec 1, 2026
3eed096
docs(agent): say what two comments on a 2.0 bypass operation can claim
CBenoit Dec 1, 2026
bb80ec7
docs(agent): state the untested properties of a 2.0 bypass event chan…
CBenoit Dec 1, 2026
153389d
Merge branch 'claude/broker-v2-requests-7702d2' into claude/broker-v2…
CBenoit Dec 1, 2026
3606b83
Merge branch 'claude/broker-v2-requests-7702d2' into claude/broker-v2…
CBenoit Dec 1, 2026
6538296
feat(agent): read a 2.0 bypass request without a source as the contra…
CBenoit Dec 1, 2026
8d3b8f6
feat(agent): name the version of the hosting Agent in the 2.0 capabil…
CBenoit Dec 1, 2026
ba1bde3
feat(agent): answer a protected uninstall of the 2.0 routes Protected…
CBenoit Dec 1, 2026
50c4dc8
test(agent): cite the wire contract for the 60 seconds of a bypass token
CBenoit Dec 1, 2026
16871b6
docs(agent): mark what keeps a Completed status of the 2.0 routes rea…
CBenoit Dec 1, 2026
3116065
docs(agent): cite the wire contract for the pause and the closing of …
CBenoit Dec 1, 2026
c973be5
test(agent): name the reply of a protected execution without a policy…
CBenoit Dec 1, 2026
1c64dd4
refactor(agent): lend the pipe of an event channel to the identificat…
CBenoit Dec 1, 2026
91088ed
feat(agent): close an event channel whose identification of a client …
CBenoit Dec 1, 2026
7e7b7e8
fix(agent): keep the pipe of an event channel only to read the id of …
CBenoit Dec 1, 2026
35c5dfc
Merge branch 'claude/broker-v2-requests-7702d2' into claude/broker-v2…
CBenoit Dec 1, 2026
b944c06
test(agent): check the command a bypass request without a source runs
CBenoit Dec 1, 2026
e61af50
fix(agent): keep the state of an event channel's pipe under one lock
CBenoit Dec 1, 2026
2ca4795
test(agent): look for the source option each manager of a bypass requ…
CBenoit Dec 1, 2026
a3c5d99
test(agent): cover what the pipe of an event channel does around a query
CBenoit Dec 1, 2026
1f4c8e9
test(agent): split the bypass requests without a source by what their…
CBenoit Dec 1, 2026
7fecff2
test(agent): end the waits of the event channel and bypass tests on t…
CBenoit Dec 1, 2026
1834430
Merge branch 'claude/broker-v2-requests-7702d2' into claude/broker-v2…
CBenoit Dec 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 62 additions & 10 deletions crates/now-package-broker/src/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,8 @@ fn wait_for_emission(pending: &AtomicUsize, grace: std::time::Duration) {
struct WriteAuditState {
actor_sid: String,
actor_exe: String,
/// The request the write arrived as.
intent: &'static str,
path: PathBuf,
terminal_recorded: AtomicBool,
recorder: Arc<dyn AuditRecorder>,
Expand All @@ -529,7 +531,7 @@ impl Drop for WriteAuditState {
policy_events::policy_write_denied(
&self.actor_sid,
&self.actor_exe,
INTENT,
self.intent,
&self.path,
DenialReason::RequestRejected.as_str(),
),
Expand All @@ -551,16 +553,34 @@ impl WriteAudit {
Self::begin_with_recorder(actor_sid, actor_exe, path, Arc::clone(recorder()))
}

/// Records the attempt of a caller authorized to replace the policy through the 2.0 encoding.
///
/// The returned audit pairs the attempt with a result as [`Self::begin`] does.
pub(crate) fn begin_document(actor_sid: &Sid, actor_exe: &Path, path: &Path) -> Self {
Self::begin_as(DOCUMENT_INTENT, actor_sid, actor_exe, path, Arc::clone(recorder()))
}

fn begin_with_recorder(actor_sid: &Sid, actor_exe: &Path, path: &Path, recorder: Arc<dyn AuditRecorder>) -> Self {
Self::begin_as(INTENT, actor_sid, actor_exe, path, recorder)
}

fn begin_as(
intent: &'static str,
actor_sid: &Sid,
actor_exe: &Path,
path: &Path,
recorder: Arc<dyn AuditRecorder>,
) -> Self {
let state = Arc::new(WriteAuditState {
actor_sid: bounded(actor_sid.to_string(), MAX_SID_BYTES),
actor_exe: bounded(actor_exe.display().to_string(), MAX_PATH_BYTES),
intent,
path: bounded_path(path),
terminal_recorded: AtomicBool::new(false),
recorder,
});
state.record(
policy_events::policy_write_attempted(&state.actor_sid, &state.actor_exe, INTENT, &state.path),
policy_events::policy_write_attempted(&state.actor_sid, &state.actor_exe, intent, &state.path),
EntryClass::Admission,
);
Self(state)
Expand Down Expand Up @@ -756,11 +776,22 @@ impl WriteAuditState {
/// logged. The denials that follow within [`DENIAL_SUMMARY_INTERVAL`] are counted and logged as
/// one summary once the interval elapses or the broker stops.
pub(crate) fn write_denied(actor_sid: &Sid, actor_exe: &Path, path: &Path, reason: DenialReason) {
write_denied_as(INTENT, actor_sid, actor_exe, path, reason);
}

/// Records that a caller was refused a policy replacement of the 2.0 encoding before its attempt was recorded.
///
/// Its denials are logged and counted as [`write_denied`] does, apart from those of the 1.x route.
pub(crate) fn document_write_denied(actor_sid: &Sid, actor_exe: &Path, path: &Path, reason: DenialReason) {
write_denied_as(DOCUMENT_INTENT, actor_sid, actor_exe, path, reason);
}

fn write_denied_as(intent: &'static str, actor_sid: &Sid, actor_exe: &Path, path: &Path, reason: DenialReason) {
let actor_sid = bounded(actor_sid.to_string(), MAX_SID_BYTES);
let actor_exe = bounded(actor_exe.display().to_string(), MAX_PATH_BYTES);
let path = bounded_path(path);
record_denials(with_denials(|denials| {
denials.deny(actor_sid, &actor_exe, &path, reason, std::time::Instant::now())
denials.deny_as(intent, actor_sid, &actor_exe, &path, reason, std::time::Instant::now())
}));
}

Expand Down Expand Up @@ -813,6 +844,8 @@ fn with_denials<R>(f: impl FnOnce(&DenialThrottle) -> R) -> R {

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
struct DenialKey {
/// The request the denied write arrived as.
intent: &'static str,
actor_sid: String,
reason: DenialReason,
}
Expand All @@ -825,17 +858,31 @@ struct DenialWindow {

/// Collapses the repeated denials of each caller into its first denial and a periodic summary.
///
/// INVARIANT: at most [`MAX_DENIAL_WINDOWS`] windows plus one overflow window per reason are open.
/// INVARIANT: at most [`MAX_DENIAL_WINDOWS`] windows plus one overflow window per intent and reason are open.
#[derive(Default)]
struct DenialThrottle(parking_lot::Mutex<HashMap<DenialKey, DenialWindow>>);

impl DenialThrottle {
/// Counts one denial, and returns the entries to log for it.
/// Counts one denial of a write through the 1.x route, as [`Self::deny_as`] does.
#[cfg(test)]
fn deny(
&self,
actor_sid: String,
actor_exe: &str,
path: &Path,
reason: DenialReason,
now: std::time::Instant,
) -> Vec<Entry> {
self.deny_as(INTENT, actor_sid, actor_exe, path, reason, now)
}

/// Counts one denial of a write that arrived as `intent`, and returns the entries to log for it.
///
/// The denial is logged when it opens a window for its caller and reason. The summaries of the
/// The denial is logged when it opens a window for its intent, caller and reason. The summaries of the
/// windows that elapsed are returned first.
fn deny(
fn deny_as(
&self,
intent: &'static str,
actor_sid: String,
actor_exe: &str,
path: &Path,
Expand All @@ -844,14 +891,18 @@ impl DenialThrottle {
) -> Vec<Entry> {
let mut windows = self.0.lock();
let mut entries = summarize(&mut windows, now, false);
let key = DenialKey { actor_sid, reason };
let key = DenialKey {
intent,
actor_sid,
reason,
};
if let Some(window) = windows.get_mut(&key) {
window.suppressed = window.suppressed.saturating_add(1);
} else if windows.len() < MAX_DENIAL_WINDOWS {
entries.push(policy_events::policy_write_denied(
&key.actor_sid,
actor_exe,
INTENT,
intent,
path,
reason.as_str(),
));
Expand All @@ -866,6 +917,7 @@ impl DenialThrottle {
// The overflow window never logs a denial individually, so it counts this one as well.
let window = windows
.entry(DenialKey {
intent,
actor_sid: OVERFLOW_ACTOR_SID.to_owned(),
reason,
})
Expand Down Expand Up @@ -900,7 +952,7 @@ fn summarize(windows: &mut HashMap<DenialKey, DenialWindow>, now: std::time::Ins
if window.suppressed > 0 {
entries.push(policy_events::policy_write_denied_summary(
&key.actor_sid,
INTENT,
key.intent,
key.reason.as_str(),
window.suppressed,
elapsed.as_secs(),
Expand Down
19 changes: 15 additions & 4 deletions crates/now-package-broker/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,26 @@ impl PipeClient {
/// must keep it off the accept loop and bound it with a connection permit.
/// Account-name resolution remains deferred because it may contact a domain controller.
pub(crate) fn from_connected_pipe(server: &NamedPipeServer) -> anyhow::Result<Self> {
let process_id = connected_pipe_client_process_id(server).context("failed to query pipe client process id")?;
Self::from_pipe_client_process(&|| connected_pipe_client_process_id(server))
}

/// Captures the identity of the process on the other end of a connected pipe instance, as
/// [`PipeClient::from_connected_pipe`] does, for a caller that does not lend the pipe for the whole capture.
///
/// `client_process_id` reads the id of that process from the pipe, with [`connected_pipe_client_process_id`].
/// The capture asks the pipe nothing else, and calls it once as it starts and once more before it returns.
pub(crate) fn from_pipe_client_process(
client_process_id: &dyn Fn() -> anyhow::Result<u32>,
) -> anyhow::Result<Self> {
let process_id = client_process_id().context("failed to query pipe client process id")?;
let process = Arc::new(
Process::get_by_pid(process_id, PROCESS_IDENTITY_ACCESS)
.with_context(|| format!("failed to open pipe client process {process_id}"))?,
);
Self::ensure_process_active(process_id, &process)?;
let process_instance = process_instance_identity(process_id, &process)?;
let client = Self::from_process(process_instance, Arc::clone(&process), ExecutableSecurityMode::Enforce)?;
let confirmed_process_id =
connected_pipe_client_process_id(server).context("failed to confirm pipe client process id")?;
let confirmed_process_id = client_process_id().context("failed to confirm pipe client process id")?;
if confirmed_process_id != process_id {
bail!("pipe client process changed while its identity was captured");
}
Expand Down Expand Up @@ -475,7 +485,8 @@ pub(crate) fn connected_pipe_client_user_sid(server: &NamedPipeServer) -> anyhow
Ok(user_sid)
}

fn connected_pipe_client_process_id(server: &NamedPipeServer) -> anyhow::Result<u32> {
/// Reads the id of the process on the other end of a connected pipe instance.
pub(crate) fn connected_pipe_client_process_id(server: &NamedPipeServer) -> anyhow::Result<u32> {
use std::os::windows::io::AsRawHandle as _;

use windows::Win32::Foundation::HANDLE;
Expand Down
Loading
Loading