Skip to content

Commit fabdfd0

Browse files
dhoehnaCopilot
andcommitted
[LXC] Implement StatefulSandboxBackend for LXC (state-aware lifecycle) (AB#62953349)
Provision/start/exec/stop/deprovision for the LXC backend, modeled on IsolationSessionRunner; reuses lxc CLI wrappers and one-shot lxc-attach PTY streaming. Registers the lxc wire key in Rust dispatch/parser and SDK state-aware routing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3b78bec0-e139-4cfd-9c10-092ef986d4f4
1 parent d3191e4 commit fabdfd0

10 files changed

Lines changed: 784 additions & 11 deletions

File tree

sdk/src/state-aware-helper.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@ export const STATE_AWARE_VERSION = '0.6.0-alpha';
1313
// Wire-format cross-cutting fields that live at the envelope's top level.
1414
// Anything else on a per-(backend, phase) Config is backend-specific and is
1515
// nested under `experimental.<backend>.<phase>`.
16-
export const CROSS_CUTTING_FIELDS = ['filesystem', 'network', 'ui', 'process'] as const;
16+
export const CROSS_CUTTING_FIELDS = ['containerId', 'filesystem', 'network', 'ui', 'process'] as const;
1717

1818
// Per-backend wire-format prefix. Each value mirrors the corresponding
1919
// Rust `<Backend>Runner::ID_PREFIX` const and is the leading segment of a
2020
// `sandboxId` produced by that backend. Each future state-aware backend
2121
// declares its own `<BACKEND>_ID_PREFIX` const here.
2222
export const ISOLATION_SESSION_ID_PREFIX = 'iso';
23+
export const LXC_ID_PREFIX = 'lxc';
2324

2425
// Mapping from a sandboxId's leading prefix segment to the wire-format
2526
// backend key. Extended as more state-aware backends opt in.
2627
export const PREFIX_TO_BACKEND: Record<string, StateAwareContainmentBackend> = {
2728
[ISOLATION_SESSION_ID_PREFIX]: 'isolation_session',
29+
[LXC_ID_PREFIX]: 'lxc',
2830
};
2931

3032
/**

sdk/src/state-aware-types.ts

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import {
55
ContainmentBackend,
66
FilesystemConfig,
7+
NetworkConfig,
78
ProcessConfig,
89
} from './types.js';
910

@@ -16,7 +17,7 @@ export type Phase = 'provision' | 'start' | 'exec' | 'stop' | 'deprovision';
1617
* Subset of `ContainmentBackend` whose backends participate in the state-aware
1718
* lifecycle. Extended as more backends opt in.
1819
*/
19-
export type StateAwareContainmentBackend = Extract<ContainmentBackend, 'isolation_session'>;
20+
export type StateAwareContainmentBackend = Extract<ContainmentBackend, 'isolation_session' | 'lxc'>;
2021

2122
/**
2223
* Branded sandbox identifier returned by `provisionSandbox` and routed back
@@ -99,6 +100,42 @@ export interface IsolationSessionDeprovisionConfig {
99100
version?: string;
100101
}
101102

103+
export interface LxcProvisionConfig {
104+
/** Schema version (semver). */
105+
version?: string;
106+
/** Optional externally assigned LXC container name. */
107+
containerId?: string;
108+
/** Linux distribution for the container rootfs, e.g. "alpine" or "ubuntu". */
109+
distribution: string;
110+
/** Distribution release version, e.g. "3.20" or "24.04". */
111+
release: string;
112+
}
113+
114+
export interface LxcStartConfig {
115+
/** Schema version (semver). */
116+
version?: string;
117+
/** Filesystem mounts to apply before starting the container. */
118+
filesystem?: FilesystemConfig;
119+
/** iptables policy to apply after the container starts. */
120+
network?: NetworkConfig;
121+
}
122+
123+
export interface LxcExecConfig {
124+
/** Schema version (semver). */
125+
version?: string;
126+
process: ProcessConfig;
127+
}
128+
129+
export interface LxcStopConfig {
130+
/** Schema version (semver). */
131+
version?: string;
132+
}
133+
134+
export interface LxcDeprovisionConfig {
135+
/** Schema version (semver). */
136+
version?: string;
137+
}
138+
102139
/**
103140
* IsolationSession's provision-phase metadata: the per-instance agent user
104141
* account name minted for this sandbox.
@@ -107,6 +144,11 @@ export interface IsolationSessionProvisionMetadata {
107144
agentUserName: string;
108145
}
109146

147+
export interface LxcProvisionMetadata {
148+
containerName: string;
149+
created: boolean;
150+
}
151+
110152
/**
111153
* Per-backend per-phase typed Config bundle. Selects the correct Config
112154
* bundle for the backend type parameter.
@@ -120,6 +162,14 @@ export type ConfigsForBackend<C extends StateAwareContainmentBackend> =
120162
stop: IsolationSessionStopConfig;
121163
deprovision: IsolationSessionDeprovisionConfig;
122164
}
165+
: C extends 'lxc'
166+
? {
167+
provision: LxcProvisionConfig;
168+
start: LxcStartConfig;
169+
exec: LxcExecConfig;
170+
stop: LxcStopConfig;
171+
deprovision: LxcDeprovisionConfig;
172+
}
123173
: never;
124174

125175
export type ProvisionConfigFor<C extends StateAwareContainmentBackend> =
@@ -142,7 +192,10 @@ export interface StateAwareMetadata {
142192
provision?: IsolationSessionProvisionMetadata;
143193
// IsolationSession returns no metadata for start, stop, or deprovision.
144194
};
145-
// Future state-aware-capable backends add typed entries here.
195+
lxc?: {
196+
provision?: LxcProvisionMetadata;
197+
// LXC returns no metadata for start, stop, or deprovision.
198+
};
146199
}
147200

148201
type MetadataForPhase<C extends StateAwareContainmentBackend, Phase extends string> =

src/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/backends/lxc/common/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ pub mod lxc_bindings;
66
pub mod lxc_runner;
77
pub mod network_iptables;
88
pub mod signal_cleanup;
9+
pub mod state_aware;

0 commit comments

Comments
 (0)