feat: snapshot Linux-first RMM MVP and pause handover
Rust development slice / linux (push) Failing after 1m10s
Rust development slice / linux (push) Failing after 1m10s
This commit is contained in:
@@ -0,0 +1,193 @@
|
||||
use prost::Message;
|
||||
#[derive(Clone, PartialEq, Message)]
|
||||
pub struct SyncRequest {
|
||||
#[prost(string, tag = "1")]
|
||||
pub request_id: String,
|
||||
#[prost(string, tag = "2")]
|
||||
pub journal_id: String,
|
||||
#[prost(uint64, tag = "3")]
|
||||
pub checkpoint: u64,
|
||||
#[prost(string, tag = "4")]
|
||||
pub previous_decision_id: String,
|
||||
#[prost(uint64, tag = "5")]
|
||||
pub assignment_version: u64,
|
||||
#[prost(message, repeated, tag = "6")]
|
||||
pub attempts: Vec<SyncAttempt>,
|
||||
#[prost(string, repeated, tag = "7")]
|
||||
pub durable_message_ids: Vec<String>,
|
||||
#[prost(bool, tag = "8")]
|
||||
pub journal_complete: bool,
|
||||
#[prost(string, tag = "9")]
|
||||
pub helper_journal_id: String,
|
||||
#[prost(uint64, tag = "10")]
|
||||
pub helper_checkpoint: u64,
|
||||
#[prost(string, tag = "11")]
|
||||
pub helper_previous_decision_id: String,
|
||||
#[prost(string, tag = "12")]
|
||||
pub previous_request_id: String,
|
||||
}
|
||||
#[derive(Clone, PartialEq, Message)]
|
||||
pub struct SyncAttempt {
|
||||
#[prost(string, tag = "1")]
|
||||
pub job_id: String,
|
||||
#[prost(string, tag = "2")]
|
||||
pub attempt_id: String,
|
||||
#[prost(string, tag = "3")]
|
||||
pub job_payload_hash: String,
|
||||
#[prost(string, tag = "4")]
|
||||
pub grant_id: String,
|
||||
/// unconsumed | consumed | uncertain. No claim may reset a server reservation.
|
||||
#[prost(string, tag = "5")]
|
||||
pub consumption: String,
|
||||
#[prost(string, tag = "6")]
|
||||
pub state: String,
|
||||
#[prost(uint64, tag = "7")]
|
||||
pub revision: u64,
|
||||
#[prost(string, tag = "8")]
|
||||
pub original_boot_id: String,
|
||||
#[prost(message, optional, tag = "9")]
|
||||
pub result: Option<JobResult>,
|
||||
#[prost(string, tag = "10")]
|
||||
pub result_message_id: String,
|
||||
#[prost(string, tag = "11")]
|
||||
pub outcome_sha256: String,
|
||||
#[prost(bytes = "vec", tag = "12")]
|
||||
pub outcome_bytes: Vec<u8>,
|
||||
#[prost(message, optional, tag = "13")]
|
||||
pub result_envelope: Option<crate::Envelope>,
|
||||
}
|
||||
#[derive(Clone, PartialEq, Message)]
|
||||
pub struct SyncResponse {
|
||||
#[prost(bytes = "vec", tag = "1")]
|
||||
pub decision_bytes: Vec<u8>,
|
||||
#[prost(bytes = "vec", tag = "2")]
|
||||
pub signature: Vec<u8>,
|
||||
}
|
||||
/// payload_bytes is rmm_domain::jobs::JobPayload codec v1, hash exact bytes.
|
||||
#[derive(Clone, PartialEq, Message)]
|
||||
pub struct JobOffer {
|
||||
#[prost(string, tag = "1")]
|
||||
pub job_id: String,
|
||||
#[prost(string, tag = "2")]
|
||||
pub attempt_id: String,
|
||||
#[prost(string, tag = "3")]
|
||||
pub authorization_id: String,
|
||||
#[prost(string, tag = "4")]
|
||||
pub plan_hash: String,
|
||||
#[prost(string, tag = "5")]
|
||||
pub job_payload_hash: String,
|
||||
#[prost(bytes = "vec", tag = "6")]
|
||||
pub payload_bytes: Vec<u8>,
|
||||
}
|
||||
#[derive(Clone, PartialEq, Message)]
|
||||
pub struct JobAccepted {
|
||||
#[prost(string, tag = "1")]
|
||||
pub job_id: String,
|
||||
#[prost(string, tag = "2")]
|
||||
pub attempt_id: String,
|
||||
#[prost(string, tag = "3")]
|
||||
pub job_payload_hash: String,
|
||||
#[prost(string, tag = "4")]
|
||||
pub journal_proof: String,
|
||||
}
|
||||
#[derive(Clone, PartialEq, Message)]
|
||||
pub struct ExecutionPermitRequest {
|
||||
#[prost(string, tag = "1")]
|
||||
pub job_id: String,
|
||||
#[prost(string, tag = "2")]
|
||||
pub attempt_id: String,
|
||||
#[prost(string, tag = "3")]
|
||||
pub job_payload_hash: String,
|
||||
#[prost(uint64, tag = "4")]
|
||||
pub assignment_version: u64,
|
||||
}
|
||||
/// Fixed Ed25519; verify exact payload_bytes using separately provisioned key.
|
||||
/// Never trust a key conveyed by the gateway as its own trust anchor.
|
||||
#[derive(Clone, PartialEq, Message)]
|
||||
pub struct ExecutionPermit {
|
||||
#[prost(bytes = "vec", tag = "1")]
|
||||
pub payload_bytes: Vec<u8>,
|
||||
#[prost(bytes = "vec", tag = "2")]
|
||||
pub signature: Vec<u8>,
|
||||
#[prost(string, tag = "3")]
|
||||
pub denial_code: String,
|
||||
}
|
||||
#[derive(Clone, PartialEq, Message)]
|
||||
pub struct JobStateChanged {
|
||||
#[prost(string, tag = "1")]
|
||||
pub job_id: String,
|
||||
#[prost(string, tag = "2")]
|
||||
pub attempt_id: String,
|
||||
#[prost(uint64, tag = "3")]
|
||||
pub revision: u64,
|
||||
#[prost(string, tag = "4")]
|
||||
pub state: String,
|
||||
#[prost(string, tag = "5")]
|
||||
pub grant_id: String,
|
||||
}
|
||||
#[derive(Clone, PartialEq, Message)]
|
||||
pub struct JobResult {
|
||||
#[prost(string, tag = "1")]
|
||||
pub job_id: String,
|
||||
#[prost(string, tag = "2")]
|
||||
pub attempt_id: String,
|
||||
#[prost(uint64, tag = "3")]
|
||||
pub revision: u64,
|
||||
#[prost(string, tag = "4")]
|
||||
pub state: String,
|
||||
#[prost(string, tag = "5")]
|
||||
pub grant_id: String,
|
||||
#[prost(bytes = "vec", tag = "6")]
|
||||
pub stdout: Vec<u8>,
|
||||
#[prost(bytes = "vec", tag = "7")]
|
||||
pub stderr: Vec<u8>,
|
||||
#[prost(bool, tag = "8")]
|
||||
pub output_truncated: bool,
|
||||
#[prost(bool, tag = "9")]
|
||||
pub reboot_required: bool,
|
||||
#[prost(int32, optional, tag = "10")]
|
||||
pub exit_code: Option<i32>,
|
||||
#[prost(string, tag = "11")]
|
||||
pub evidence_json: String,
|
||||
#[prost(string, tag = "12")]
|
||||
pub error_code: String,
|
||||
}
|
||||
#[derive(Clone, PartialEq, Message)]
|
||||
pub struct CancelRequest {
|
||||
#[prost(string, tag = "1")]
|
||||
pub job_id: String,
|
||||
#[prost(string, tag = "2")]
|
||||
pub attempt_id: String,
|
||||
#[prost(string, tag = "3")]
|
||||
pub reason: String,
|
||||
}
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn additive_job_offer_wire() {
|
||||
let offer = JobOffer {
|
||||
job_id: "j".into(),
|
||||
attempt_id: "a".into(),
|
||||
authorization_id: "h".into(),
|
||||
plan_hash: "p".into(),
|
||||
job_payload_hash: "b".into(),
|
||||
payload_bytes: vec![123, 125],
|
||||
};
|
||||
assert_eq!(
|
||||
offer.encode_to_vec(),
|
||||
vec![
|
||||
10, 1, 106, 18, 1, 97, 26, 1, 104, 34, 1, 112, 42, 1, 98, 50, 2, 123, 125
|
||||
]
|
||||
);
|
||||
let e = crate::Envelope {
|
||||
protocol_major: 1,
|
||||
payload: Some(crate::Payload::JobOffer(offer)),
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(
|
||||
crate::Envelope::decode(e.encode_to_vec().as_slice()).unwrap(),
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
//! Wire types mirror proto/agent.proto. Golden-wire tests protect stable tags.
|
||||
use prost::Message;
|
||||
use serde::{Deserialize, Serialize};
|
||||
mod jobs;
|
||||
pub use jobs::*;
|
||||
|
||||
#[derive(Clone, PartialEq, Message)]
|
||||
pub struct Envelope {
|
||||
#[prost(uint32, tag = "1")]
|
||||
pub protocol_major: u32,
|
||||
#[prost(uint32, tag = "2")]
|
||||
pub protocol_minor: u32,
|
||||
#[prost(string, tag = "3")]
|
||||
pub message_id: String,
|
||||
#[prost(string, tag = "4")]
|
||||
pub agent_id: String,
|
||||
#[prost(uint64, tag = "5")]
|
||||
pub enrollment_generation: u64,
|
||||
#[prost(uint64, tag = "6")]
|
||||
pub connection_generation: u64,
|
||||
#[prost(string, tag = "7")]
|
||||
pub boot_id: String,
|
||||
#[prost(uint64, tag = "8")]
|
||||
pub sequence: u64,
|
||||
#[prost(int64, tag = "9")]
|
||||
pub observed_at: i64,
|
||||
#[prost(
|
||||
oneof = "Payload",
|
||||
tags = "10, 11, 12, 13, 14, 20, 21, 22, 23, 24, 25, 26, 27, 28"
|
||||
)]
|
||||
pub payload: Option<Payload>,
|
||||
}
|
||||
#[derive(Clone, PartialEq, prost::Oneof)]
|
||||
pub enum Payload {
|
||||
#[prost(message, tag = "10")]
|
||||
ClientHello(ClientHello),
|
||||
#[prost(message, tag = "11")]
|
||||
ServerHello(ServerHello),
|
||||
#[prost(message, tag = "12")]
|
||||
Heartbeat(Heartbeat),
|
||||
#[prost(message, tag = "13")]
|
||||
InventorySnapshot(InventorySnapshot),
|
||||
#[prost(message, tag = "14")]
|
||||
Ack(Ack),
|
||||
#[prost(message, tag = "20")]
|
||||
JobOffer(JobOffer),
|
||||
#[prost(message, tag = "21")]
|
||||
JobAccepted(JobAccepted),
|
||||
#[prost(message, tag = "22")]
|
||||
ExecutionPermitRequest(ExecutionPermitRequest),
|
||||
#[prost(message, tag = "23")]
|
||||
ExecutionPermit(ExecutionPermit),
|
||||
#[prost(message, tag = "24")]
|
||||
JobStateChanged(JobStateChanged),
|
||||
#[prost(message, tag = "25")]
|
||||
JobResult(JobResult),
|
||||
#[prost(message, tag = "26")]
|
||||
CancelRequest(CancelRequest),
|
||||
#[prost(message, tag = "27")]
|
||||
SyncRequest(SyncRequest),
|
||||
#[prost(message, tag = "28")]
|
||||
SyncResponse(SyncResponse),
|
||||
}
|
||||
#[derive(Clone, PartialEq, Message)]
|
||||
pub struct ClientHello {
|
||||
#[prost(string, tag = "1")]
|
||||
pub agent_version: String,
|
||||
#[prost(string, repeated, tag = "2")]
|
||||
pub capabilities: Vec<String>,
|
||||
}
|
||||
#[derive(Clone, PartialEq, Message)]
|
||||
pub struct ServerHello {
|
||||
#[prost(uint64, tag = "1")]
|
||||
pub connection_generation: u64,
|
||||
#[prost(uint32, tag = "2")]
|
||||
pub max_message_bytes: u32,
|
||||
}
|
||||
#[derive(Clone, PartialEq, Message)]
|
||||
pub struct Heartbeat {
|
||||
#[prost(string, tag = "1")]
|
||||
pub instance_id: String,
|
||||
#[prost(uint64, tag = "2")]
|
||||
pub uptime_seconds: u64,
|
||||
}
|
||||
#[derive(Clone, PartialEq, Message)]
|
||||
pub struct InventorySnapshot {
|
||||
#[prost(string, tag = "1")]
|
||||
pub snapshot_id: String,
|
||||
#[prost(string, tag = "2")]
|
||||
pub scope: String,
|
||||
#[prost(uint32, tag = "3")]
|
||||
pub schema_version: u32,
|
||||
#[prost(uint32, tag = "4")]
|
||||
pub chunk_index: u32,
|
||||
#[prost(uint32, tag = "5")]
|
||||
pub chunk_count: u32,
|
||||
#[prost(bytes = "vec", tag = "6")]
|
||||
pub data: Vec<u8>,
|
||||
#[prost(bytes = "vec", tag = "7")]
|
||||
pub sha256: Vec<u8>,
|
||||
#[prost(string, tag = "8")]
|
||||
pub completeness: String,
|
||||
}
|
||||
#[derive(Clone, PartialEq, Message)]
|
||||
pub struct Ack {
|
||||
#[prost(string, tag = "1")]
|
||||
pub message_id: String,
|
||||
}
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct EnrollmentRequest {
|
||||
pub token: String,
|
||||
pub csr_pem: String,
|
||||
}
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct EnrollmentResponse {
|
||||
pub agent_id: String,
|
||||
pub asset_id: String,
|
||||
pub certificate_pem: String,
|
||||
}
|
||||
/// HTTP batch profile 1. Maximum 16 envelopes and 1 MiB encoded total.
|
||||
#[derive(Clone, PartialEq, Message)]
|
||||
pub struct MessageBatch {
|
||||
#[prost(uint32, tag = "1")]
|
||||
pub protocol_major: u32,
|
||||
#[prost(message, repeated, tag = "2")]
|
||||
pub messages: Vec<Envelope>,
|
||||
}
|
||||
/// Submit one fresh heartbeat/control envelope and wait up to 25 seconds.
|
||||
#[derive(Clone, PartialEq, Message)]
|
||||
pub struct PollRequest {
|
||||
#[prost(message, optional, tag = "1")]
|
||||
pub envelope: Option<Envelope>,
|
||||
#[prost(uint32, tag = "2")]
|
||||
pub wait_seconds: u32,
|
||||
}
|
||||
pub fn valid_envelope(e: &Envelope, agent: &str, generation: u64) -> bool {
|
||||
e.protocol_major == 1
|
||||
&& e.protocol_minor == 0
|
||||
&& e.agent_id == agent
|
||||
&& e.enrollment_generation == 1
|
||||
&& e.connection_generation == generation
|
||||
&& uuid::Uuid::parse_str(&e.message_id).is_ok()
|
||||
&& uuid::Uuid::parse_str(&e.boot_id).is_ok()
|
||||
&& e.sequence > 0
|
||||
&& e.payload.is_some()
|
||||
}
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn golden_heartbeat_and_unknown_major() {
|
||||
let e = Envelope {
|
||||
protocol_major: 1,
|
||||
payload: Some(Payload::Heartbeat(Heartbeat {
|
||||
instance_id: "x".into(),
|
||||
uptime_seconds: 1,
|
||||
})),
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(e.encode_to_vec(), vec![8, 1, 98, 5, 10, 1, 120, 16, 1]);
|
||||
assert_eq!(Envelope::decode(e.encode_to_vec().as_slice()).unwrap(), e);
|
||||
assert!(!valid_envelope(&e, "", 0));
|
||||
}
|
||||
#[test]
|
||||
fn http_batch_wire_golden() {
|
||||
let batch = MessageBatch {
|
||||
protocol_major: 1,
|
||||
messages: vec![Envelope {
|
||||
protocol_major: 1,
|
||||
..Default::default()
|
||||
}],
|
||||
};
|
||||
assert_eq!(batch.encode_to_vec(), vec![8, 1, 18, 2, 8, 1]);
|
||||
assert_eq!(
|
||||
MessageBatch::decode(batch.encode_to_vec().as_slice()).unwrap(),
|
||||
batch
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user