Implement independently authorized Windows checkpoint recovery
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -7,6 +7,7 @@ pub mod inventory_document;
|
||||
pub mod jobs;
|
||||
pub mod reconciliation;
|
||||
pub mod windows_execution;
|
||||
pub mod windows_sync_history;
|
||||
|
||||
pub const TENANT_A: &str = "11111111-1111-4111-8111-111111111111";
|
||||
pub const TENANT_B: &str = "22222222-2222-4222-8222-222222222222";
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
//! Public historical reference for the human-reviewed Windows incident of 15 November 2026.
|
||||
use chrono::{DateTime, Duration, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub const RECEIPT_DOMAIN: &str = "rmm.sync.windows-helper-checkpoint-human-repair";
|
||||
|
||||
/// Observed on the named server and guest. This reference cannot establish present readiness.
|
||||
pub fn case_witness() -> Value {
|
||||
serde_json::from_str(include_str!("windows_sync_history_case.json"))
|
||||
.expect("checked-in Windows witness")
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Receipt {
|
||||
pub domain: String,
|
||||
pub schema_version: u32,
|
||||
pub request_id: Uuid,
|
||||
pub receipt_id: Uuid,
|
||||
pub witness_sha256: String,
|
||||
pub witness: Value,
|
||||
pub key_id: String,
|
||||
pub issued_at: DateTime<Utc>,
|
||||
pub valid_until: DateTime<Utc>,
|
||||
pub confirmed_by: String,
|
||||
pub approval_origin: String,
|
||||
pub testsimulation: bool,
|
||||
pub ready: bool,
|
||||
pub helper_ready: bool,
|
||||
pub unlock: bool,
|
||||
}
|
||||
|
||||
impl Receipt {
|
||||
pub fn matches_human_review(&self, now: DateTime<Utc>) -> bool {
|
||||
self.matches_reviewed_witness(&case_witness(), now)
|
||||
}
|
||||
|
||||
/// Compare a receipt to an independently produced historical witness, after signature verification.
|
||||
pub fn matches_reviewed_witness(&self, expected: &Value, now: DateTime<Utc>) -> bool {
|
||||
let principal = self.confirmed_by.strip_prefix("oidc:");
|
||||
self.domain == RECEIPT_DOMAIN && self.schema_version == 1
|
||||
&& !self.receipt_id.is_nil() && !self.request_id.is_nil()
|
||||
&& self.request_id != self.receipt_id
|
||||
&& !self.testsimulation && !self.ready && !self.helper_ready && !self.unlock
|
||||
&& self.approval_origin == "human_webui"
|
||||
&& principal.is_some_and(|s| s.len() == 64 && s.bytes().all(|c| c.is_ascii_digit() || (b'a'..=b'f').contains(&c)))
|
||||
&& self.issued_at <= now && now < self.valid_until
|
||||
&& self.valid_until - self.issued_at <= Duration::minutes(10)
|
||||
&& self.key_id == expected["verification_key_id"]
|
||||
&& &self.witness == expected
|
||||
&& crate::checkpoint_repair::inventory_sha256(expected).is_ok_and(|h| h == self.witness_sha256)
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ mod scheduler;
|
||||
mod synchronization;
|
||||
mod tls;
|
||||
mod update_artifact_store;
|
||||
mod windows_checkpoint_review;
|
||||
mod windows_msi_catalog;
|
||||
mod windows_policy;
|
||||
|
||||
@@ -183,6 +184,7 @@ async fn main() -> Result<()> {
|
||||
if role.api() {
|
||||
if dev {
|
||||
routes = routes.route("/auth/dev/login", post(auth::login));
|
||||
routes = windows_checkpoint_review::routes(routes);
|
||||
}
|
||||
routes = routes
|
||||
.route("/auth/config", get(auth::configuration))
|
||||
|
||||
@@ -0,0 +1,648 @@
|
||||
//! Individually reviewed Windows control-history repair. No job or ordinary
|
||||
//! reconciliation decision can be issued through this development-only route.
|
||||
use crate::{auth::Principal, jobs::Error};
|
||||
use axum::{
|
||||
Json, Router,
|
||||
extract::{Path, State},
|
||||
http::{HeaderMap, StatusCode},
|
||||
routing::{get, post},
|
||||
};
|
||||
use chrono::{DateTime, Duration, Utc};
|
||||
use openssl::{
|
||||
pkey::{Id, PKey},
|
||||
sign::Verifier,
|
||||
};
|
||||
use rmm_domain::{
|
||||
checkpoint_repair::{SignedReceipt, inventory_sha256},
|
||||
jobs::hash,
|
||||
reconciliation::ReconcileDecisionPayload,
|
||||
windows_sync_history::{RECEIPT_DOMAIN, Receipt, case_witness},
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::{Value, json};
|
||||
use sqlx::{Postgres, Row, Transaction};
|
||||
use uuid::Uuid;
|
||||
|
||||
type Result<T> = std::result::Result<T, Error>;
|
||||
const CASE_AGENT: Uuid = Uuid::from_u128(0x63ea15b20643403db5b4cba1288dbea3);
|
||||
const CASE_ASSET: Uuid = Uuid::from_u128(0xa176520e8a914e93a78b8e7620f430e0);
|
||||
const CASE_TENANT: Uuid = Uuid::from_u128(0x11111111111141118111111111111111);
|
||||
const FIRST: Uuid = Uuid::from_u128(0xb6a3101f68ad41c8be4e4c7c2bc963d6);
|
||||
const DENIED: Uuid = Uuid::from_u128(0x0633a4de7e524e5da2a159fb134817fe);
|
||||
const CERTIFICATE: &str = "c55aa8214cb8d60382fe453bddd56c6e46fa79b61ccefda502e001be56bb5075";
|
||||
|
||||
fn changed() -> Error {
|
||||
Error(StatusCode::CONFLICT, "WINDOWS_RECOVERY_WITNESS_CHANGED")
|
||||
}
|
||||
fn missing() -> Error {
|
||||
Error(StatusCode::NOT_FOUND, "NOT_FOUND")
|
||||
}
|
||||
fn forbidden() -> Error {
|
||||
Error(StatusCode::FORBIDDEN, "REAL_HUMAN_WEBUI_REQUIRED")
|
||||
}
|
||||
pub fn routes(r: Router<crate::State>) -> Router<crate::State> {
|
||||
r.route(
|
||||
"/api/v1/tenants/{tenant}/windows-checkpoint-recovery",
|
||||
get(read).post(submit),
|
||||
)
|
||||
.route(
|
||||
"/api/v1/tenants/{tenant}/windows-checkpoint-recovery/{request}/confirm",
|
||||
post(confirm),
|
||||
)
|
||||
.route(
|
||||
"/api/v1/tenants/{tenant}/windows-checkpoint-recovery/{request}/receipt",
|
||||
get(download),
|
||||
)
|
||||
}
|
||||
async fn access(s: &crate::State, h: &HeaderMap, t: Uuid, write: bool) -> Result<Principal> {
|
||||
let p = s
|
||||
.auth
|
||||
.principal(s, h, write)
|
||||
.await
|
||||
.map_err(|status| Error(status, crate::auth::error_code(status)))?;
|
||||
crate::jobs::scope(&p, t, write)?;
|
||||
if t != CASE_TENANT {
|
||||
return Err(missing());
|
||||
}
|
||||
Ok(p)
|
||||
}
|
||||
fn real_browser(p: &Principal) -> Result<&str> {
|
||||
if p.testsimulation
|
||||
|| p.scopes.is_some()
|
||||
|| p.identity.is_none()
|
||||
|| p.csrf.is_none()
|
||||
|| !p.operator
|
||||
{
|
||||
return Err(forbidden());
|
||||
}
|
||||
p.session_hash.as_deref().ok_or_else(forbidden)
|
||||
}
|
||||
async fn reviewer(tx: &mut Transaction<'_, Postgres>, p: &Principal) -> Result<()> {
|
||||
real_browser(p)?;
|
||||
// Hold the current human membership through the commit.
|
||||
let identity = p.identity.as_ref().ok_or_else(forbidden)?;
|
||||
let allowed: bool = sqlx::query_scalar("SELECT lock_windows_checkpoint_reviewer($1,$2,$3)")
|
||||
.bind(&p.name)
|
||||
.bind(&identity.issuer)
|
||||
.bind(&identity.subject)
|
||||
.fetch_one(&mut **tx)
|
||||
.await?;
|
||||
if !allowed {
|
||||
return Err(forbidden());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn view(tx: &mut Transaction<'_, Postgres>) -> Result<Value> {
|
||||
let row=sqlx::query_scalar::<_,Value>(
|
||||
"SELECT jsonb_build_object('request_id',r.request_id,'tenant_id',r.tenant_id,'asset_id',r.asset_id,
|
||||
'agent_id',r.agent_id,'witness_sha256',r.witness_sha256,'witness',r.witness,
|
||||
'status',CASE WHEN c.receipt_id IS NULL THEN 'pending_review' ELSE 'confirmed' END,
|
||||
'confirmed_by',c.confirmed_by,'confirmed_at',c.issued_at,'receipt_id',c.receipt_id,'receipt_valid_until',c.valid_until)
|
||||
FROM windows_checkpoint_reviews r LEFT JOIN LATERAL
|
||||
(SELECT * FROM windows_checkpoint_review_receipts WHERE tenant_id=r.tenant_id AND request_id=r.request_id
|
||||
ORDER BY issued_at DESC,receipt_id DESC LIMIT 1) c ON true
|
||||
WHERE r.tenant_id=$1 AND r.agent_id=$2").bind(CASE_TENANT).bind(CASE_AGENT).fetch_optional(&mut **tx).await?;
|
||||
Ok(json!({"request":row}))
|
||||
}
|
||||
async fn read(
|
||||
State(s): State<crate::State>,
|
||||
Path(t): Path<Uuid>,
|
||||
h: HeaderMap,
|
||||
) -> Result<Json<Value>> {
|
||||
let p = access(&s, &h, t, false).await?;
|
||||
let mut tx = rmm_persistence::tenant_tx(&s.pool, t).await?;
|
||||
crate::permissions::require_principal(&mut tx, &p, "inventory:read").await?;
|
||||
let value = view(&mut tx).await?;
|
||||
tx.commit().await?;
|
||||
Ok(Json(value))
|
||||
}
|
||||
fn verify_original(
|
||||
s: &crate::State,
|
||||
row: &sqlx::postgres::PgRow,
|
||||
expected: &Value,
|
||||
w: &Value,
|
||||
) -> Result<()> {
|
||||
let raw: Vec<u8> = row.try_get("payload")?;
|
||||
let signature: Vec<u8> = row.try_get("signature")?;
|
||||
if raw.len() > 32768
|
||||
|| signature.len() != 64
|
||||
|| hash(&raw) != expected["payload_sha256"]
|
||||
|| hash(&signature) != expected["signature_sha256"]
|
||||
{
|
||||
return Err(changed());
|
||||
}
|
||||
let key = PKey::public_key_from_raw_bytes(&s.job_signer.public_key()?, Id::ED25519)
|
||||
.map_err(|_| changed())?;
|
||||
let mut verifier = Verifier::new_without_digest(&key).map_err(|_| changed())?;
|
||||
if !verifier
|
||||
.verify_oneshot(&signature, &raw)
|
||||
.map_err(|_| changed())?
|
||||
{
|
||||
return Err(changed());
|
||||
}
|
||||
let d: ReconcileDecisionPayload = serde_json::from_slice(&raw)?;
|
||||
let ready = d.checkpoint == 6755;
|
||||
if !d.valid_profile(d.issued_at)
|
||||
|| d.key_id != s.job_signer.key_id
|
||||
|| w["verification_key_id"] != d.key_id
|
||||
|| d.tenant_id != CASE_TENANT
|
||||
|| d.asset_id != CASE_ASSET
|
||||
|| d.agent_id != CASE_AGENT
|
||||
|| d.enrollment_generation != 1
|
||||
|| d.assignment_version != 1
|
||||
|| w["boot_id"] != d.boot_id.to_string()
|
||||
|| d.connection_generation != 150
|
||||
|| row.get::<i64, _>("connection_generation") != 150
|
||||
|| expected["request_id"] != d.request_id.to_string()
|
||||
|| row.get::<Uuid, _>("request_id") != d.request_id
|
||||
|| expected["decision_id"] != d.decision_id.to_string()
|
||||
|| row.get::<Uuid, _>("decision_id") != d.decision_id
|
||||
|| expected["request_sha256"] != d.request_hash
|
||||
|| row.get::<String, _>("request_hash") != d.request_hash
|
||||
|| expected["checkpoint"] != d.checkpoint
|
||||
|| row.get::<i64, _>("checkpoint") != d.checkpoint as i64
|
||||
|| w["agent_journal_id"] != d.journal_id.to_string()
|
||||
|| row.get::<Uuid, _>("journal_id") != d.journal_id
|
||||
|| d.helper_journal_id.map(|id| Value::String(id.to_string()))
|
||||
!= Some(w["helper_journal_id"].clone())
|
||||
|| d.helper_checkpoint != 1
|
||||
|| d.ready != ready
|
||||
|| d.helper_ready != ready
|
||||
|| expected["reason"] != d.reason
|
||||
|| !d.attempts.is_empty()
|
||||
{
|
||||
return Err(changed());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
async fn verify_case(
|
||||
tx: &mut Transaction<'_, Postgres>,
|
||||
s: &crate::State,
|
||||
w: &Value,
|
||||
promoted: bool,
|
||||
) -> Result<()> {
|
||||
crate::agent_service::control_lock(tx, CASE_TENANT, CASE_AGENT).await?;
|
||||
let dev=sqlx::query("SELECT asset_id,certificate_sha256,enrollment_generation,assignment_version,connection_generation,connection_boot_id,capabilities,revoked_at IS NULL AS active,restore_blocked,sequence_regressed,sync_recovery_required,sync_required
|
||||
FROM agent_installations WHERE tenant_id=$1 AND agent_id=$2 FOR UPDATE")
|
||||
.bind(CASE_TENANT).bind(CASE_AGENT).fetch_optional(&mut **tx).await?.ok_or_else(changed)?;
|
||||
let mut caps: Vec<String> = serde_json::from_value(dev.get("capabilities"))?;
|
||||
caps.sort();
|
||||
if dev.get::<Uuid, _>("asset_id") != CASE_ASSET
|
||||
|| dev.get::<String, _>("certificate_sha256") != CERTIFICATE
|
||||
|| dev.get::<i64, _>("enrollment_generation") != 1
|
||||
|| dev.get::<i64, _>("assignment_version") != 1
|
||||
|| dev.get::<i64, _>("connection_generation") <= 150
|
||||
|| dev
|
||||
.get::<Option<Uuid>, _>("connection_boot_id")
|
||||
.map(|v| Value::String(v.to_string()))
|
||||
!= Some(w["boot_id"].clone())
|
||||
|| !dev.get::<bool, _>("active")
|
||||
|| !dev.get::<bool, _>("restore_blocked")
|
||||
|| dev.get::<bool, _>("sequence_regressed")
|
||||
|| dev.get::<bool, _>("sync_recovery_required")
|
||||
|| dev.get::<bool, _>("sync_required")
|
||||
|| caps != ["agent.update/1", "heartbeat/1", "windows.base/1"]
|
||||
{
|
||||
return Err(changed());
|
||||
}
|
||||
// The device row lock also excludes a concurrent plan authorization targeting it.
|
||||
let jobs: bool =
|
||||
sqlx::query_scalar("SELECT EXISTS(SELECT 1 FROM jobs WHERE tenant_id=$1 AND agent_id=$2)")
|
||||
.bind(CASE_TENANT)
|
||||
.bind(CASE_AGENT)
|
||||
.fetch_one(&mut **tx)
|
||||
.await?;
|
||||
// Outbox and permit rows have non-null foreign keys to the scoped jobs.
|
||||
if jobs {
|
||||
return Err(changed());
|
||||
}
|
||||
let history=sqlx::query("SELECT request_id,decision_id,request_hash,journal_id,checkpoint,connection_generation,payload,signature
|
||||
FROM sync_checkpoints WHERE tenant_id=$1 AND agent_id=$2 ORDER BY checkpoint LIMIT 3")
|
||||
.bind(CASE_TENANT).bind(CASE_AGENT).fetch_all(&mut **tx).await?;
|
||||
if history.len() != 2 {
|
||||
return Err(changed());
|
||||
}
|
||||
for (index, row) in history.iter().enumerate() {
|
||||
verify_original(s, row, &w["decisions"][index], w)?;
|
||||
}
|
||||
let head=sqlx::query("SELECT journal_id,checkpoint,decision_id,helper_journal_id,helper_checkpoint FROM agent_sync_state WHERE tenant_id=$1 AND agent_id=$2 FOR UPDATE")
|
||||
.bind(CASE_TENANT).bind(CASE_AGENT).fetch_optional(&mut **tx).await?.ok_or_else(changed)?;
|
||||
let (cp, id) = if promoted {
|
||||
(6756, DENIED)
|
||||
} else {
|
||||
(6755, FIRST)
|
||||
};
|
||||
if head.get::<i64, _>("checkpoint") != cp
|
||||
|| head.get::<Uuid, _>("decision_id") != id
|
||||
|| w["agent_journal_id"] != head.get::<Uuid, _>("journal_id").to_string()
|
||||
|| head.get::<i64, _>("helper_checkpoint") != 1
|
||||
|| head
|
||||
.get::<Option<Uuid>, _>("helper_journal_id")
|
||||
.map(|id| Value::String(id.to_string()))
|
||||
!= Some(w["helper_journal_id"].clone())
|
||||
{
|
||||
return Err(changed());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct Empty {}
|
||||
async fn submit(
|
||||
State(s): State<crate::State>,
|
||||
Path(t): Path<Uuid>,
|
||||
h: HeaderMap,
|
||||
Json(_): Json<Empty>,
|
||||
) -> Result<Json<Value>> {
|
||||
let p = access(&s, &h, t, true).await?;
|
||||
let mut tx = rmm_persistence::tenant_tx(&s.pool, t).await?;
|
||||
crate::permissions::require_principal(&mut tx, &p, "operations:submit").await?;
|
||||
crate::agent_service::control_lock(&mut tx, t, CASE_AGENT).await?;
|
||||
let mut value = view(&mut tx).await?;
|
||||
if value["request"].is_null() {
|
||||
let w = case_witness();
|
||||
verify_case(&mut tx, &s, &w, false).await?;
|
||||
let digest = inventory_sha256(&w)?;
|
||||
let request_id = Uuid::new_v4();
|
||||
sqlx::query("INSERT INTO windows_checkpoint_reviews(tenant_id,request_id,agent_id,asset_id,witness,witness_sha256,requested_by) VALUES($1,$2,$3,$4,$5,$6,$7)")
|
||||
.bind(t).bind(request_id).bind(CASE_AGENT).bind(CASE_ASSET).bind(&w).bind(&digest).bind(&p.name).execute(&mut *tx).await?;
|
||||
value = view(&mut tx).await?;
|
||||
}
|
||||
tx.commit().await?;
|
||||
Ok(Json(value))
|
||||
}
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct Confirmation {
|
||||
witness_sha256: String,
|
||||
reviewed: bool,
|
||||
previous_receipt_id: Option<Uuid>,
|
||||
}
|
||||
async fn confirm(
|
||||
State(s): State<crate::State>,
|
||||
Path((t, id)): Path<(Uuid, Uuid)>,
|
||||
h: HeaderMap,
|
||||
Json(input): Json<Confirmation>,
|
||||
) -> Result<Json<Value>> {
|
||||
let p = access(&s, &h, t, true).await?;
|
||||
confirm_review(&s, &p, id, input, &case_witness()).await
|
||||
}
|
||||
async fn confirm_review(
|
||||
s: &crate::State,
|
||||
p: &Principal,
|
||||
id: Uuid,
|
||||
input: Confirmation,
|
||||
expected: &Value,
|
||||
) -> Result<Json<Value>> {
|
||||
let t = p.tenant;
|
||||
let session = real_browser(p)?;
|
||||
if !input.reviewed {
|
||||
return Err(Error(StatusCode::BAD_REQUEST, "REVIEW_REQUIRED"));
|
||||
}
|
||||
let mut tx = rmm_persistence::tenant_tx(&s.pool, t).await?;
|
||||
reviewer(&mut tx, p).await?;
|
||||
crate::agent_service::control_lock(&mut tx, t, CASE_AGENT).await?;
|
||||
let row=sqlx::query("SELECT witness,witness_sha256 FROM windows_checkpoint_reviews WHERE tenant_id=$1 AND request_id=$2 AND agent_id=$3")
|
||||
.bind(t).bind(id).bind(CASE_AGENT).fetch_optional(&mut *tx).await?.ok_or_else(missing)?;
|
||||
let w: Value = row.get("witness");
|
||||
let digest = inventory_sha256(&w)?;
|
||||
if &w != expected
|
||||
|| input.witness_sha256 != digest
|
||||
|| row.get::<String, _>("witness_sha256") != digest
|
||||
{
|
||||
return Err(changed());
|
||||
}
|
||||
let last=sqlx::query("SELECT receipt_id,valid_until FROM windows_checkpoint_review_receipts WHERE tenant_id=$1 AND request_id=$2 ORDER BY issued_at DESC,receipt_id DESC LIMIT 1")
|
||||
.bind(t).bind(id).fetch_optional(&mut *tx).await?;
|
||||
verify_case(&mut tx, s, &w, last.is_some()).await?;
|
||||
if let Some(ref r) = last {
|
||||
if r.get::<DateTime<Utc>, _>("valid_until") > Utc::now() {
|
||||
let value = view(&mut tx).await?;
|
||||
tx.commit().await?;
|
||||
return Ok(Json(value));
|
||||
}
|
||||
if input.previous_receipt_id != Some(r.get("receipt_id")) {
|
||||
return Err(Error(
|
||||
StatusCode::CONFLICT,
|
||||
"EXPIRED_RECEIPT_REVIEW_REQUIRED",
|
||||
));
|
||||
}
|
||||
} else if input.previous_receipt_id.is_some() {
|
||||
return Err(changed());
|
||||
}
|
||||
|
||||
let now = Utc::now();
|
||||
let receipt = Receipt {
|
||||
domain: RECEIPT_DOMAIN.into(),
|
||||
schema_version: 1,
|
||||
request_id: id,
|
||||
receipt_id: Uuid::new_v4(),
|
||||
witness_sha256: digest,
|
||||
witness: w,
|
||||
key_id: s.job_signer.key_id.clone(),
|
||||
issued_at: now,
|
||||
valid_until: now + Duration::minutes(10),
|
||||
confirmed_by: p.name.clone(),
|
||||
approval_origin: "human_webui".into(),
|
||||
testsimulation: false,
|
||||
ready: false,
|
||||
helper_ready: false,
|
||||
unlock: false,
|
||||
};
|
||||
let payload = serde_json::to_vec(&receipt)?;
|
||||
let signature = s.job_signer.sign(&payload)?;
|
||||
if last.is_none() && sqlx::query("UPDATE agent_sync_state SET checkpoint=6756, decision_id=$4 WHERE tenant_id=$1 AND agent_id=$2 AND checkpoint=6755 AND decision_id=$3 AND helper_checkpoint=1")
|
||||
.bind(t).bind(CASE_AGENT).bind(FIRST).bind(DENIED).execute(&mut *tx).await?.rows_affected()!=1 {return Err(changed());}
|
||||
sqlx::query("INSERT INTO windows_checkpoint_review_receipts(tenant_id,request_id,receipt_id,confirmed_by,session_hash,issued_at,valid_until,payload,signature) VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9)")
|
||||
.bind(t).bind(id).bind(receipt.receipt_id).bind(&p.name).bind(session).bind(now).bind(receipt.valid_until).bind(&payload).bind(signature).execute(&mut *tx).await?;
|
||||
sqlx::query("INSERT INTO audit_events(tenant_id,event_id,principal,event_type,data) VALUES($1,$2,$3,'windows_checkpoint_human_repair',$4)")
|
||||
.bind(t).bind(receipt.receipt_id).bind(&p.name)
|
||||
.bind(json!({"request_id":id,"agent_id":CASE_AGENT,"witness_sha256":receipt.witness_sha256,"receipt_sha256":hash(&payload),"approval_origin":"human_webui","testsimulation":false,"ready":false,"helper_ready":false,"unlock":false}))
|
||||
.execute(&mut *tx).await?;
|
||||
let value = view(&mut tx).await?;
|
||||
tx.commit().await?;
|
||||
Ok(Json(value))
|
||||
}
|
||||
async fn download(
|
||||
State(s): State<crate::State>,
|
||||
Path((t, id)): Path<(Uuid, Uuid)>,
|
||||
h: HeaderMap,
|
||||
) -> Result<Json<SignedReceipt>> {
|
||||
let p = access(&s, &h, t, false).await?;
|
||||
let mut tx = rmm_persistence::tenant_tx(&s.pool, t).await?;
|
||||
reviewer(&mut tx, &p).await?;
|
||||
verify_case(&mut tx, &s, &case_witness(), true).await?;
|
||||
let row=sqlx::query("SELECT receipt_id,confirmed_by,payload,signature FROM windows_checkpoint_review_receipts WHERE tenant_id=$1 AND request_id=$2 AND valid_until>now() ORDER BY issued_at DESC,receipt_id DESC LIMIT 1")
|
||||
.bind(t).bind(id).fetch_optional(&mut *tx).await?.ok_or_else(missing)?;
|
||||
let signed = SignedReceipt {
|
||||
payload: row.get("payload"),
|
||||
signature: row.get("signature"),
|
||||
};
|
||||
let receipt: Receipt = serde_json::from_slice(&signed.payload)?;
|
||||
let key = PKey::public_key_from_raw_bytes(&s.job_signer.public_key()?, Id::ED25519)
|
||||
.map_err(|_| changed())?;
|
||||
if !Verifier::new_without_digest(&key)
|
||||
.map_err(|_| changed())?
|
||||
.verify_oneshot(&signed.signature, &signed.payload)
|
||||
.map_err(|_| changed())?
|
||||
|| !receipt.matches_human_review(Utc::now())
|
||||
|| receipt.request_id != id
|
||||
|| receipt.receipt_id != row.get::<Uuid, _>("receipt_id")
|
||||
|| receipt.confirmed_by != row.get::<String, _>("confirmed_by")
|
||||
{
|
||||
return Err(changed());
|
||||
}
|
||||
tx.commit().await?;
|
||||
Ok(Json(signed))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::job_signer::JobSigner;
|
||||
use std::{collections::BTreeSet, sync::Arc};
|
||||
|
||||
fn operator() -> Principal {
|
||||
Principal {
|
||||
tenant: CASE_TENANT,
|
||||
name: format!("oidc:{}", "e".repeat(64)),
|
||||
operator: true,
|
||||
session_hash: Some("a".repeat(64)),
|
||||
csrf: Some("test-csrf".into()),
|
||||
scopes: None,
|
||||
testsimulation: false,
|
||||
identity: Some(rmm_oidc_auth::Identity {
|
||||
issuer: "https://human-review.example.test".into(),
|
||||
subject: "synthetic-operator".into(),
|
||||
}),
|
||||
tenants: vec![CASE_TENANT],
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simulated_sessions_and_bearers_have_no_confirmation_authority() {
|
||||
let p = operator();
|
||||
assert!(real_browser(&p).is_ok());
|
||||
let mut simulated = p.clone();
|
||||
simulated.testsimulation = true;
|
||||
assert!(real_browser(&simulated).is_err());
|
||||
let mut bearer = p.clone();
|
||||
bearer.scopes = Some(BTreeSet::from(["recovery:confirm".into()]));
|
||||
assert!(real_browser(&bearer).is_err());
|
||||
for field in ["identity", "session", "csrf"] {
|
||||
let mut p = p.clone();
|
||||
match field {
|
||||
"identity" => p.identity = None,
|
||||
"session" => p.session_hash = None,
|
||||
_ => p.csrf = None,
|
||||
}
|
||||
assert!(real_browser(&p).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore = "requires a fresh isolated PostgreSQL database"]
|
||||
async fn isolated_windows_checkpoint_human_review() {
|
||||
let admin = sqlx::PgPool::connect(&std::env::var("RMM_TEST_REPAIR_ADMIN_URL").unwrap())
|
||||
.await
|
||||
.unwrap();
|
||||
let pool = sqlx::PgPool::connect(&std::env::var("RMM_TEST_REPAIR_APP_URL").unwrap())
|
||||
.await
|
||||
.unwrap();
|
||||
rmm_persistence::verify_application_role(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
let tmp = std::env::temp_dir().join(format!("windows-review-{}", Uuid::new_v4()));
|
||||
let s = crate::State {
|
||||
pool,
|
||||
signer: None,
|
||||
viewer_a: [0; 32],
|
||||
viewer_b: [1; 32],
|
||||
auth: Arc::new(crate::auth::Auth::from_env("development").await.unwrap()),
|
||||
job_signer: Arc::new(JobSigner::load_or_create(&tmp.join("fixture-key.pem")).unwrap()),
|
||||
};
|
||||
let p = operator();
|
||||
let identity = p.identity.as_ref().unwrap();
|
||||
let mut w = case_witness();
|
||||
w["verification_key_id"] = json!(s.job_signer.key_id);
|
||||
let boot = Uuid::parse_str(w["boot_id"].as_str().unwrap()).unwrap();
|
||||
let journal = Uuid::parse_str(w["agent_journal_id"].as_str().unwrap()).unwrap();
|
||||
let helper = Uuid::parse_str(w["helper_journal_id"].as_str().unwrap()).unwrap();
|
||||
sqlx::query("INSERT INTO assets VALUES($1,$2)")
|
||||
.bind(CASE_TENANT)
|
||||
.bind(CASE_ASSET)
|
||||
.execute(&admin)
|
||||
.await
|
||||
.unwrap();
|
||||
sqlx::query("INSERT INTO agent_installations(tenant_id,agent_id,asset_id,certificate_sha256,assignment_version,connection_generation,connection_boot_id,restore_blocked,capabilities) VALUES($1,$2,$3,$4,1,151,$5,true,$6)")
|
||||
.bind(CASE_TENANT).bind(CASE_AGENT).bind(CASE_ASSET).bind(CERTIFICATE).bind(boot)
|
||||
.bind(json!(["heartbeat/1","windows.base/1","agent.update/1"])).execute(&admin).await.unwrap();
|
||||
sqlx::query("INSERT INTO agent_sync_state(tenant_id,agent_id,journal_id,checkpoint,decision_id,helper_journal_id,helper_checkpoint) VALUES($1,$2,$3,6755,$4,$5,1)")
|
||||
.bind(CASE_TENANT).bind(CASE_AGENT).bind(journal).bind(FIRST).bind(helper).execute(&admin).await.unwrap();
|
||||
for (i, c) in w["decisions"]
|
||||
.as_array_mut()
|
||||
.unwrap()
|
||||
.iter_mut()
|
||||
.enumerate()
|
||||
{
|
||||
let now = Utc::now() - Duration::hours(1);
|
||||
let d = ReconcileDecisionPayload {
|
||||
domain: "rmm.reconciliation-decision".into(),
|
||||
schema_version: 1,
|
||||
decision_id: Uuid::parse_str(c["decision_id"].as_str().unwrap()).unwrap(),
|
||||
request_id: Uuid::parse_str(c["request_id"].as_str().unwrap()).unwrap(),
|
||||
request_hash: c["request_sha256"].as_str().unwrap().into(),
|
||||
tenant_id: CASE_TENANT,
|
||||
agent_id: CASE_AGENT,
|
||||
asset_id: CASE_ASSET,
|
||||
enrollment_generation: 1,
|
||||
assignment_version: 1,
|
||||
connection_generation: 150,
|
||||
boot_id: boot,
|
||||
journal_id: journal,
|
||||
checkpoint: 6755 + i as u64,
|
||||
helper_journal_id: Some(helper),
|
||||
helper_checkpoint: 1,
|
||||
issued_at: now,
|
||||
valid_until: now + Duration::seconds(60),
|
||||
ready: i == 0,
|
||||
helper_ready: i == 0,
|
||||
reason: c["reason"].as_str().unwrap().into(),
|
||||
attempts: vec![],
|
||||
acknowledged_message_ids: vec![],
|
||||
key_id: s.job_signer.key_id.clone(),
|
||||
};
|
||||
let raw = serde_json::to_vec(&d).unwrap();
|
||||
let signature = s.job_signer.sign(&raw).unwrap();
|
||||
c["payload_sha256"] = json!(hash(&raw));
|
||||
c["signature_sha256"] = json!(hash(&signature));
|
||||
sqlx::query("INSERT INTO sync_checkpoints(tenant_id,agent_id,request_id,decision_id,request_hash,journal_id,checkpoint,connection_generation,payload,signature) VALUES($1,$2,$3,$4,$5,$6,$7,150,$8,$9)")
|
||||
.bind(CASE_TENANT).bind(CASE_AGENT).bind(d.request_id).bind(d.decision_id).bind(&d.request_hash)
|
||||
.bind(journal).bind(d.checkpoint as i64).bind(raw).bind(signature).execute(&admin).await.unwrap();
|
||||
}
|
||||
let request = Uuid::new_v4();
|
||||
let digest = inventory_sha256(&w).unwrap();
|
||||
sqlx::query("INSERT INTO oidc_principals(principal,issuer,subject,tenant_ids) VALUES($1,$2,$3,ARRAY[$4]::uuid[])")
|
||||
.bind(&p.name).bind(&identity.issuer).bind(&identity.subject).bind(CASE_TENANT).execute(&admin).await.unwrap();
|
||||
sqlx::query("INSERT INTO memberships(tenant_id,principal,kind,permissions) VALUES($1,$2,'human',ARRAY['inventory:read'])")
|
||||
.bind(CASE_TENANT).bind(&p.name).execute(&admin).await.unwrap();
|
||||
sqlx::query("INSERT INTO windows_checkpoint_reviews(tenant_id,request_id,asset_id,agent_id,witness,witness_sha256,requested_by) VALUES($1,$2,$3,$4,$5,$6,'fixture-submitter')")
|
||||
.bind(CASE_TENANT).bind(request).bind(CASE_ASSET).bind(CASE_AGENT).bind(&w).bind(&digest).execute(&admin).await.unwrap();
|
||||
let confirmation = || Confirmation {
|
||||
reviewed: true,
|
||||
witness_sha256: digest.clone(),
|
||||
previous_receipt_id: None,
|
||||
};
|
||||
assert_eq!(
|
||||
confirm_review(&s, &p, request, confirmation(), &w)
|
||||
.await
|
||||
.unwrap_err()
|
||||
.0,
|
||||
StatusCode::FORBIDDEN
|
||||
);
|
||||
sqlx::query("UPDATE memberships SET permissions=array_append(permissions,'recovery:confirm') WHERE tenant_id=$1 AND principal=$2").bind(CASE_TENANT).bind(&p.name).execute(&admin).await.unwrap();
|
||||
sqlx::query("UPDATE oidc_principals SET disabled=true WHERE principal=$1")
|
||||
.bind(&p.name)
|
||||
.execute(&admin)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
confirm_review(&s, &p, request, confirmation(), &w)
|
||||
.await
|
||||
.unwrap_err()
|
||||
.0,
|
||||
StatusCode::FORBIDDEN
|
||||
);
|
||||
sqlx::query("UPDATE oidc_principals SET disabled=false WHERE principal=$1")
|
||||
.bind(&p.name)
|
||||
.execute(&admin)
|
||||
.await
|
||||
.unwrap();
|
||||
let mut sim = p.clone();
|
||||
sim.testsimulation = true;
|
||||
assert!(
|
||||
confirm_review(&s, &sim, request, confirmation(), &w)
|
||||
.await
|
||||
.is_err()
|
||||
);
|
||||
let mut wrong = confirmation();
|
||||
wrong.witness_sha256 = "00".repeat(32);
|
||||
assert!(confirm_review(&s, &p, request, wrong, &w).await.is_err());
|
||||
let mut altered = w.clone();
|
||||
altered["decisions"][0]["signature_sha256"] = json!("00".repeat(32));
|
||||
let mut tx = rmm_persistence::tenant_tx(&s.pool, CASE_TENANT)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(verify_case(&mut tx, &s, &altered, false).await.is_err());
|
||||
tx.rollback().await.unwrap();
|
||||
let mut other =
|
||||
rmm_persistence::tenant_tx(&s.pool, Uuid::parse_str(rmm_domain::TENANT_B).unwrap())
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
sqlx::query_scalar::<_, i64>("SELECT count(*) FROM windows_checkpoint_reviews")
|
||||
.fetch_one(&mut *other)
|
||||
.await
|
||||
.unwrap(),
|
||||
0
|
||||
);
|
||||
other.rollback().await.unwrap();
|
||||
let first = confirm_review(&s, &p, request, confirmation(), &w)
|
||||
.await
|
||||
.unwrap()
|
||||
.0;
|
||||
assert_eq!(first["request"]["status"], "confirmed");
|
||||
assert_eq!(
|
||||
confirm_review(&s, &p, request, confirmation(), &w)
|
||||
.await
|
||||
.unwrap()
|
||||
.0,
|
||||
first
|
||||
);
|
||||
let row = sqlx::query(
|
||||
"SELECT payload,signature FROM windows_checkpoint_review_receipts WHERE request_id=$1",
|
||||
)
|
||||
.bind(request)
|
||||
.fetch_one(&admin)
|
||||
.await
|
||||
.unwrap();
|
||||
let bytes: Vec<u8> = row.get("payload");
|
||||
let signature: Vec<u8> = row.get("signature");
|
||||
let key = PKey::public_key_from_raw_bytes(&s.job_signer.public_key().unwrap(), Id::ED25519)
|
||||
.unwrap();
|
||||
assert!(
|
||||
Verifier::new_without_digest(&key)
|
||||
.unwrap()
|
||||
.verify_oneshot(&signature, &bytes)
|
||||
.unwrap()
|
||||
);
|
||||
let receipt: Receipt = serde_json::from_slice(&bytes).unwrap();
|
||||
assert!(
|
||||
!receipt.ready && !receipt.helper_ready && !receipt.unlock && !receipt.testsimulation
|
||||
);
|
||||
assert_eq!(
|
||||
(receipt.domain, receipt.witness, receipt.confirmed_by),
|
||||
(RECEIPT_DOMAIN.to_owned(), w, p.name)
|
||||
);
|
||||
let flags=sqlx::query("SELECT restore_blocked,sync_required,helper_sync_ready FROM agent_installations WHERE agent_id=$1").bind(CASE_AGENT).fetch_one(&admin).await.unwrap();
|
||||
assert!(
|
||||
flags.get::<bool, _>("restore_blocked")
|
||||
&& !flags.get::<bool, _>("sync_required")
|
||||
&& !flags.get::<bool, _>("helper_sync_ready")
|
||||
);
|
||||
assert_eq!(
|
||||
sqlx::query_scalar::<_, Uuid>(
|
||||
"SELECT decision_id FROM agent_sync_state WHERE agent_id=$1"
|
||||
)
|
||||
.bind(CASE_AGENT)
|
||||
.fetch_one(&admin)
|
||||
.await
|
||||
.unwrap(),
|
||||
DENIED
|
||||
);
|
||||
assert_eq!(sqlx::query_scalar::<_,i64>("SELECT count(*) FROM audit_events WHERE event_type='windows_checkpoint_human_repair'").fetch_one(&admin).await.unwrap(),1);
|
||||
assert_eq!(sqlx::query_scalar::<_,i64>("SELECT (SELECT count(*) FROM jobs)+(SELECT count(*) FROM outbox)+(SELECT count(*) FROM execution_permits)").fetch_one(&admin).await.unwrap(),0);
|
||||
std::fs::remove_dir_all(tmp).unwrap();
|
||||
}
|
||||
}
|
||||
@@ -433,3 +433,22 @@ Die WebUI ist noch nicht auf dem permanenten Server veröffentlicht.
|
||||
Die aktuelle Liveauskunft `/auth/config` lieferte HTTP 200 mit
|
||||
`oidc_configured=false` und `dev_login_enabled=true`. Die Angaben zum
|
||||
tatsächlichen Identitätsanbieter sind beim Betreiber angefragt.
|
||||
|
||||
Der dazugehörige Serverweg besteht aus lesbarem Prüfantrag, einer separat
|
||||
berechtigten menschlichen Bestätigung und dem Download der signierten Quittung.
|
||||
Er ist ausschließlich im Entwicklungsprofil registriert. Ein simuliertes
|
||||
Principal oder ein Bearer kann die Bestätigung nicht auslösen. Die Bestätigung
|
||||
prüft die zwei historischen Originalsignaturen und den gegenwärtigen
|
||||
Geräte-/Serverstand erneut. Der gültige Kontrollhead wird monoton auf 6756
|
||||
übernommen, ohne Bereitschaft oder Ausführungsjobs zu erzeugen.
|
||||
|
||||
Zwei isolierte PostgreSQL-Tests bestanden. Eine frische Datenbank erhielt alle
|
||||
Migrationen 0001 bis 0017. Die zusätzliche Upgradeprobe erhielt den zuvor unter
|
||||
0016 gespeicherten Fremdtenant-Assetmarker; Mitgliedschaften erhielten keine
|
||||
implizite neue Berechtigung. Geprüft wurden unter anderem Simulation, Bearer,
|
||||
fehlendes Recht, deaktivierte OIDC-Identität, manipulierte Signatur, falscher
|
||||
Beleghash, Fremdtenant, idempotente Wiederholung und Null-Jobartefakte.
|
||||
Das positive Fixture verwendete eine synthetische menschliche Sitzung.
|
||||
Es ist keine tatsächliche Betreiberfreigabe. Fixture-Protokoll SHA-256
|
||||
`ee854f4fa2d26af9fd0b1e06335b5c1d2f9285359fc62fcc1251fbcb4114cc14`.
|
||||
Server-Clippy mit `--all-targets -- -D warnings` bestand lokal.
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
-- Separate from job approval. Only the reviewed no-effect case is represented.
|
||||
CREATE TABLE windows_checkpoint_reviews (
|
||||
tenant_id uuid NOT NULL,
|
||||
request_id uuid NOT NULL,
|
||||
asset_id uuid NOT NULL,
|
||||
agent_id uuid NOT NULL,
|
||||
witness jsonb NOT NULL,
|
||||
witness_sha256 text NOT NULL CHECK (witness_sha256 ~ '^[0-9a-f]{64}$'),
|
||||
requested_by text NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (tenant_id, request_id),
|
||||
UNIQUE (tenant_id, agent_id),
|
||||
FOREIGN KEY (tenant_id, asset_id) REFERENCES assets(tenant_id, asset_id),
|
||||
FOREIGN KEY (tenant_id, agent_id) REFERENCES agent_installations(tenant_id, agent_id)
|
||||
);
|
||||
CREATE TABLE windows_checkpoint_review_receipts (
|
||||
tenant_id uuid NOT NULL,
|
||||
request_id uuid NOT NULL,
|
||||
receipt_id uuid NOT NULL,
|
||||
confirmed_by text NOT NULL CHECK (confirmed_by ~ '^oidc:[0-9a-f]{64}$'),
|
||||
session_hash text NOT NULL CHECK (session_hash ~ '^[0-9a-f]{64}$'),
|
||||
issued_at timestamptz NOT NULL,
|
||||
valid_until timestamptz NOT NULL CHECK (valid_until > issued_at AND valid_until <= issued_at + interval '10 minutes'),
|
||||
payload bytea NOT NULL,
|
||||
signature bytea NOT NULL CHECK (octet_length(signature)=64),
|
||||
PRIMARY KEY (tenant_id, receipt_id),
|
||||
FOREIGN KEY (tenant_id, request_id) REFERENCES windows_checkpoint_reviews(tenant_id, request_id)
|
||||
);
|
||||
CREATE INDEX windows_checkpoint_receipts_latest ON windows_checkpoint_review_receipts(tenant_id, request_id, issued_at DESC);
|
||||
DO $$ DECLARE t text; BEGIN
|
||||
FOREACH t IN ARRAY ARRAY['windows_checkpoint_reviews', 'windows_checkpoint_review_receipts'] LOOP
|
||||
EXECUTE format('ALTER TABLE %I ENABLE ROW LEVEL SECURITY',t);
|
||||
EXECUTE format('ALTER TABLE %I FORCE ROW LEVEL SECURITY',t);
|
||||
EXECUTE format('CREATE POLICY tenant_scope ON %I USING (tenant_id::text=current_setting(''app.tenant_id'',true)) WITH CHECK (tenant_id::text=current_setting(''app.tenant_id'',true))',t);
|
||||
EXECUTE format('GRANT SELECT, INSERT ON %I TO rmm_app',t);
|
||||
EXECUTE format('CREATE TRIGGER immutable_content BEFORE UPDATE OR DELETE ON %I FOR EACH ROW EXECUTE FUNCTION immutable_plan()',t);
|
||||
END LOOP;
|
||||
END $$;
|
||||
|
||||
-- Application roles have no membership UPDATE privilege. Lock both independently
|
||||
-- provisioned bindings while the API validates and records a human confirmation.
|
||||
CREATE FUNCTION lock_windows_checkpoint_reviewer(name_value text, issuer_value text, subject_value text)
|
||||
RETURNS boolean LANGUAGE sql SECURITY DEFINER SET search_path=pg_catalog,public AS $$
|
||||
SELECT EXISTS (
|
||||
SELECT 1 FROM public.memberships m JOIN public.oidc_principals p USING (principal)
|
||||
WHERE m.tenant_id='11111111-1111-4111-8111-111111111111'::uuid
|
||||
AND m.tenant_id::text=current_setting('app.tenant_id',true) AND m.tenant_id=ANY(p.tenant_ids)
|
||||
AND m.principal=name_value AND m.kind='human' AND m.revoked_at IS NULL
|
||||
AND 'recovery:confirm'=ANY(m.permissions) AND NOT p.disabled
|
||||
AND p.issuer=issuer_value AND p.subject=subject_value FOR SHARE OF m,p
|
||||
);
|
||||
$$;
|
||||
REVOKE ALL ON FUNCTION lock_windows_checkpoint_reviewer(text,text,text) FROM PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION lock_windows_checkpoint_reviewer(text,text,text) TO rmm_app;
|
||||
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Human checkpoint recovery contract against an isolated PostgreSQL fixture."""
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import time
|
||||
import uuid
|
||||
|
||||
ROOT=Path(__file__).resolve().parents[1]
|
||||
NAME='rmm-windows-human-review-'+uuid.uuid4().hex[:10]
|
||||
|
||||
|
||||
def command(args, data=None, timeout=120):
|
||||
result=subprocess.run(args,input=data,capture_output=True,timeout=timeout)
|
||||
if result.returncode:
|
||||
raise RuntimeError(result.stderr.decode(errors='replace')[-4000:])
|
||||
return result.stdout
|
||||
|
||||
|
||||
def main():
|
||||
command(['docker','run','-d','--network','none','--name',NAME,
|
||||
'-e','POSTGRES_HOST_AUTH_METHOD=trust','postgres:17.6-bookworm'])
|
||||
try:
|
||||
for _ in range(100):
|
||||
logs=command(['docker','logs',NAME])
|
||||
ready=subprocess.run(['docker','exec',NAME,'pg_isready','-U','postgres'],capture_output=True)
|
||||
if b'init process complete' in logs and ready.returncode==0:break
|
||||
time.sleep(.2)
|
||||
else:raise RuntimeError('ISOLATED_POSTGRES_NOT_READY')
|
||||
def sql(raw):
|
||||
return command(['docker','exec','-i',NAME,'psql','-X','-qAt','-v','ON_ERROR_STOP=1','-U','postgres'],raw.encode())
|
||||
sql('CREATE ROLE rmm_app LOGIN NOINHERIT NOSUPERUSER NOBYPASSRLS;')
|
||||
# Exercise the 0016 -> 0017 transition with an existing device record.
|
||||
files = sorted((ROOT / 'migrations').glob('*.sql'))
|
||||
upgrade = ROOT / 'migrations/0017_windows_checkpoint_recovery.sql'
|
||||
for path in files:
|
||||
if path == upgrade:
|
||||
break
|
||||
sql(path.read_text())
|
||||
marker = '21c7560f-0132-4870-8be9-452fa3f67b56'
|
||||
sql(f"INSERT INTO assets VALUES('22222222-2222-4222-8222-222222222222','{marker}');")
|
||||
for path in files[files.index(upgrade):]:
|
||||
sql(path.read_text())
|
||||
if sql(f"SELECT count(*) FROM assets WHERE asset_id='{marker}';").strip() != b'1':
|
||||
raise RuntimeError('Existing record lost during recovery migration')
|
||||
if sql("SELECT count(*) FROM memberships WHERE 'recovery:confirm'=ANY(permissions);").strip() != b'0':
|
||||
raise RuntimeError('Migration implicitly granted human recovery permission')
|
||||
output=command(['docker','run','--rm','--network','container:'+NAME,
|
||||
'--read-only','--tmpfs','/tmp:rw,size=512m','-v',str(ROOT)+':/src:ro',
|
||||
'-v',str(ROOT/'devstate/windows-server-contract/target')+':/target','-e','CARGO_TARGET_DIR=/target',
|
||||
'-e','RMM_TEST_REPAIR_ADMIN_URL=postgres://postgres@127.0.0.1/postgres',
|
||||
'-e','RMM_TEST_REPAIR_APP_URL=postgres://rmm_app@127.0.0.1/postgres',
|
||||
'--entrypoint','cargo','rust-discovery-windows-tls-full:local',
|
||||
'test','--locked','--offline','-p','rmm-server','windows_checkpoint_review::tests',
|
||||
'--','--include-ignored','--nocapture'],timeout=300)
|
||||
print(output.decode())
|
||||
print('PASS isolated synthetic human review, signed denial checkpoint, denial of simulated principals, idempotence and zero jobs/permits.')
|
||||
finally:
|
||||
subprocess.run(['docker','rm','-f',NAME],capture_output=True)
|
||||
|
||||
|
||||
if __name__=='__main__':main()
|
||||
Reference in New Issue
Block a user