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