Skip to main content

a3s_box_runtime/
lib.rs

1//! A3S Box Runtime - MicroVM runtime implementation.
2//!
3//! This module provides the actual runtime implementation for A3S Box,
4//! including VM management, OCI image handling, rootfs building, and gRPC health checks.
5//!
6//! # Feature Flags
7//!
8//! - `pool` — Warm VM pool with autoscaling (enabled by default)
9//! - `scale` — Multi-node scale manager and instance registry (enabled by default)
10//! - `compose` — Multi-container compose orchestration (enabled by default)
11//! - `operator` — Kubernetes CRD autoscaler controller (enabled by default)
12//! - `build` — Dockerfile/Containerfile build engine (enabled by default)
13
14#![allow(clippy::result_large_err)]
15
16// -- Core modules (always compiled) --
17#[cfg(all(feature = "vm", target_os = "linux"))]
18pub mod a3s_runtime_driver;
19pub mod audit;
20pub mod box_record;
21pub mod box_state;
22pub mod cache;
23pub(crate) mod file_lock;
24pub mod fs;
25pub mod grpc;
26pub mod host_check;
27pub mod local_execution;
28pub mod log;
29pub mod managed_execution_store;
30pub mod network;
31pub mod oci;
32pub mod process;
33pub mod prom;
34pub mod resize;
35mod resolved_image;
36pub mod rootfs;
37pub mod sandbox;
38pub mod snapshot;
39mod store_io;
40#[cfg(unix)]
41pub mod tee;
42#[cfg(feature = "vm")]
43pub mod vm;
44#[cfg(feature = "vm")]
45pub mod vmm;
46pub mod volume;
47
48// -- Optional modules (feature-gated) --
49#[cfg(feature = "compose")]
50pub mod compose;
51#[cfg(feature = "operator")]
52pub mod operator;
53#[cfg(feature = "pool")]
54pub mod pool;
55#[cfg(feature = "scale")]
56pub mod scale;
57
58// ── Core re-exports (used by CLI, CRI, SDK, shim) ──
59
60// Audit
61pub use audit::{read_audit_log, AuditLog, AuditQuery};
62
63#[cfg(all(feature = "vm", target_os = "linux"))]
64pub use a3s_runtime_driver::{BoxRuntimeDriver, BoxRuntimeDriverConfig};
65
66// Canonical local execution metadata
67pub use box_record::{
68    BoxRecord, HealthCheck, ManagedExecutionMetadata, ManagedExecutionOperation,
69    ManagedExecutionState, ManagedRestartCompletion, ManagedRestartOutcome,
70};
71pub use box_state::BoxStateStore;
72#[cfg(feature = "vm")]
73pub use local_execution::VmLocalExecutionBackend;
74pub use local_execution::{
75    acquire_execution_lifecycle_lock, ExecutionLifecycleLock, LocalExecutionBackend,
76    LocalExecutionHandle, LocalExecutionManager, LocalExecutionObservation,
77};
78pub use managed_execution_store::{
79    ManagedExecutionReservation, ManagedExecutionStore, ManagedExecutionStoreError,
80    ManagedExecutionStoreResult,
81};
82pub use process::{is_process_alive, is_process_alive_with_identity, pid_start_time};
83
84// gRPC clients
85#[cfg(unix)]
86pub use grpc::{
87    AttestationClient, ExecClient, PtyClient, RaTlsAttestationClient, StreamingExec,
88    StreamingExecInput, StreamingPty, StreamingPtyInput,
89};
90#[cfg(unix)]
91pub use grpc::{SealClient, SecretEntry, SecretInjector};
92
93// Host checks
94pub use host_check::check_virtualization_support;
95
96// Network
97pub use network::NetworkStore;
98
99// OCI images
100pub use a3s_box_core::StoredImage;
101pub use oci::{CredentialStore, PushResult, RegistryProtocol, RegistryPusher};
102pub use oci::{
103    ImagePuller, ImageReference, ImageStore, PullProgress, PullProgressEventFn, PullProgressState,
104    RegistryAuth, RegistryPullPolicy,
105};
106pub use oci::{OciImage, SignResult, SignaturePolicy};
107
108// Metrics
109pub use prom::RuntimeMetrics;
110
111// Snapshot
112pub use resolved_image::{load_resolved_image_config, RESOLVED_IMAGE_CONFIG_FILE};
113pub use snapshot::SnapshotStore;
114
115// TEE
116#[cfg(unix)]
117pub use tee::{seal, unseal};
118#[cfg(unix)]
119pub use tee::{
120    verify_attestation, verify_attestation_with_time, AmdKdsClient, AttestationPolicy,
121    MinTcbPolicy, PolicyResult, VerificationResult,
122};
123#[cfg(unix)]
124pub use tee::{AttestationReport, AttestationRequest, PlatformInfo};
125
126// VM
127#[cfg(feature = "vm")]
128pub use vm::{BoxState, PullProgressFn, VmManager};
129#[cfg(feature = "vm")]
130pub use vmm::{
131    Entrypoint, FsMount, InstanceSpec, NetworkInstanceConfig, ShimHandler, TeeInstanceConfig,
132    VmController, VmHandler, VmMetrics, VmmProvider,
133};
134
135// Resize
136pub use resize::{validate_update, ResizeResult, ResourceUpdate};
137
138// Volume
139pub use volume::VolumeStore;
140
141// ── Feature-gated re-exports ──
142
143#[cfg(feature = "build")]
144pub use oci::{BuildConfig, BuildRunPoolConfig, Dockerfile, Instruction};
145
146#[cfg(feature = "compose")]
147#[allow(deprecated)]
148pub use compose::{ComposeProject, ComposeRuntimePlan, HealthCheckSpec};
149
150#[cfg(feature = "operator")]
151pub use operator::AutoscalerController;
152
153#[cfg(feature = "pool")]
154pub use pool::WarmPool;
155
156#[cfg(feature = "scale")]
157pub use scale::ScaleManager;
158
159// ── Constants ──
160
161/// A3S Box Runtime version.
162pub const VERSION: &str = env!("CARGO_PKG_VERSION");
163
164pub use a3s_box_core::{ATTEST_VSOCK_PORT, EXEC_VSOCK_PORT, PORT_FWD_VSOCK_PORT, PTY_VSOCK_PORT};
165
166/// Default maximum image cache size: 10 GB.
167pub const DEFAULT_IMAGE_CACHE_SIZE: u64 = 10 * 1024 * 1024 * 1024;