Add reviewed Windows scope completion and idle certificate renewal; deploy completion API
Rust development slice / linux (push) Failing after 7s

This commit is contained in:
2026-11-16 10:25:25 +01:00
parent ebcad08731
commit bb4ffe518d
43 changed files with 5146 additions and 50 deletions
+44 -6
View File
@@ -24,17 +24,26 @@ const IMMUTABLE: &str = "CREATE TRIGGER windows_echo_probe_no_change BEFORE UPDA
const RETAIN: &str = "CREATE TRIGGER windows_echo_probe_no_delete BEFORE DELETE ON windows_echo_probe_scope BEGIN SELECT RAISE(ABORT,'WINDOWS_ECHO_SCOPE_IMMUTABLE'); END";
const BOUND: &str = "WHEN NOT EXISTS(SELECT 1 FROM windows_echo_probe_scope s WHERE s.id=1 AND s.job=NEW.job AND s.attempt=NEW.attempt AND typeof(NEW.offer)='blob' AND length(NEW.offer)=length(s.prefix)+36+length(s.suffix) AND substr(NEW.offer,1,length(s.prefix))=s.prefix AND substr(NEW.offer,-length(s.suffix))=s.suffix) BEGIN SELECT RAISE(ABORT,'WINDOWS_ECHO_OFFER_OUT_OF_SCOPE'); END";
fn schema() -> [String; 6] {
fn schema(completed: bool) -> [String; 6] {
let bound = if completed {
BOUND.replacen(
"WHEN ",
"WHEN NOT EXISTS(SELECT 1 FROM windows_echo_scope_completion WHERE id=1) AND ",
1,
)
} else {
BOUND.to_owned()
};
[
POLICY.to_owned(),
"CREATE TRIGGER windows_echo_probe_no_replace BEFORE INSERT ON windows_echo_probe_scope WHEN EXISTS(SELECT 1 FROM windows_echo_probe_scope) BEGIN SELECT RAISE(ABORT,'WINDOWS_ECHO_SCOPE_IMMUTABLE'); END".to_owned(),
IMMUTABLE.to_owned(),
RETAIN.to_owned(),
format!(
"CREATE TRIGGER windows_echo_probe_offer_insert BEFORE INSERT ON job_attempts {BOUND}"
"CREATE TRIGGER windows_echo_probe_offer_insert BEFORE INSERT ON job_attempts {bound}"
),
format!(
"CREATE TRIGGER windows_echo_probe_offer_update BEFORE UPDATE OF job,attempt,offer ON job_attempts {BOUND}"
"CREATE TRIGGER windows_echo_probe_offer_update BEFORE UPDATE OF job,attempt,offer ON job_attempts {bound}"
),
]
}
@@ -82,7 +91,7 @@ pub fn install(
review: &[u8],
) -> Result<()> {
let (prefix, suffix) = blobs(scope, payload)?;
for sql in schema() {
for sql in schema(false) {
tx.execute_batch(&sql)?;
}
tx.execute(
@@ -100,7 +109,12 @@ pub fn install(
}
pub fn check(db: &Connection, scope: &ProbeScope, payload: &[u8], review: &[u8]) -> Result<()> {
let (prefix, suffix) = blobs(scope, payload)?;
for (name, expected) in OBJECTS.iter().zip(schema()) {
let completed: bool = db.query_row(
"SELECT EXISTS(SELECT 1 FROM sqlite_schema WHERE name='windows_echo_scope_completion')",
[],
|r| r.get(0),
)?;
for (name, expected) in OBJECTS.iter().zip(schema(completed)) {
let actual: String =
db.query_row("SELECT sql FROM sqlite_schema WHERE name=?", [name], |r| {
r.get(0)
@@ -115,6 +129,20 @@ pub fn installed(
db: &Connection,
binding: &rmm_agent_core::auth::Binding,
) -> Result<Option<ProbeScope>> {
let Some((scope, raw)) = archive(db, binding)? else {
return Ok(None);
};
if crate::echo_completion::installed(db, binding, &scope, &raw)? {
return Ok(None);
}
Ok(Some(scope))
}
/// Verify the retained original, including after the separately reviewed completion.
pub fn archive(
db: &Connection,
binding: &rmm_agent_core::auth::Binding,
) -> Result<Option<(ProbeScope, Vec<u8>)>> {
use rmm_agent_core::crypto::{DalekVerifier, Ed25519Verifier};
use rmm_domain::{
checkpoint_repair::SignedReceipt, windows_echo_probe::ProbeReceipt,
@@ -141,7 +169,17 @@ pub fn installed(
"Echo archive signature"
);
check(db, &r.scope, &r.job_payload_bytes, &raw)?;
Ok(Some(r.scope))
Ok(Some((r.scope, raw)))
}
pub(crate) fn retire_triggers(tx: &Transaction<'_>) -> Result<()> {
for name in &OBJECTS[4..] {
tx.execute_batch(&format!("DROP TRIGGER {name}"))?;
}
for ddl in &schema(true)[4..] {
tx.execute_batch(ddl)?;
}
Ok(())
}
pub fn permits_offer(scope: &ProbeScope, offer: &JobOffer, job: &JobPayload) -> bool {
scope.matches_job(job)