Qualify tenant-scoped bootstrap rotation and fresh Windows scripting

This commit is contained in:
2026-11-17 16:19:08 +01:00
parent 81fcd9c8f8
commit fbd24b6d75
26 changed files with 877 additions and 118 deletions
+32 -5
View File
@@ -9,14 +9,41 @@ struct Config {
updater_sha256: String,
updater_bytes: u64,
}
fn config(platform: Platform) -> Result<Config, Error> {
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
struct Pin { sha256: String, bytes: u64 }
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
struct Previous { pin: Pin, expires_at: i64 }
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
struct TenantPins { current: Pin, previous: Vec<Previous> }
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
pub(super) struct UpdaterQuery { platform: Platform, sha256: Option<String> }
fn config(platform: Platform, tenant: Uuid, wanted: Option<&str>) -> Result<Config, Error> {
let slot = match platform {
Platform::LinuxX64 => "RMM_AGENT_BOOTSTRAP_LINUX_FILE",
Platform::WindowsX64 => "RMM_AGENT_BOOTSTRAP_WINDOWS_FILE",
Platform::WindowsGnuX64 => "RMM_AGENT_BOOTSTRAP_WINDOWS_GNU_FILE",
};
let path = std::env::var(slot).map_err(|_| fail("BOOTSTRAP_NOT_CONFIGURED"))?;
let config: Config = serde_json::from_slice(&protected_file(FsPath::new(&path), 8192)?)?;
let path = FsPath::new(&path);
let mut config: Config = serde_json::from_slice(&protected_file(path, 8192)?)?;
let scoped = path.with_extension(format!("{tenant}.json"));
if scoped.try_exists().map_err(|_| fail("BOOTSTRAP_CONFIGURATION_INVALID"))? {
let pins: TenantPins = serde_json::from_slice(&protected_file(&scoped, 32768)?)?;
let selected = match wanted {
Some(digest) if pins.current.sha256 != digest => pins.previous.into_iter()
.find(|p| p.pin.sha256 == digest && p.expires_at > chrono::Utc::now().timestamp())
.map(|p| p.pin).ok_or_else(missing)?,
_ => pins.current,
};
config.updater_sha256 = selected.sha256;
config.updater_bytes = selected.bytes;
}
if wanted.is_some_and(|digest| digest != config.updater_sha256) { return Err(missing()); }
let url = url::Url::parse(&config.gateway_origin).map_err(|_| invalid())?;
if url.scheme() != "https"
|| url.domain().is_none()
@@ -143,7 +170,7 @@ pub(super) async fn current(
Query(q): Query<Current>,
) -> Result<Response, Error> {
let t = token_tenant(&s, &headers).await?;
let c = config(q.platform)?;
let c = config(q.platform, t, None)?;
let mut tx = rmm_persistence::tenant_tx(&s.pool, t).await?;
let release: Uuid = sqlx::query_scalar("SELECT release_id FROM agent_update_releases WHERE platform=$1 ORDER BY release_sequence DESC LIMIT 1")
.bind(platform_name(q.platform)).fetch_optional(&mut *tx).await?.ok_or_else(missing)?;
@@ -187,9 +214,9 @@ pub(super) async fn artifact(
pub(super) async fn updater(
State(s): State<crate::State>,
headers: HeaderMap,
Query(q): Query<Current>,
Query(q): Query<UpdaterQuery>,
) -> Result<Response, Error> {
let tenant = token_tenant(&s, &headers).await?;
let c = config(q.platform)?;
let c = config(q.platform, tenant, q.sha256.as_deref())?;
verified_binary(tenant, c.updater_sha256, c.updater_bytes).await
}