2026-07-16 16:28:18 +09:00
|
|
|
use std::cell::RefCell;
|
2026-07-18 04:03:39 +09:00
|
|
|
use std::ffi::{OsStr, OsString};
|
2026-07-16 18:39:03 +09:00
|
|
|
use std::fmt;
|
2026-07-16 18:53:20 +09:00
|
|
|
use std::fs::File;
|
2026-07-18 02:08:14 +09:00
|
|
|
use std::io::{Read, Write};
|
2026-07-16 18:39:03 +09:00
|
|
|
use std::os::fd::{AsFd, OwnedFd};
|
|
|
|
|
use std::os::unix::ffi::OsStringExt;
|
|
|
|
|
use std::os::unix::fs::{FileExt, PermissionsExt};
|
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
|
|
2026-07-16 18:53:20 +09:00
|
|
|
use lazaret_core::configuration::{ConfinedPathPlan, ResolvedDomainConfiguration};
|
2026-07-18 02:08:14 +09:00
|
|
|
use lazaret_core::identity::{BundleDigest, ContainerId, HostPath, MountIdentity};
|
2026-07-16 18:39:03 +09:00
|
|
|
use lazaret_core::network::{ReachabilityExpectation, derive_ipv4_policy};
|
|
|
|
|
use lazaret_core::records::{
|
|
|
|
|
Generation, GenerationIdentity, HostProcessOwnershipSlot, IpAddress, PreparedArtifact, Session,
|
|
|
|
|
};
|
2026-07-18 02:08:14 +09:00
|
|
|
use lazaret_ignored_workspace::git_common_directory;
|
2026-07-18 04:03:39 +09:00
|
|
|
use lazaret_linux::filesystem::{RegularFileMailbox, mount_identity, namespace_identity};
|
2026-07-18 02:08:14 +09:00
|
|
|
use lazaret_linux::process::{
|
|
|
|
|
ProcessOwnershipContext, TargetCommand, child_broker, current_process_identity,
|
|
|
|
|
};
|
2026-07-16 18:39:03 +09:00
|
|
|
use lazaret_runtime_supervisor::network::NetworkProbeRequest;
|
|
|
|
|
use lazaret_runtime_supervisor::sandbox::{
|
|
|
|
|
RootProcess, SandboxBuildRequest, SandboxBundle, build_sandbox_bundle,
|
2026-07-18 02:08:14 +09:00
|
|
|
build_sandbox_bundle_with_workspace,
|
|
|
|
|
};
|
|
|
|
|
use lazaret_runtime_supervisor::supervision::{
|
|
|
|
|
RuntimeGitRoutingAuthority, RuntimeGitRoutingLaunch, RuntimeNetworkLaunch,
|
|
|
|
|
RuntimeSupervisorLaunch,
|
2026-07-16 18:39:03 +09:00
|
|
|
};
|
|
|
|
|
use lazaret_state_anchor::{StateAnchorLaunchAuthority, StateAnchorLayout};
|
|
|
|
|
use lazaret_storage_catalog::Catalog;
|
|
|
|
|
use rustix::event::{PollFd, PollFlags, Timespec, poll};
|
2026-07-16 18:53:20 +09:00
|
|
|
use rustix::fs::{
|
|
|
|
|
AtFlags, FileType, Mode, OFlags, RawDir, ResolveFlags, fchmod, fstat, mkdirat, openat2, statat,
|
|
|
|
|
unlinkat,
|
|
|
|
|
};
|
2026-07-16 16:28:18 +09:00
|
|
|
use rustix::io::{FdFlags, dup, fcntl_setfd};
|
2026-07-18 02:08:14 +09:00
|
|
|
use rustix::pipe::{PipeFlags, pipe_with};
|
2026-07-16 18:39:03 +09:00
|
|
|
use sha2::{Digest, Sha256};
|
|
|
|
|
|
2026-07-18 22:35:48 +09:00
|
|
|
use crate::bootstrap::{BootstrapPlan, CoordinatorLifecycle, coordinator_lifecycle};
|
2026-07-16 16:28:18 +09:00
|
|
|
use crate::control::RunscNonInteractiveExecutor;
|
2026-07-16 18:39:03 +09:00
|
|
|
use crate::domain_store::HostCoordinatorDomainStore;
|
2026-07-17 06:59:39 +09:00
|
|
|
use crate::terminal::RunscInteractiveSessionExecutor;
|
2026-07-16 16:28:18 +09:00
|
|
|
use crate::waiter::{BootstrapWaitOutcome, BootstrapWaiterFace};
|
2026-07-16 18:39:03 +09:00
|
|
|
|
|
|
|
|
const NETWORK_NAMESPACE_PATH: &str = "/proc/self/ns/net";
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2026-07-18 22:35:48 +09:00
|
|
|
pub struct ColdStartError(String);
|
2026-07-16 18:39:03 +09:00
|
|
|
|
2026-07-18 22:35:48 +09:00
|
|
|
impl fmt::Display for ColdStartError {
|
2026-07-16 18:39:03 +09:00
|
|
|
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
|
formatter.write_str(&self.0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-18 22:35:48 +09:00
|
|
|
impl std::error::Error for ColdStartError {}
|
2026-07-16 18:39:03 +09:00
|
|
|
|
2026-07-18 22:35:48 +09:00
|
|
|
impl ColdStartError {
|
2026-07-16 16:28:18 +09:00
|
|
|
pub(crate) fn service(error: impl fmt::Display) -> Self {
|
|
|
|
|
Self(error.to_string())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-18 22:35:48 +09:00
|
|
|
fn failure(error: impl fmt::Display) -> ColdStartError {
|
|
|
|
|
ColdStartError(error.to_string())
|
2026-07-16 18:39:03 +09:00
|
|
|
}
|
|
|
|
|
|
2026-07-18 22:35:48 +09:00
|
|
|
pub struct ColdStartInputs<'a> {
|
2026-07-16 18:39:03 +09:00
|
|
|
pub store: Arc<HostCoordinatorDomainStore>,
|
|
|
|
|
pub catalog: &'a Catalog,
|
|
|
|
|
pub configuration: &'a ResolvedDomainConfiguration,
|
|
|
|
|
pub generation: Generation,
|
|
|
|
|
pub prepared_artifact: &'a PreparedArtifact,
|
2026-07-17 03:58:27 +09:00
|
|
|
pub prepared_artifact_authority: &'a File,
|
|
|
|
|
pub prepared_artifact_label: &'a Path,
|
2026-07-16 18:39:03 +09:00
|
|
|
pub root_process: RootProcess,
|
|
|
|
|
pub resolver_addresses: Vec<IpAddress>,
|
|
|
|
|
pub network_probe: NetworkProbeRequest,
|
|
|
|
|
pub reachability: ReachabilityExpectation,
|
|
|
|
|
pub container_id: ContainerId,
|
|
|
|
|
pub invoking_uid: u32,
|
|
|
|
|
pub escalation_client: &'a File,
|
2026-07-16 20:41:40 +09:00
|
|
|
pub sandbox_init: &'a File,
|
2026-07-16 18:39:03 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct BootstrapOwnerGuard {
|
|
|
|
|
descriptor: OwnedFd,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl BootstrapOwnerGuard {
|
2026-07-16 16:28:18 +09:00
|
|
|
/// Adopts the private bootstrap entry's pipe standard input.
|
|
|
|
|
///
|
|
|
|
|
/// # Errors
|
|
|
|
|
/// Refuses a standard input that cannot be duplicated or is not a pipe.
|
2026-07-18 22:35:48 +09:00
|
|
|
pub fn from_stdin() -> Result<Self, ColdStartError> {
|
2026-07-16 16:28:18 +09:00
|
|
|
let stdin = std::io::stdin();
|
|
|
|
|
Self::from_inherited(dup(&stdin).map_err(failure)?)
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-16 18:39:03 +09:00
|
|
|
/// Adopts an inherited bootstrap-owner lifetime pipe without PID sampling.
|
|
|
|
|
///
|
|
|
|
|
/// # Errors
|
|
|
|
|
/// Refuses a descriptor that is not a pipe or cannot be confined to this process.
|
2026-07-18 22:35:48 +09:00
|
|
|
pub fn from_inherited(descriptor: OwnedFd) -> Result<Self, ColdStartError> {
|
2026-07-16 18:39:03 +09:00
|
|
|
let metadata = fstat(&descriptor).map_err(failure)?;
|
|
|
|
|
if !FileType::from_raw_mode(metadata.st_mode).is_fifo() {
|
2026-07-18 22:35:48 +09:00
|
|
|
return Err(ColdStartError(
|
2026-07-16 18:39:03 +09:00
|
|
|
"bootstrap-owner lifetime descriptor is not a pipe".into(),
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
fcntl_setfd(descriptor.as_fd(), FdFlags::CLOEXEC).map_err(failure)?;
|
|
|
|
|
Ok(Self { descriptor })
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-16 16:28:18 +09:00
|
|
|
/// Observes whether the exact retained bootstrap-owner pipe still has a writer.
|
|
|
|
|
///
|
|
|
|
|
/// # Errors
|
|
|
|
|
/// Returns a polling failure for the retained descriptor.
|
|
|
|
|
pub fn is_live(&self) -> std::io::Result<bool> {
|
2026-07-16 18:39:03 +09:00
|
|
|
let mut descriptors = [PollFd::new(&self.descriptor, PollFlags::IN)];
|
|
|
|
|
poll(&mut descriptors, Some(&Timespec::default()))?;
|
|
|
|
|
Ok(!descriptors[0]
|
|
|
|
|
.revents()
|
|
|
|
|
.intersects(PollFlags::IN | PollFlags::HUP | PollFlags::ERR))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-18 22:35:48 +09:00
|
|
|
pub struct ColdStart<'a> {
|
2026-07-16 18:39:03 +09:00
|
|
|
store: Arc<HostCoordinatorDomainStore>,
|
|
|
|
|
catalog: &'a Catalog,
|
|
|
|
|
configuration: &'a ResolvedDomainConfiguration,
|
|
|
|
|
generation: Generation,
|
|
|
|
|
generation_identity: GenerationIdentity,
|
|
|
|
|
prepared_artifact: &'a PreparedArtifact,
|
|
|
|
|
state_anchor_layout: StateAnchorLayout<'a>,
|
|
|
|
|
runtime_launch: Option<RuntimeSupervisorLaunch>,
|
|
|
|
|
sandbox_bundle: SandboxBundle,
|
|
|
|
|
network_policy: lazaret_core::network::CanonicalDerivedNetworkPolicy,
|
|
|
|
|
network_probe: NetworkProbeRequest,
|
|
|
|
|
reachability: ReachabilityExpectation,
|
|
|
|
|
container_id: ContainerId,
|
|
|
|
|
runtime_root: PathBuf,
|
|
|
|
|
bundle_digest: BundleDigest,
|
|
|
|
|
invoking_uid: u32,
|
2026-07-17 03:58:27 +09:00
|
|
|
staging: RuntimeStaging,
|
2026-07-18 02:08:14 +09:00
|
|
|
git_routing: Option<GitRoutingLayout>,
|
2026-07-16 18:39:03 +09:00
|
|
|
}
|
|
|
|
|
|
2026-07-18 22:35:48 +09:00
|
|
|
impl<'a> ColdStart<'a> {
|
|
|
|
|
/// Stages one generation from validated component authorities.
|
2026-07-16 18:39:03 +09:00
|
|
|
///
|
|
|
|
|
/// # Errors
|
|
|
|
|
/// Refuses mismatched generation/configuration/probe inputs, changed host authority, unsafe
|
|
|
|
|
/// staging paths, or component construction failure.
|
2026-07-18 02:08:14 +09:00
|
|
|
#[allow(clippy::too_many_lines)]
|
2026-07-18 22:35:48 +09:00
|
|
|
pub fn stage(inputs: ColdStartInputs<'a>) -> Result<Self, ColdStartError> {
|
2026-07-16 18:39:03 +09:00
|
|
|
require_inputs(&inputs)?;
|
|
|
|
|
let runtime_domain = host_path(
|
|
|
|
|
inputs
|
|
|
|
|
.configuration
|
|
|
|
|
.runtime_domain_root()
|
|
|
|
|
.canonical_label()
|
|
|
|
|
.as_bytes(),
|
|
|
|
|
);
|
|
|
|
|
let state_anchor_layout = StateAnchorLayout::create(inputs.configuration)
|
|
|
|
|
.map_err(|error| failure(format!("State Anchor layout: {error}")))?;
|
|
|
|
|
let staging = RuntimeStaging::create(
|
2026-07-16 18:53:20 +09:00
|
|
|
inputs.configuration.runtime_domain_root(),
|
2026-07-16 18:39:03 +09:00
|
|
|
inputs.container_id,
|
|
|
|
|
inputs.escalation_client,
|
2026-07-16 20:41:40 +09:00
|
|
|
inputs.sandbox_init,
|
2026-07-16 18:53:20 +09:00
|
|
|
inputs.invoking_uid,
|
2026-07-16 18:39:03 +09:00
|
|
|
)
|
|
|
|
|
.map_err(|error| failure(format!("runtime staging: {error}")))?;
|
2026-07-18 02:08:14 +09:00
|
|
|
let git_routing = GitRoutingLayout::create(
|
|
|
|
|
inputs.configuration,
|
|
|
|
|
inputs.container_id,
|
|
|
|
|
inputs.invoking_uid,
|
|
|
|
|
)
|
|
|
|
|
.map_err(|error| failure(format!("Git-routing staging: {error}")))?;
|
2026-07-16 18:39:03 +09:00
|
|
|
let expected_network_namespace = namespace_identity(Path::new(NETWORK_NAMESPACE_PATH))
|
|
|
|
|
.map_err(|error| failure(format!("network namespace: {error}")))?;
|
2026-07-18 02:08:14 +09:00
|
|
|
let request = SandboxBuildRequest {
|
2026-07-16 18:39:03 +09:00
|
|
|
configuration: inputs.configuration,
|
|
|
|
|
container_id: inputs.container_id,
|
|
|
|
|
expected_network_namespace,
|
|
|
|
|
root_process: inputs.root_process,
|
|
|
|
|
terminal: None,
|
2026-07-17 03:58:27 +09:00
|
|
|
prepared_root: inputs.prepared_artifact_label.to_owned(),
|
2026-07-18 02:08:14 +09:00
|
|
|
};
|
|
|
|
|
let sandbox_bundle = match &git_routing {
|
|
|
|
|
Some(git_routing) => {
|
|
|
|
|
build_sandbox_bundle_with_workspace(request, git_routing.mountpoint_label.clone())
|
|
|
|
|
}
|
|
|
|
|
None => build_sandbox_bundle(request),
|
|
|
|
|
}
|
2026-07-16 18:39:03 +09:00
|
|
|
.map_err(|error| failure(format!("sandbox bundle: {error}")))?;
|
|
|
|
|
staging
|
|
|
|
|
.write_bundle(sandbox_bundle.specification_json())
|
|
|
|
|
.map_err(|error| failure(format!("bundle staging: {error}")))?;
|
|
|
|
|
let network_policy = derive_ipv4_policy(inputs.configuration, inputs.resolver_addresses)
|
|
|
|
|
.map_err(|error| failure(format!("network policy: {error}")))?;
|
|
|
|
|
let ownership = ProcessOwnershipContext {
|
|
|
|
|
domain_id: inputs.generation.domain_id,
|
|
|
|
|
generation_id: inputs.generation.generation_id,
|
|
|
|
|
coordinator_id: inputs.generation.coordinator_id,
|
|
|
|
|
slot: HostProcessOwnershipSlot::SandboxRuntimeSupervisor,
|
|
|
|
|
};
|
2026-07-17 03:58:27 +09:00
|
|
|
let state_anchor = StateAnchorLaunchAuthority::capture_retained(
|
|
|
|
|
&state_anchor_layout,
|
|
|
|
|
inputs.prepared_artifact,
|
|
|
|
|
inputs.prepared_artifact_label,
|
|
|
|
|
inputs.prepared_artifact_authority,
|
|
|
|
|
)
|
|
|
|
|
.map_err(|error| failure(format!("State Anchor authority: {error}")))?;
|
2026-07-18 02:08:14 +09:00
|
|
|
let mut runtime_launch = RuntimeSupervisorLaunch::from_networked_runsc_command(
|
2026-07-16 18:39:03 +09:00
|
|
|
ownership,
|
|
|
|
|
sandbox_bundle.command(),
|
|
|
|
|
RuntimeNetworkLaunch {
|
|
|
|
|
policy: &network_policy,
|
|
|
|
|
configuration_fingerprint: inputs.generation.configuration_fingerprint,
|
|
|
|
|
network_sidecar_id: inputs.generation.network_sidecar_id,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
.map_err(|error| failure(format!("Runtime Supervisor launch: {error}")))?
|
2026-07-19 03:56:49 +09:00
|
|
|
.with_state_anchor(state_anchor)
|
|
|
|
|
.map_err(|error| failure(format!("Runtime Supervisor handoff: {error}")))?;
|
2026-07-18 02:08:14 +09:00
|
|
|
if let Some(git_routing) = &git_routing {
|
2026-07-19 03:56:49 +09:00
|
|
|
runtime_launch = runtime_launch
|
|
|
|
|
.with_git_routing(
|
|
|
|
|
git_routing
|
|
|
|
|
.launch_authority(inputs.configuration)
|
|
|
|
|
.map_err(|error| failure(format!("Git-routing authority: {error}")))?,
|
|
|
|
|
)
|
|
|
|
|
.map_err(|error| failure(format!("Runtime Supervisor handoff: {error}")))?;
|
2026-07-18 02:08:14 +09:00
|
|
|
}
|
2026-07-16 18:39:03 +09:00
|
|
|
let bundle_digest =
|
|
|
|
|
BundleDigest::new(Sha256::digest(sandbox_bundle.specification_json()).into());
|
|
|
|
|
let generation_identity = GenerationIdentity {
|
|
|
|
|
agent_profile: inputs.configuration.selected_profile().to_owned(),
|
|
|
|
|
domain_id: inputs.generation.domain_id,
|
|
|
|
|
generation_id: inputs.generation.generation_id,
|
|
|
|
|
configuration_fingerprint: inputs.generation.configuration_fingerprint,
|
|
|
|
|
coordinator_id: inputs.generation.coordinator_id,
|
|
|
|
|
sandbox_id: inputs.generation.sandbox_id,
|
|
|
|
|
};
|
|
|
|
|
Ok(Self {
|
|
|
|
|
store: inputs.store,
|
|
|
|
|
catalog: inputs.catalog,
|
|
|
|
|
configuration: inputs.configuration,
|
|
|
|
|
generation: inputs.generation,
|
|
|
|
|
generation_identity,
|
|
|
|
|
prepared_artifact: inputs.prepared_artifact,
|
|
|
|
|
state_anchor_layout,
|
|
|
|
|
runtime_launch: Some(runtime_launch),
|
|
|
|
|
sandbox_bundle,
|
|
|
|
|
network_policy,
|
|
|
|
|
network_probe: inputs.network_probe,
|
|
|
|
|
reachability: inputs.reachability,
|
|
|
|
|
container_id: inputs.container_id,
|
|
|
|
|
runtime_root: runtime_domain.join("runsc"),
|
|
|
|
|
bundle_digest,
|
|
|
|
|
invoking_uid: inputs.invoking_uid,
|
2026-07-17 03:58:27 +09:00
|
|
|
staging,
|
2026-07-18 02:08:14 +09:00
|
|
|
git_routing,
|
2026-07-16 18:39:03 +09:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-18 22:35:48 +09:00
|
|
|
/// Runs cold start and exposes the exact retained lifecycle to one service loop.
|
2026-07-16 18:39:03 +09:00
|
|
|
///
|
|
|
|
|
/// # Errors
|
|
|
|
|
/// Returns staging, lifecycle, or service-loop failure. The service is single-use.
|
|
|
|
|
pub fn run<Service>(
|
|
|
|
|
mut self,
|
|
|
|
|
bootstrap_owner: Session,
|
|
|
|
|
owner_guard: &BootstrapOwnerGuard,
|
|
|
|
|
service: Service,
|
2026-07-18 22:35:48 +09:00
|
|
|
) -> Result<(), ColdStartError>
|
2026-07-16 18:39:03 +09:00
|
|
|
where
|
|
|
|
|
Service: FnOnce(
|
2026-07-18 22:35:48 +09:00
|
|
|
&Mutex<CoordinatorLifecycle<'_, '_>>,
|
2026-07-16 16:28:18 +09:00
|
|
|
&RefCell<BootstrapWaiterFace>,
|
|
|
|
|
&BootstrapOwnerGuard,
|
|
|
|
|
lazaret_core::identity::SessionId,
|
2026-07-18 22:35:48 +09:00
|
|
|
) -> Result<(), ColdStartError>,
|
2026-07-16 18:39:03 +09:00
|
|
|
{
|
2026-07-16 16:28:18 +09:00
|
|
|
let bootstrap_owner_session_id = bootstrap_owner.session_id;
|
|
|
|
|
let waiters = RefCell::new(
|
|
|
|
|
BootstrapWaiterFace::bind(
|
|
|
|
|
self.configuration,
|
|
|
|
|
self.generation.generation_id,
|
|
|
|
|
self.invoking_uid,
|
|
|
|
|
)
|
|
|
|
|
.map_err(failure)?,
|
|
|
|
|
);
|
2026-07-16 18:39:03 +09:00
|
|
|
let store = Arc::clone(&self.store);
|
|
|
|
|
let generation = self.generation.clone();
|
|
|
|
|
let plan = self.take_plan()?;
|
2026-07-18 22:35:48 +09:00
|
|
|
let mut lifecycle = coordinator_lifecycle(&store, plan).map_err(failure)?;
|
2026-07-16 16:28:18 +09:00
|
|
|
let bootstrap = lifecycle.bootstrap_new_domain_while_owner_live_and_service(
|
|
|
|
|
generation,
|
|
|
|
|
bootstrap_owner,
|
|
|
|
|
|| owner_guard.is_live().unwrap_or(false),
|
|
|
|
|
|lifecycle| {
|
|
|
|
|
waiters
|
|
|
|
|
.borrow_mut()
|
|
|
|
|
.admit_pending(lifecycle)
|
2026-07-18 22:35:48 +09:00
|
|
|
.map_err(crate::bootstrap::LifecycleServiceError::service)
|
2026-07-16 16:28:18 +09:00
|
|
|
},
|
|
|
|
|
|lifecycle| {
|
|
|
|
|
let mut waiters = waiters.borrow_mut();
|
|
|
|
|
waiters
|
|
|
|
|
.admit_pending(lifecycle)
|
2026-07-18 22:35:48 +09:00
|
|
|
.map_err(crate::bootstrap::LifecycleServiceError::service)?;
|
2026-07-16 16:28:18 +09:00
|
|
|
waiters
|
|
|
|
|
.withdraw()
|
2026-07-18 22:35:48 +09:00
|
|
|
.map_err(crate::bootstrap::LifecycleServiceError::service)
|
2026-07-16 16:28:18 +09:00
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
match bootstrap {
|
|
|
|
|
Ok(true) => {
|
|
|
|
|
for session_id in waiters.borrow_mut().notify(BootstrapWaitOutcome::Published) {
|
|
|
|
|
lifecycle.disconnect_session(session_id).map_err(failure)?;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(false) => {
|
|
|
|
|
let mut waiters = waiters.borrow_mut();
|
|
|
|
|
let withdrawal = waiters.withdraw();
|
|
|
|
|
let disconnected = waiters.notify(BootstrapWaitOutcome::Failed);
|
|
|
|
|
withdrawal.map_err(failure)?;
|
|
|
|
|
drop(waiters);
|
|
|
|
|
for session_id in disconnected {
|
|
|
|
|
lifecycle.disconnect_session(session_id).map_err(failure)?;
|
|
|
|
|
}
|
2026-07-18 22:35:48 +09:00
|
|
|
return Err(ColdStartError(
|
2026-07-16 16:28:18 +09:00
|
|
|
"bootstrap owner disconnected before publication".into(),
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
Err(error) => {
|
|
|
|
|
let mut waiters = waiters.borrow_mut();
|
|
|
|
|
let _ = waiters.withdraw();
|
|
|
|
|
let _ = waiters.notify(BootstrapWaitOutcome::Failed);
|
|
|
|
|
return Err(failure(error));
|
|
|
|
|
}
|
2026-07-16 18:39:03 +09:00
|
|
|
}
|
2026-07-16 16:28:18 +09:00
|
|
|
service(
|
|
|
|
|
&Mutex::new(lifecycle),
|
|
|
|
|
&waiters,
|
|
|
|
|
owner_guard,
|
|
|
|
|
bootstrap_owner_session_id,
|
|
|
|
|
)
|
2026-07-16 18:39:03 +09:00
|
|
|
}
|
|
|
|
|
|
2026-07-18 22:35:48 +09:00
|
|
|
fn take_plan(&mut self) -> Result<BootstrapPlan<'_>, ColdStartError> {
|
2026-07-17 07:20:21 +09:00
|
|
|
let interactive_executor = RunscInteractiveSessionExecutor::new(
|
|
|
|
|
Arc::clone(&self.store),
|
|
|
|
|
&self.generation_identity,
|
|
|
|
|
self.container_id,
|
|
|
|
|
current_process_identity().map_err(failure)?,
|
|
|
|
|
self.sandbox_bundle.command(),
|
|
|
|
|
self.runtime_root.clone(),
|
|
|
|
|
)
|
|
|
|
|
.map_err(failure)?;
|
|
|
|
|
let prompt_transport = interactive_executor.prompt_transport();
|
2026-07-18 22:35:48 +09:00
|
|
|
Ok(BootstrapPlan {
|
2026-07-16 18:39:03 +09:00
|
|
|
store: Arc::clone(&self.store),
|
|
|
|
|
catalog: self.catalog,
|
|
|
|
|
configuration: self.configuration,
|
|
|
|
|
generation_identity: self.generation_identity.clone(),
|
|
|
|
|
prepared_artifact: self.prepared_artifact,
|
|
|
|
|
state_anchor_layout: &self.state_anchor_layout,
|
2026-07-18 22:35:48 +09:00
|
|
|
runtime_launch: self
|
|
|
|
|
.runtime_launch
|
|
|
|
|
.take()
|
|
|
|
|
.ok_or_else(|| ColdStartError("cold start was already consumed".into()))?,
|
2026-07-16 18:39:03 +09:00
|
|
|
sandbox_bundle: &self.sandbox_bundle,
|
|
|
|
|
network_policy: &self.network_policy,
|
|
|
|
|
network_probe: self.network_probe.clone(),
|
|
|
|
|
reachability: &self.reachability,
|
|
|
|
|
container_id: self.container_id,
|
|
|
|
|
runtime_root: self.runtime_root.clone(),
|
|
|
|
|
bundle_digest: self.bundle_digest,
|
|
|
|
|
invoking_uid: self.invoking_uid,
|
2026-07-16 16:28:18 +09:00
|
|
|
non_interactive_executor: Arc::new(
|
|
|
|
|
RunscNonInteractiveExecutor::from_run_command(
|
|
|
|
|
self.sandbox_bundle.command(),
|
|
|
|
|
self.container_id,
|
|
|
|
|
)
|
|
|
|
|
.map_err(failure)?,
|
|
|
|
|
),
|
2026-07-17 07:20:21 +09:00
|
|
|
interactive_executor: Arc::new(interactive_executor),
|
|
|
|
|
prompt_transport,
|
2026-07-17 03:58:27 +09:00
|
|
|
runtime_staging: &self.staging,
|
2026-07-18 02:08:14 +09:00
|
|
|
git_routing: self.git_routing.as_ref().map(|routing| {
|
2026-07-18 22:35:48 +09:00
|
|
|
crate::bootstrap::BootstrapGitRouting {
|
2026-07-18 02:08:14 +09:00
|
|
|
mountpoint: routing.mountpoint(),
|
|
|
|
|
host_root: routing.host_root(),
|
|
|
|
|
isolated_root: routing.isolated_root(),
|
|
|
|
|
}
|
|
|
|
|
}),
|
2026-07-16 18:39:03 +09:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-18 22:35:48 +09:00
|
|
|
fn require_inputs(inputs: &ColdStartInputs<'_>) -> Result<(), ColdStartError> {
|
2026-07-16 18:39:03 +09:00
|
|
|
if inputs.generation.domain_id != inputs.configuration.domain_id()
|
|
|
|
|
|| inputs.generation.configuration_fingerprint
|
|
|
|
|
!= inputs.configuration.configuration_fingerprint()
|
|
|
|
|
|| inputs.network_probe.domain_id != inputs.generation.domain_id
|
|
|
|
|
|| inputs.network_probe.generation_id != inputs.generation.generation_id
|
|
|
|
|
|| inputs.resolver_addresses.is_empty()
|
2026-07-16 18:53:20 +09:00
|
|
|
|| inputs.invoking_uid != rustix::process::getuid().as_raw()
|
2026-07-16 18:39:03 +09:00
|
|
|
{
|
2026-07-18 22:35:48 +09:00
|
|
|
return Err(ColdStartError("cold-start inputs disagree".into()));
|
2026-07-16 18:39:03 +09:00
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-19 05:12:57 +09:00
|
|
|
mod git_routing;
|
|
|
|
|
mod runtime_staging;
|
|
|
|
|
|
|
|
|
|
use git_routing::GitRoutingLayout;
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
use git_routing::parse_global_excludes_path;
|
|
|
|
|
pub(crate) use runtime_staging::RuntimeStaging;
|
|
|
|
|
use runtime_staging::{
|
|
|
|
|
FileIdentity, confined_resolve_flags, hex, host_path, open_or_create_private_directory,
|
|
|
|
|
remove_staging_directory, require_private_file,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests;
|