Implement guarded Linux updater runtime and compatible baseline tooling
Rust development slice / linux (push) Failing after 8s
Rust development slice / linux (push) Failing after 8s
This commit is contained in:
@@ -134,19 +134,61 @@ fn verifier_platform(platform: Platform) -> rmm_updater::Platform {
|
||||
Platform::WindowsX64 => rmm_updater::Platform::WindowsX64,
|
||||
}
|
||||
}
|
||||
/// Network input can choose only one of two statically named protected
|
||||
/// configuration slots. It never supplies a path or introduces update trust.
|
||||
fn keyring_path_with(
|
||||
platform: Platform,
|
||||
lookup: impl Fn(&str) -> Result<Option<String>, Error>,
|
||||
) -> Result<std::path::PathBuf, Error> {
|
||||
let name = match platform {
|
||||
Platform::LinuxX64 => "RMM_AGENT_UPDATE_LINUX_KEYRING_FILE",
|
||||
Platform::WindowsX64 => "RMM_AGENT_UPDATE_WINDOWS_KEYRING_FILE",
|
||||
};
|
||||
if let Some(path) = lookup(name)? {
|
||||
if path.is_empty() || !FsPath::new(&path).is_absolute() {
|
||||
return Err(fail("AGENT_UPDATE_NOT_CONFIGURED"));
|
||||
}
|
||||
return Ok(path.into());
|
||||
}
|
||||
// Exact legacy compatibility only when the platform-specific slot is
|
||||
// absent. An invalid explicit slot must never silently choose other trust.
|
||||
lookup("RMM_AGENT_UPDATE_KEYRING_FILE")?
|
||||
.map(Into::into)
|
||||
.ok_or_else(|| fail("AGENT_UPDATE_NOT_CONFIGURED"))
|
||||
}
|
||||
pub fn verify_envelope(
|
||||
envelope: &ReleaseEnvelope,
|
||||
binding: Option<&rmm_domain::agent_update::UpdaterBinding>,
|
||||
) -> Result<ReleaseManifest, Error> {
|
||||
let platform = envelope.decode().map_err(|_| invalid())?.manifest.platform;
|
||||
let path = keyring_path_with(platform, |name| match std::env::var(name) {
|
||||
Ok(value) => Ok(Some(value)),
|
||||
Err(std::env::VarError::NotPresent) => Ok(None),
|
||||
Err(std::env::VarError::NotUnicode(_)) => Err(fail("AGENT_UPDATE_NOT_CONFIGURED")),
|
||||
})?;
|
||||
let raw = protected_file(&path, 16384)?;
|
||||
verify_envelope_with_keyring(
|
||||
envelope,
|
||||
binding,
|
||||
&raw,
|
||||
chrono::Utc::now()
|
||||
.timestamp()
|
||||
.try_into()
|
||||
.map_err(|_| invalid())?,
|
||||
)
|
||||
}
|
||||
fn verify_envelope_with_keyring(
|
||||
envelope: &ReleaseEnvelope,
|
||||
binding: Option<&rmm_domain::agent_update::UpdaterBinding>,
|
||||
raw: &[u8],
|
||||
now_utc_seconds: u64,
|
||||
) -> Result<ReleaseManifest, Error> {
|
||||
let decoded = envelope.decode().map_err(|_| invalid())?;
|
||||
let path = std::env::var("RMM_AGENT_UPDATE_KEYRING_FILE")
|
||||
.map_err(|_| fail("AGENT_UPDATE_NOT_CONFIGURED"))?;
|
||||
let raw = protected_file(FsPath::new(&path), 16384)?;
|
||||
let config: rmm_domain::agent_update::UpdateKeyringFile =
|
||||
serde_json::from_slice(&raw).map_err(|_| fail("AGENT_UPDATE_TRUST_INVALID"))?;
|
||||
serde_json::from_slice(raw).map_err(|_| fail("AGENT_UPDATE_TRUST_INVALID"))?;
|
||||
if !config.validate()
|
||||
|| binding.is_some_and(|b| {
|
||||
b.keyring_generation != config.generation || b.keyring_sha256 != hash(&raw)
|
||||
b.keyring_generation != config.generation || b.keyring_sha256 != hash(raw)
|
||||
})
|
||||
{
|
||||
return Err(fail("AGENT_UPDATE_TRUST_INVALID"));
|
||||
@@ -174,10 +216,7 @@ pub fn verify_envelope(
|
||||
.map_err(|_| fail("AGENT_UPDATE_TRUST_INVALID"))?;
|
||||
let context = rmm_updater::TrustedContext {
|
||||
platform: verifier_platform(decoded.manifest.platform),
|
||||
now_utc_seconds: chrono::Utc::now()
|
||||
.timestamp()
|
||||
.try_into()
|
||||
.map_err(|_| invalid())?,
|
||||
now_utc_seconds,
|
||||
keyring_generation: config.generation,
|
||||
protocol_major: 1,
|
||||
state_schema: 1,
|
||||
@@ -826,6 +865,164 @@ pub async fn validate_current_target(
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn protected_keyring_slots_are_platform_specific_with_exact_legacy_fallback() {
|
||||
use std::collections::BTreeMap;
|
||||
let paths = BTreeMap::from([
|
||||
("RMM_AGENT_UPDATE_LINUX_KEYRING_FILE", "/trust/linux.json"),
|
||||
(
|
||||
"RMM_AGENT_UPDATE_WINDOWS_KEYRING_FILE",
|
||||
"/trust/windows.json",
|
||||
),
|
||||
("RMM_AGENT_UPDATE_KEYRING_FILE", "/trust/legacy.json"),
|
||||
]);
|
||||
let choose = |platform, map: &BTreeMap<&str, &str>| {
|
||||
keyring_path_with(platform, |name| Ok(map.get(name).map(|v| v.to_string())))
|
||||
};
|
||||
assert_eq!(
|
||||
choose(Platform::LinuxX64, &paths).unwrap(),
|
||||
FsPath::new("/trust/linux.json")
|
||||
);
|
||||
assert_eq!(
|
||||
choose(Platform::WindowsX64, &paths).unwrap(),
|
||||
FsPath::new("/trust/windows.json")
|
||||
);
|
||||
let legacy = BTreeMap::from([("RMM_AGENT_UPDATE_KEYRING_FILE", "legacy-relative.json")]);
|
||||
for platform in [Platform::LinuxX64, Platform::WindowsX64] {
|
||||
assert_eq!(
|
||||
choose(platform, &legacy).unwrap(),
|
||||
FsPath::new("legacy-relative.json")
|
||||
);
|
||||
}
|
||||
let only_linux =
|
||||
BTreeMap::from([("RMM_AGENT_UPDATE_LINUX_KEYRING_FILE", "/trust/linux.json")]);
|
||||
assert!(choose(Platform::WindowsX64, &only_linux).is_err());
|
||||
for invalid in ["", "relative.json"] {
|
||||
let wrong = BTreeMap::from([
|
||||
("RMM_AGENT_UPDATE_LINUX_KEYRING_FILE", invalid),
|
||||
("RMM_AGENT_UPDATE_KEYRING_FILE", "/trust/legacy.json"),
|
||||
]);
|
||||
assert!(choose(Platform::LinuxX64, &wrong).is_err());
|
||||
}
|
||||
assert!(
|
||||
keyring_path_with(Platform::WindowsX64, |_| Err(fail(
|
||||
"AGENT_UPDATE_NOT_CONFIGURED"
|
||||
)))
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn selected_platform_keyring_still_enforces_real_signatures_revocation_generation_and_raw_hash()
|
||||
{
|
||||
use base64::{Engine, engine::general_purpose::URL_SAFE_NO_PAD};
|
||||
use openssl::{pkey::PKey, sign::Signer};
|
||||
use rmm_domain::agent_update::{
|
||||
ArtifactRole, UpdateKeyringEntry, UpdateKeyringFile, UpdaterBinding,
|
||||
};
|
||||
let make = |platform| {
|
||||
let key = PKey::generate_ed25519().unwrap();
|
||||
let public = key.raw_public_key().unwrap();
|
||||
let manifest = ReleaseManifest {
|
||||
schema_version: 1,
|
||||
release_id: Uuid::new_v4(),
|
||||
release_sequence: 2,
|
||||
version: "0.1.1".into(),
|
||||
platform,
|
||||
published_at: 90,
|
||||
expires_at: 200,
|
||||
protocol_major: 1,
|
||||
state_schema: 1,
|
||||
minimum_updater_version: 1,
|
||||
artifacts: [
|
||||
ArtifactDescriptor {
|
||||
role: ArtifactRole::Agent,
|
||||
artifact_id: Uuid::new_v4(),
|
||||
sha256: hash(b"agent"),
|
||||
bytes: 10,
|
||||
},
|
||||
ArtifactDescriptor {
|
||||
role: ArtifactRole::Helper,
|
||||
artifact_id: Uuid::new_v4(),
|
||||
sha256: hash(b"helper"),
|
||||
bytes: 20,
|
||||
},
|
||||
],
|
||||
};
|
||||
let raw = encode(&manifest).unwrap();
|
||||
let mut message = rmm_updater::RELEASE_SIGNATURE_DOMAIN.to_vec();
|
||||
message.extend_from_slice(&raw);
|
||||
let signature = Signer::new_without_digest(&key)
|
||||
.unwrap()
|
||||
.sign_oneshot_to_vec(&message)
|
||||
.unwrap();
|
||||
let envelope = ReleaseEnvelope {
|
||||
schema_version: 1,
|
||||
key_id: hash(&public),
|
||||
payload_bytes: URL_SAFE_NO_PAD.encode(&raw),
|
||||
signature: URL_SAFE_NO_PAD.encode(signature),
|
||||
};
|
||||
let keys = UpdateKeyringFile {
|
||||
schema_version: 1,
|
||||
generation: 7,
|
||||
keys: vec![UpdateKeyringEntry {
|
||||
public_key_hex: hex::encode(public),
|
||||
platform,
|
||||
first_sequence: 1,
|
||||
last_sequence: 4,
|
||||
revoked: false,
|
||||
}],
|
||||
};
|
||||
(envelope, keys)
|
||||
};
|
||||
let (linux, linux_keys) = make(Platform::LinuxX64);
|
||||
let (windows, windows_keys) = make(Platform::WindowsX64);
|
||||
let linux_raw = encode(&linux_keys).unwrap();
|
||||
let windows_raw = encode(&windows_keys).unwrap();
|
||||
assert_eq!(
|
||||
verify_envelope_with_keyring(&linux, None, &linux_raw, 100)
|
||||
.unwrap()
|
||||
.platform,
|
||||
Platform::LinuxX64
|
||||
);
|
||||
assert_eq!(
|
||||
verify_envelope_with_keyring(&windows, None, &windows_raw, 100)
|
||||
.unwrap()
|
||||
.platform,
|
||||
Platform::WindowsX64
|
||||
);
|
||||
assert!(verify_envelope_with_keyring(&windows, None, &linux_raw, 100).is_err());
|
||||
assert!(verify_envelope_with_keyring(&linux, None, &windows_raw, 100).is_err());
|
||||
let fixture: Value = serde_json::from_str(include_str!(
|
||||
"../../../tests/agent_update/codec-golden.json"
|
||||
))
|
||||
.unwrap();
|
||||
let mut binding: UpdaterBinding = serde_json::from_value(
|
||||
fixture["linux_full"]["payload"]["jobs"][0]["payload"]["action"]["update"]["updater"]
|
||||
.clone(),
|
||||
)
|
||||
.unwrap();
|
||||
binding.keyring_generation = 7;
|
||||
binding.keyring_sha256 = hash(&linux_raw);
|
||||
assert!(verify_envelope_with_keyring(&linux, Some(&binding), &linux_raw, 100).is_ok());
|
||||
binding.keyring_generation = 8;
|
||||
assert!(verify_envelope_with_keyring(&linux, Some(&binding), &linux_raw, 100).is_err());
|
||||
binding.keyring_generation = 7;
|
||||
binding.keyring_sha256 = hash(b"different raw bytes");
|
||||
assert!(verify_envelope_with_keyring(&linux, Some(&binding), &linux_raw, 100).is_err());
|
||||
let mut forged = linux.clone();
|
||||
forged.signature = URL_SAFE_NO_PAD.encode([0u8; 64]);
|
||||
assert!(verify_envelope_with_keyring(&forged, None, &linux_raw, 100).is_err());
|
||||
let mut revoked = linux_keys;
|
||||
revoked.keys[0].revoked = true;
|
||||
assert!(
|
||||
verify_envelope_with_keyring(&linux, None, &encode(&revoked).unwrap(), 100).is_err()
|
||||
);
|
||||
let mut changed = linux.decode().unwrap().manifest;
|
||||
changed.platform = Platform::WindowsX64;
|
||||
let mut forged = linux;
|
||||
forged.payload_bytes = URL_SAFE_NO_PAD.encode(encode(&changed).unwrap());
|
||||
assert!(verify_envelope_with_keyring(&forged, None, &linux_raw, 100).is_err());
|
||||
}
|
||||
#[test]
|
||||
fn actual_codec_pair_plan_requires_exact_per_attempt_artifact_authority() {
|
||||
let fixtures: Value = serde_json::from_str(include_str!(
|
||||
"../../../tests/agent_update/codec-golden.json"
|
||||
|
||||
Reference in New Issue
Block a user