Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 7 additions & 2 deletions crates/inventory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,26 @@ pub type PackageSnapshot = BTreeMap<String, String>;

/// What happened to one package between two snapshots.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(missing_docs)] // #362
pub enum PackageChangeKind {
/// The package is in the new snapshot but not in the old one.
Added,
/// The package was in the old snapshot and is gone from the new one.
Removed,
/// The package is in both snapshots with a different version.
Upgraded,
}

/// One package's change between two snapshots, enough to build the
/// `schema::PackageChangeEvent` the agent emits for it.
#[derive(Debug, Clone, PartialEq, Eq)]
#[allow(missing_docs)] // #362
pub struct PackageChange {
/// Package name, the key of the [`PackageSnapshot`] entry.
pub package: String,
/// Whether the package was added, removed or upgraded.
pub kind: PackageChangeKind,
/// Version in the old snapshot; `None` for an added package.
pub previous_version: Option<String>,
/// Version in the new snapshot; `None` for a removed package.
pub version: Option<String>,
}

Expand Down
25 changes: 20 additions & 5 deletions crates/response/src/kill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,36 @@ use policy::ResponsePolicy;
/// #25's "policy off = observe-only" acceptance criterion: observing is not a
/// different code path from acting, just a different variant of the same result).
#[derive(Debug, Clone, PartialEq, Eq)]
#[allow(missing_docs)] // #362
pub enum KillOutcome {
/// The process was signaled; `terminate` reported success.
Killed { pid: u32 },
Killed {
/// Process id that was signaled.
pid: u32,
},
/// `policy.kill_enabled` was false — no signal was sent.
ObserveOnly { pid: u32 },
ObserveOnly {
/// Process id that would have been signaled.
pid: u32,
},
/// `policy.kill_enabled` was true, but `terminate` failed (already exited,
/// permission denied, ...). `error` is `terminate`'s error rendered to a string,
/// not a structured type — this crate has no opinion on the caller's OS error type.
Failed { pid: u32, error: String },
Failed {
/// Process id `terminate` was called on.
pid: u32,
/// `terminate`'s error, rendered to a string.
error: String,
},
/// The pid is one this crate never signals, whatever the policy says (see
/// [`protected_reason`]). Reported instead of [`KillOutcome::ObserveOnly`]
/// even with kill disabled, so the audit line says the truth: it would not
/// have been killed, rather than that it would have.
Refused { pid: u32, reason: &'static str },
Refused {
/// The protected process id that was not signaled.
pid: u32,
/// Why the pid is protected, as returned by [`protected_reason`].
reason: &'static str,
},
}

/// Why `pid` must never be handed to `terminate`, or `None` when it may be.
Expand Down
16 changes: 13 additions & 3 deletions crates/response/src/quarantine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,30 @@ use policy::ResponsePolicy;
/// this is one enum covering both the acted and observe-only cases rather than two
/// separate code paths.
#[derive(Debug, Clone, PartialEq, Eq)]
#[allow(missing_docs)] // #362
pub enum QuarantineOutcome {
/// `path` was moved into `quarantine_dir` under a digest-based name. Identical
/// payloads use a numeric suffix so each original path has its own record.
Quarantined {
/// The path the file had before it was moved.
original: PathBuf,
/// Where the file now lives inside `quarantine_dir`.
quarantined_at: PathBuf,
/// Lowercase hex SHA-256 of the quarantined content.
sha256_hex: String,
},
/// `policy.quarantine_enabled` was false — `path` was left untouched.
ObserveOnly { path: PathBuf },
ObserveOnly {
/// The path that would have been quarantined.
path: PathBuf,
},
/// Policy allowed it, but hashing or the move failed (already gone, permission
/// denied, ...). `error` is the underlying `io::Error` rendered to a string.
Failed { path: PathBuf, error: String },
Failed {
/// The path whose quarantine failed.
path: PathBuf,
/// The underlying `io::Error`, rendered to a string.
error: String,
},
}

/// Policy-gates quarantining `path` into `quarantine_dir` (created if missing).
Expand Down
5 changes: 4 additions & 1 deletion crates/sinks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,13 @@ fn needs_tail_repair(path: &Path) -> bool {
/// on-disk record stays a sink concern: the agent converts whatever its detection
/// engines emit into this record.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[allow(missing_docs)] // #362
pub struct AlertRecord {
/// When the record was written, in nanoseconds since the UNIX epoch.
pub timestamp_ns: u64,
/// ATT&CK technique id, or the label of an internal finding (`RESPONSE-ESCALATE`, `BAYES`,
/// `Sigma`, the watchdog's `SELF-PROTECTION`).
pub technique: String,
/// Human-readable description of what was detected.
pub message: String,
}

Expand Down
16 changes: 12 additions & 4 deletions crates/tamper/src/integrity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,33 @@ impl Manifest {

/// What is wrong with one protected path (each variant is one failed check).
#[derive(Debug, Clone, PartialEq, Eq)]
#[allow(missing_docs)] // #362
pub enum ViolationKind {
/// The file exists and was hashed, but the hash does not match the manifest —
/// the artifact was replaced or edited.
Modified { expected: String, actual: String },
Modified {
/// Hash the manifest records for the path.
expected: String,
/// Hash computed from the file on disk.
actual: String,
},
/// The protected path is gone — an uninstall or a move as a prelude to a swap.
Missing,
/// The path exists but could not be read as a regular file (a FIFO/device
/// planted at the path, a permissions change, an I/O error).
Unreadable,
/// The file grew past [`MAX_VERIFY_BYTES`] — suspicious in its own right.
Oversized { size: u64 },
Oversized {
/// Size of the file in bytes.
size: u64,
},
}

/// One protected path that failed verification.
#[derive(Debug, Clone, PartialEq, Eq)]
#[allow(missing_docs)] // #362
pub struct IntegrityViolation {
/// The protected path that failed its check.
pub path: PathBuf,
/// Which check failed.
pub kind: ViolationKind,
}

Expand Down
3 changes: 2 additions & 1 deletion crates/transport/src/detection_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ const SERVER_INVALID_PAYLOAD: &str = "Invalid payload";
/// The retry identity is persisted in the same spool record as its detection.
/// Reopening an in-flight segment therefore reuses the exact same key.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[allow(missing_docs)] // #362
pub struct QueuedDetection {
/// Idempotency key sent with every attempt, so a retry is recognised as the same upload.
pub key: String,
/// The detection to upload.
pub detection: Detection,
}

Expand Down
15 changes: 12 additions & 3 deletions crates/transport/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ pub type Result<T> = std::result::Result<T, TransportError>;

/// Errors that can occur during transport operations.
#[derive(Debug, Error)]
#[allow(missing_docs)] // #362
pub enum TransportError {
/// Server returned an error status code.
#[error("server error: {status} - {message}")]
ServerError { status: u16, message: String },
ServerError {
/// HTTP status code of the response.
status: u16,
/// The server's `error`, `message` or `reason` string, else the response body, else
/// `http status: N` when the body is empty. The body is read up to 2 KiB, and control and
/// bidi characters are stripped, so a log reader can trust it is one printable line.
message: String,
},

/// Network error (connection refused, timeout, etc.).
#[error("network error: {0}")]
Expand Down Expand Up @@ -46,7 +52,10 @@ pub enum TransportError {
/// lost silently: the segment is not acknowledged, so the next drain delivers it again, and
/// only the attempt budget skips it, with a warning that counts what was dropped.
#[error("{count} event(s) cannot be sent under the body limit")]
Unsendable { count: usize },
Unsendable {
/// How many events of the segment could not be shortened.
count: usize,
},

/// Server is unreachable (for graceful degradation).
#[error("server unreachable")]
Expand Down
2 changes: 1 addition & 1 deletion crates/updater/src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ impl ContentEntry {
/// Field order is alphabetical and fixed by declaration — canonicalization
/// relies on it, exactly like [`crate::manifest::ReleaseManifest`].
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[allow(missing_docs)] // #362
pub struct ContentManifest {
/// The content files this release lists, each with its path and hash.
pub entries: Vec<ContentEntry>,
/// Monotone, strictly increasing per `ring`. See [`Self::check_release_version`].
pub release_version: u64,
Expand Down
82 changes: 69 additions & 13 deletions crates/updater/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ use thiserror::Error;

/// Everything that can go wrong staging, verifying, or promoting a release.
#[derive(Debug, Error)]
#[allow(missing_docs)] // #362
pub enum UpdaterError {
/// The manifest's `schema_version` is not one this build understands
/// (ADR-0015 Decision 2: readers reject an unknown value outright).
#[error("manifest schema_version {found} is not supported (expected {expected})")]
SchemaVersionUnsupported { found: u32, expected: u32 },
SchemaVersionUnsupported {
/// The `schema_version` the manifest carries.
found: u32,
/// The `schema_version` this build understands.
expected: u32,
},

/// The manifest's Ed25519 signature does not verify against the embedded
/// public key.
Expand All @@ -28,22 +32,35 @@ pub enum UpdaterError {
/// `release_version` is not strictly greater than the currently installed
/// one (ADR-0015 Decision 2: anti-rollback-attack check).
#[error("release {offered} is not newer than the installed release {current}")]
ReleaseNotNewer { offered: u64, current: u64 },
ReleaseNotNewer {
/// The `release_version` the manifest offers.
offered: u64,
/// The `release_version` currently installed.
current: u64,
},

/// A content manifest lists nothing while the agent has applied content: applying it
/// would delete every recorded file and leave the agent with no rules. A release that
/// really withdraws everything must be a deliberate, separate decision; an empty or
/// mis-globbed build must not be able to do it by accident.
#[error("the manifest lists no content but {would_remove} applied file(s) would be removed")]
EmptyContentManifest { would_remove: usize },
EmptyContentManifest {
/// How many applied files the empty manifest would remove.
would_remove: usize,
},

/// A content manifest's `ring` does not match the ring the caller actually
/// requested. A valid signature only proves "we signed this manifest", not
/// "this is the manifest for the ring you asked for" — without this check a
/// correctly-signed manifest for a different (e.g. less-vetted canary) ring
/// would still verify and be accepted.
#[error("manifest is for ring `{found}`, expected `{requested}`")]
RingMismatch { requested: String, found: String },
RingMismatch {
/// The ring the caller asked for.
requested: String,
/// The ring the manifest declares.
found: String,
},

/// `release_version` is on the local ban list — a previous install of this
/// exact release failed its health check (ADR-0015 Decision 6).
Expand All @@ -65,29 +82,48 @@ pub enum UpdaterError {

/// A file the manifest lists is missing from the staged release directory.
#[error("staged release is missing manifest entry `{path}`")]
StagedFileMissing { path: PathBuf },
StagedFileMissing {
/// The manifest entry path that has no file in the staged directory.
path: PathBuf,
},

/// A staged file's content does not match the manifest's recorded hash.
#[error("staged file `{path}` hash mismatch (expected {expected}, found {actual})")]
StagedFileMismatch {
/// The staged file whose hash differs.
path: PathBuf,
/// The hash the manifest records.
expected: String,
/// The hash computed from the staged file.
actual: String,
},

/// A snapshot manifest's `kind` is not one this build knows (ADR-0033: only `common-set`).
#[error("snapshot manifest kind `{found}` is not supported")]
SnapshotKindUnsupported { found: String },
SnapshotKindUnsupported {
/// The `kind` the snapshot manifest declares.
found: String,
},

/// A snapshot manifest's `built_at` is not later than the snapshot in force: a replay or a
/// rollback of the server's own state. The snapshot in force stays (ADR-0033 decision 3).
#[error("snapshot built at {offered} is not newer than the one in force ({current})")]
SnapshotNotNewer { offered: u64, current: u64 },
SnapshotNotNewer {
/// The `built_at` of the offered snapshot.
offered: u64,
/// The `built_at` of the snapshot in force.
current: u64,
},

/// A snapshot manifest claims to be built further in the future than the clock-skew
/// tolerance allows: a wrong server clock, or a manifest made to outlive its maximum age.
#[error("snapshot built at {built_at} is dated beyond now ({now}) plus the tolerance")]
SnapshotFromFuture { built_at: u64, now: u64 },
SnapshotFromFuture {
/// The `built_at` the manifest claims.
built_at: u64,
/// The local clock reading it was compared with.
now: u64,
},

/// The artifact does not match the signed manifest that names it (size, hash, or a header
/// that disagrees with the manifest).
Expand All @@ -105,25 +141,41 @@ pub enum UpdaterError {
#[error(
"key-rotation manifest does not apply: it retires a {role} key this install does not trust"
)]
RotationDoesNotApply { role: &'static str },
RotationDoesNotApply {
/// The key role (`release` or `content`) the manifest tried to retire a key for.
role: &'static str,
},

/// A key-rotation manifest is past its `expires_at`.
#[error("key-rotation manifest expired at {expires_at} (now {now})")]
RotationExpired { expires_at: u64, now: u64 },
RotationExpired {
/// The manifest's `expires_at`.
expires_at: u64,
/// The local clock reading it was compared with.
now: u64,
},

/// A key-rotation manifest is dated beyond now plus the clock-skew tolerance.
#[error(
"key-rotation manifest issued at {issued_at} is dated beyond now ({now}) plus the tolerance"
)]
RotationNotYetValid { issued_at: u64, now: u64 },
RotationNotYetValid {
/// The manifest's `issued_at`.
issued_at: u64,
/// The local clock reading it was compared with.
now: u64,
},

/// The file that records the applied key rotations exists but cannot be trusted: it does not
/// parse, one of its rotations does not verify under the embedded `recovery` key, they are not
/// in increasing `release_version` order, or they do not lead from this build's embedded keys.
/// Refused rather than ignored: a file that exists proves a rotation happened, and falling
/// back to the embedded keys could re-trust a key that was rotated away from.
#[error("the key-rotation record is not trustworthy: {reason}")]
TrustStateCorrupt { reason: String },
TrustStateCorrupt {
/// Which of the checks on the record failed.
reason: String,
},

/// The install already holds [`crate::trust_state::MAX_ROTATIONS`] rotations.
#[error("this install already holds the maximum of {0} recorded key rotations")]
Expand All @@ -133,7 +185,9 @@ pub enum UpdaterError {
/// specifics (missing permissions, disk full, etc).
#[error("I/O error on {path}: {source}")]
Io {
/// The file or directory the operation was on.
path: PathBuf,
/// The underlying I/O error.
#[source]
source: std::io::Error,
},
Expand All @@ -143,7 +197,9 @@ pub enum UpdaterError {
/// never expected from this crate's own [`crate::layout::Layout::persist_manifest`].
#[error("manifest at {path} is corrupt: {source}")]
ManifestCorrupt {
/// The persisted manifest file.
path: PathBuf,
/// The JSON error from parsing it.
#[source]
source: serde_json::Error,
},
Expand Down
Loading
Loading