Skip to content

Commit 20ad32b

Browse files
committed
fix(isolation): validate confirmation for external backend implementations
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent 72c8d53 commit 20ad32b

3 files changed

Lines changed: 70 additions & 20 deletions

File tree

‎crates/openshell-isolation-interface/src/contract.rs‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
//! -> start_agent -> Running
1515
//! ```
1616
//!
17-
//! Each transition consumes the prior state by value (`self: Box<Self>`), and no
18-
//! state type has a public constructor, so a stage cannot be skipped or
19-
//! replayed. The supervisor holds no `match`/downcast on concrete backends: the
17+
//! Each transition consumes the prior state by value (`self: Box<Self>`).
18+
//! Trusted backend implementations construct confirmation through a validating
19+
//! constructor; the supervisor cannot obtain a ready boundary without evidence.
20+
//! The supervisor holds no `match`/downcast on concrete backends: the
2021
//! registry is the only lookup by `backend_name`, and everything past it is a
2122
//! `Box<dyn _>` / `Arc<dyn _>`.
2223
//!
@@ -492,10 +493,23 @@ pub struct ConfirmedBoundary {
492493
}
493494

494495
impl ConfirmedBoundary {
495-
/// Construct a confirmed state after backend-specific evidence validation.
496-
#[allow(dead_code)] // Implemented by the remote backend in the next stack layer.
497-
pub(crate) fn new(boundary: Box<dyn ReadyBoundary>, evidence: SandboxConfirmEvidence) -> Self {
498-
Self { boundary, evidence }
496+
/// Construct confirmation after checking measured evidence against the
497+
/// immutable identity admitted at attach time.
498+
///
499+
/// Backend implementations are trusted to collect this evidence and bind
500+
/// it to their resource. This constructor enforces the common requirements
501+
/// without requiring those implementations to live in the interface crate.
502+
///
503+
/// # Errors
504+
///
505+
/// Returns an error if evidence is incomplete or the identity does not match.
506+
pub fn try_new(
507+
boundary: Box<dyn ReadyBoundary>,
508+
evidence: SandboxConfirmEvidence,
509+
expected: &ResolvedWorkloadIdentity,
510+
) -> Result<Self, BackendError> {
511+
evidence.validate(expected)?;
512+
Ok(Self { boundary, evidence })
499513
}
500514

501515
/// Return the measured evidence carried by this confirmed state.
@@ -830,6 +844,3 @@ pub trait DnsMediationSource: Send + Sync {
830844
/// Await the next DNS query from this boundary.
831845
async fn accept(&self) -> Result<MediatedDnsQuery, BackendError>;
832846
}
833-
834-
#[cfg(test)]
835-
mod tests;

‎crates/openshell-isolation-interface/src/lib.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
//! The lifecycle states run in order: attach -> Bound -> confirm -> Ready ->
2222
//! `start_agent` -> Running. Nothing untrusted runs inside the boundary until it
2323
//! is confirmed ready. This is enforced *by construction*: each transition
24-
//! consumes the prior state by value, and no state type has a public
25-
//! constructor, so the supervisor cannot skip a stage or run a workload before
26-
//! [`contract::ReadyBoundary`] exists.
24+
//! consumes the prior state by value. Trusted backends construct confirmation
25+
//! through [`contract::ConfirmedBoundary::try_new`], which checks common evidence
26+
//! before the supervisor can obtain a [`contract::ReadyBoundary`].
2727
//!
2828
//! [`AgentSpec`] is shared between the workload definition the supervisor
2929
//! submits and the [`contract::SandboxContext`] that `attach` binds to a

crates/openshell-isolation-interface/src/contract/tests.rs renamed to crates/openshell-isolation-interface/tests/backend_conformance.rs

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
//! backends behind `dyn` with no enum over concrete state, and that one driver
1010
//! runs both unchanged.
1111
12+
use std::collections::BTreeMap;
1213
use std::marker::PhantomData;
13-
use std::sync::Mutex;
14+
use std::path::PathBuf;
1415
use std::sync::atomic::{AtomicBool, Ordering};
16+
use std::sync::{Arc, Mutex};
1517

16-
use super::*;
18+
use async_trait::async_trait;
19+
use openshell_isolation_interface::contract::*;
20+
use tokio::sync::oneshot;
1721

1822
// ---------------------------------------------------------------------------
1923
// Marker kinds: two materially different backends.
@@ -211,10 +215,11 @@ impl<K: MockKind> BoundBoundary for MockBound<K> {
211215
self.source.clone()
212216
}
213217
async fn confirm(self: Box<Self>) -> Result<ConfirmedBoundary, BackendError> {
214-
Ok(ConfirmedBoundary::new(
218+
ConfirmedBoundary::try_new(
215219
Box::new(MockReady::<K> { _k: PhantomData }),
216220
confirmation_evidence(),
217-
))
221+
&workload_identity(),
222+
)
218223
}
219224
}
220225

@@ -389,8 +394,8 @@ async fn drive(
389394
let _ingress = bound.network_mediation_source();
390395
assert_eq!(bound.host_gateway_ip(), None);
391396
let confirmed = bound.confirm().await?;
392-
confirmed.evidence.validate(&sandbox_ctx().identity)?;
393-
confirmed.boundary.start_agent().await
397+
confirmed.evidence().validate(&sandbox_ctx().identity)?;
398+
confirmed.into_boundary().start_agent().await
394399
}
395400

396401
// ---------------------------------------------------------------------------
@@ -466,6 +471,36 @@ async fn one_driver_runs_both_backends() {
466471
);
467472
}
468473

474+
#[test]
475+
fn confirmation_constructor_rejects_incomplete_evidence() {
476+
let mut evidence = confirmation_evidence();
477+
evidence.seccomp.cancellation = false;
478+
let result = ConfirmedBoundary::try_new(
479+
Box::new(MockReady::<Primary> { _k: PhantomData }),
480+
evidence,
481+
&workload_identity(),
482+
);
483+
assert!(matches!(result, Err(BackendError::Confirm(_))));
484+
}
485+
486+
#[test]
487+
fn confirmation_constructor_rejects_another_workload_identity() {
488+
let expected = ResolvedWorkloadIdentity::new(
489+
1001,
490+
1001,
491+
vec![1001],
492+
"policy".to_string(),
493+
"sha256:test".to_string(),
494+
)
495+
.unwrap();
496+
let result = ConfirmedBoundary::try_new(
497+
Box::new(MockReady::<Primary> { _k: PhantomData }),
498+
confirmation_evidence(),
499+
&expected,
500+
);
501+
assert!(matches!(result, Err(BackendError::Confirm(_))));
502+
}
503+
469504
#[tokio::test]
470505
async fn one_boundary_termination_does_not_change_another_boundary() {
471506
let reg = registry();
@@ -519,7 +554,11 @@ async fn runtime_interfaces_survive_lifecycle_consumption() {
519554
// The retained Arc must remain usable afterward.
520555
let source = bound.network_mediation_source();
521556
let confirmed = bound.confirm().await.expect("confirm");
522-
let _running = confirmed.boundary.start_agent().await.expect("start");
557+
let _running = confirmed
558+
.into_boundary()
559+
.start_agent()
560+
.await
561+
.expect("start");
523562

524563
let conn = source.accept().await.expect("accept after consumption");
525564
let identity = conn.binary_identity.expect("identity resolves");

0 commit comments

Comments
 (0)