Implement bounded Windows Event Log jobs and verify contracts on cloud Linux
Rust development slice / linux (push) Failing after 7s

This commit is contained in:
2026-11-14 10:48:05 +01:00
parent d532ff0ffd
commit 5656431ebf
21 changed files with 2296 additions and 136 deletions
+88 -4
View File
@@ -1,4 +1,5 @@
//! Bounded, local, fixture-only live Event Log query; not wired into any job.
//! Bounded, local, fixture-only Event Log provider. Only the authorized native
//! job worker may call the Windows provider; this module confers no authority.
//!
//! EvtQuery/EvtRender have no per-call timeout. The monotonic deadline below is
//! cooperative between Win32 calls; the eventual executor must also supervise
@@ -12,8 +13,9 @@ use chrono::{DateTime, SecondsFormat, Utc};
use serde::{Deserialize, Serialize};
use std::sync::atomic::AtomicBool;
pub const CHANNEL: &str = "Application";
pub const PROVIDER: &str = "RustDiscovery-MVP-Test";
pub use rmm_domain::jobs::{
WINDOWS_EVENT_LOG_FIXTURE_CHANNEL as CHANNEL, WINDOWS_EVENT_LOG_FIXTURE_PROVIDER as PROVIDER,
};
const MAX_BYTES: usize = 256 * 1024;
#[cfg(any(windows, test))]
const REPORT_RESERVE: usize = 256;
@@ -57,7 +59,42 @@ impl Query {
}
}
#[derive(Debug, Serialize)]
/// Pure job-to-provider binding. Never opens a channel or touches a bookmark.
pub fn for_job(job: &rmm_domain::jobs::JobPayload) -> Result<Query> {
use rmm_domain::jobs::{Action, WINDOWS_EVENT_LOG_FIXTURE_SOURCE};
let Action::QueryLogs {
unit,
since,
until,
max_lines,
} = &job.action
else {
anyhow::bail!("EVENT_LOG_ACTION_REQUIRED")
};
ensure!(
job.execution_identity == "agent_service"
&& unit == WINDOWS_EVENT_LOG_FIXTURE_SOURCE
&& job.action.validate()
&& job
.action
.valid_job_limits(job.max_runtime_seconds, job.max_output_bytes),
"EVENT_LOG_JOB_BINDING"
);
let q = Query {
channel: CHANNEL.into(),
provider: PROVIDER.into(),
start_utc: *since,
end_utc: *until,
max_events: *max_lines,
max_output_bytes: job.max_output_bytes,
timeout_ms: 5000,
};
q.xpath()?;
Ok(q)
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Event {
pub channel: String,
pub provider: String,
@@ -501,6 +538,53 @@ mod tests {
}
}
#[test]
fn job_mapping_is_only_fixed_unprivileged_live_logs_with_exact_limits() {
use rmm_domain::jobs::{Action, JobPayload, WINDOWS_EVENT_LOG_FIXTURE_SOURCE};
let id = uuid::Uuid::new_v4();
let now = DateTime::from_timestamp(1_700_000_000, 0).unwrap();
let mut job = JobPayload {
schema_version: 1,
tenant_id: id,
asset_id: id,
agent_id: id,
enrollment_generation: 1,
assignment_version: 1,
job_id: id,
attempt_id: id,
action: Action::QueryLogs {
unit: WINDOWS_EVENT_LOG_FIXTURE_SOURCE.into(),
since: now,
until: now + chrono::Duration::hours(24),
max_lines: 1000,
},
execution_identity: "agent_service".into(),
not_before: now,
start_before: now + chrono::Duration::seconds(60),
max_runtime_seconds: 10,
max_output_bytes: 65536,
};
let q = for_job(&job).unwrap();
assert_eq!(
(q.channel.as_str(), q.provider.as_str()),
(CHANNEL, PROVIDER)
);
assert_eq!(q.max_output_bytes, 65536);
for identity in ["root", "system"] {
job.execution_identity = identity.into();
assert!(for_job(&job).is_err());
}
job.execution_identity = "agent_service".into();
for bytes in [1023, 65537] {
job.max_output_bytes = bytes;
assert!(for_job(&job).is_err());
}
job.max_output_bytes = 65536;
if let Action::QueryLogs { until, .. } = &mut job.action {
*until += chrono::Duration::nanoseconds(1);
}
assert!(for_job(&job).is_err());
}
#[test]
fn serialized_byte_budget_includes_xml_escaping_and_metadata() {
let q = request();
let mut report = Report::new(&q);