Integrate signed agent catalog, tenant enrollment and HTTPS installers

This commit is contained in:
2026-11-17 15:56:18 +01:00
parent 689f326460
commit 7fd17272d5
70 changed files with 12982 additions and 327 deletions
@@ -1,6 +1,7 @@
//! Passive TLS renewal. SQLite commits only public CSR/certificate/version data;
//! private keys stay in immutable, protected files outside the telemetry WAL.
//! The caller must retain the existing exclusive agent-state journal lock.
//! Mutation/current callers retain the exclusive agent-state journal lock.
//! `read_only_current` is the bounded, snapshot-only stable-updater exception.
use anyhow::{Context, Result, ensure};
use rcgen::{CertificateParams, DnType, KeyPair};
use rusqlite::{Connection, OptionalExtension, params};
@@ -119,6 +120,48 @@ impl RotationStore {
private_key_pem: key,
})
}
/// Independent stable-updater mTLS read ONLY. This cannot initialize,
/// rotate, acknowledge, alter selectors, enroll or allocate a generation.
/// Concurrent rotation may make transport fail; it never selects a key
/// from another device or treats old TLS as an execution/sync lease.
pub fn read_only_current(
&self,
db: &Connection,
keys: &impl KeyFiles,
now: i64,
) -> Result<DeviceIdentity> {
ensure!(
unsafe { rusqlite::ffi::sqlite3_db_readonly(db.handle(), c"main".as_ptr()) } == 1
&& db.query_row("PRAGMA query_only", [], |r| r.get::<_, bool>(0))?
&& !db.query_row("PRAGMA trusted_schema", [], |r| r.get::<_, bool>(0))?,
"ROTATION_READ_ONLY_CONNECTION_REQUIRED"
);
let tx = db.unchecked_transaction()?;
for table in ["tls_rotation", "tls_versions"] {
ensure!(
tx.query_row(
"SELECT type FROM sqlite_master WHERE name=?1",
[table],
|r| r.get::<_, String>(0)
)? == "table",
"ROTATION_SELECTOR_MUST_BE_TABLE"
);
}
let (version, _) = self.selector(&tx)?;
let length: u64 = tx.query_row(
"SELECT length(certificate) FROM tls_versions WHERE version=?1",
[version.to_string()],
|r| r.get(0),
)?;
ensure!(length > 0 && length <= 32768, "ROTATION_CERTIFICATE_LIMIT");
let identity = self.current(&tx, keys, now)?;
ensure!(
self.selector(&tx)?.0 == version,
"ROTATION_READ_ONLY_SNAPSHOT_CHANGED"
);
tx.commit()?;
Ok(identity)
}
fn verify(&self, pem: &[u8], key: &[u8], now: i64) -> Result<(i64, i64)> {
ensure!(
pem.len() <= 32768 && key.len() <= 16384,
@@ -590,6 +633,29 @@ mod tests {
.unwrap()
}
#[test]
fn updater_tls_snapshot_requires_read_only_handle_and_preserves_selector() {
let (db, keys, store, _, cert) = setup();
db.execute_batch("PRAGMA trusted_schema=OFF;PRAGMA query_only=ON")
.unwrap();
assert!(store.read_only_current(&db, &keys, now()).is_err());
db.execute_batch("PRAGMA query_only=OFF").unwrap();
let path = std::env::temp_dir().join(format!("rmm-tls-read-{}.sqlite", Uuid::new_v4()));
db.execute("VACUUM INTO ?1", [path.to_str().unwrap()])
.unwrap();
let read =
Connection::open_with_flags(&path, rusqlite::OpenFlags::SQLITE_OPEN_READ_ONLY).unwrap();
assert!(store.read_only_current(&read, &keys, now()).is_err());
read.execute_batch("PRAGMA query_only=ON;PRAGMA trusted_schema=OFF")
.unwrap();
let before = store.selector(&read).unwrap();
let identity = store.read_only_current(&read, &keys, now()).unwrap();
assert_eq!(identity.certificate_pem, cert.as_bytes());
assert_eq!(identity.private_key_pem, keys.read(Uuid::nil()).unwrap());
assert_eq!(store.selector(&read).unwrap(), before);
drop(read);
std::fs::remove_file(path).unwrap();
}
#[test]
fn active_idle_admission_is_atomic_retained_and_cannot_adopt_legacy_pending() {
let (mut db, keys, store, _, _) = setup();
let witness = b"exact independently checked idle context";