Skip to content

Commit a0846a5

Browse files
committed
feat(podman): support verified provider workload identity
Let the Podman driver start supervisors that a Workload API issuer can bind to one sandbox launch, and make those starts replayable. - The driver labels the supervisor container with the launch SPIFFE ID and advertises provider workload identity and ordered provider start when the socket and supervisor image qualify. A probe checks the image and the projected socket before the supervisor is trusted. - A verified start replaces only the supervisor. It resolves the image, identity and probe first, then removes the old supervisor and creates the new one. The workload container, its volumes and its secrets stay. A replaced supervisor reads proxy_auth_file again. - StartSandbox and StopSandbox run under the launch journal. A replay settles when this launch's supervisor is running and ready. Otherwise it stops the workload, removes this launch's supervisor by container ID, and records the failure once Podman confirms. - An ordered stop waits for a terminal state and kills a paused workload without letting it resume. One failed status read does not make the outcome unknown. - Delete and unordered Stop wait for a launch that owns the journal. Delete removes every supervisor of the sandbox and its journal. - When a verified supervisor is lost, the watcher stops the workload under the launch lock and records a stop it could not confirm. Without the gateway's explicit selection the driver keeps its current behavior. A failed replacement of a running pair falls back to an ordinary restart. Signed-off-by: Shiju <shiju@nvidia.com>
1 parent b59f687 commit a0846a5

11 files changed

Lines changed: 4240 additions & 712 deletions

File tree

‎crates/openshell-driver-podman/README.md‎

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,23 @@ binary extraction path. `supervisor_image` supplies the dynamically linked
100100
glibc `/openshell-supervisor` binary outside the workload. Image and request
101101
environment belong to agent children, never the supervisor process.
102102

103+
With verified SPIFFE provider grants, a restart that only changes the launch
104+
identity recreates the supervisor with the same local image. If the image or
105+
other launch settings have changed, the driver refreshes mutable tags before
106+
selecting and verifying a replacement image.
107+
To upgrade an otherwise compatible supervisor, pull the updated tag into
108+
the Podman service used by OpenShell or configure a new `supervisor_image`
109+
digest before restarting.
110+
111+
A verified start selects and probes the image before it changes anything.
112+
It then stops the pair, removes the previous supervisor, and creates the
113+
replacement under the same name, so a sandbox never has two supervisors.
114+
When the gateway replays an interrupted start, the driver starts nothing.
115+
If that launch's supervisor is running and ready, the start succeeded.
116+
Otherwise the driver stops the workload, removes the supervisor that carries
117+
that launch's label, and reports the launch as failed so the next start can
118+
proceed. It reports `UNAVAILABLE` while Podman cannot confirm those steps.
119+
103120
## OCI working directory
104121

105122
OpenShell reads `WORKDIR` from the workload image. If it is unset, `/`, or
@@ -129,11 +146,13 @@ driver-owned volumes and secrets.
129146
Stop retains both containers, workspace, channel, and secrets. Start restores
130147
the consumed sandbox bootstrap from a copy in the supervisor's private
131148
filesystem, verifies the fence, and starts the same pair. A failed supervisor
132-
start stops the workload. Delete removes the companion first, then the workload,
133-
channel, workspace, and driver-owned secrets. User-owned volumes are retained.
134-
Delete keeps a channel, control, or workspace volume whose
149+
start stops the workload. Delete removes every supervisor container labelled
150+
with the sandbox ID first, then the workload, channel, workspace, driver-owned
151+
secrets, and the sandbox's provider launch journal. User-owned volumes are
152+
retained. Delete keeps a channel, control, or workspace volume whose
135153
`openshell.ai/sandbox-id` label is missing or names another sandbox, and logs a
136-
warning.
154+
warning. While a provider launch holds the sandbox's journal lock, Delete and an
155+
unordered Stop return `UNAVAILABLE`.
137156

138157
Only workload containers appear in sandbox list/watch results. Readiness uses
139158
the supervisor's private health socket; there is no shell, legacy marker, or
@@ -153,6 +172,12 @@ root cannot be replaced. User-owned volumes are never created or deleted.
153172
See [gateway configuration](../../docs/how-it-works/gateways/configuration.mdx) for
154173
operator settings and [NETWORKING.md](NETWORKING.md) for supervisor networking.
155174
The supervisor uses Podman's host network and owns the upstream proxy settings.
175+
When OpenShell replaces a supervisor and retains the workload, it reads
176+
`proxy_auth_file` again and creates a proxy secret for the new supervisor.
177+
Updated proxy credentials apply at the next replacement: every restart with
178+
verified SPIFFE provider grants, otherwise a restart that follows a
179+
destination-trust or Workload API socket change. A restart that keeps the
180+
supervisor keeps its secret.
156181
Omit `health_check_interval_secs` to disable Podman's periodic health command.
157182
Explicit zero is invalid. OpenShell still gates readiness on the supervisor's
158183
authenticated health signal.

‎crates/openshell-driver-podman/src/client.rs‎

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use tracing::{debug, warn};
2121
const API_VERSION: &str = "v5.0.0";
2222

2323
/// Timeout for individual Podman API calls.
24-
const API_TIMEOUT: Duration = Duration::from_mins(1);
24+
pub const API_TIMEOUT: Duration = Duration::from_mins(1);
2525

2626
/// Maximum allowed size for the event stream line buffer (1 MB).
2727
const MAX_EVENT_BUFFER: usize = 1_048_576;
@@ -91,6 +91,8 @@ pub struct ContainerInspect {
9191
#[serde(default)]
9292
pub mounts: Option<Vec<Value>>,
9393
pub id: String,
94+
#[serde(default)]
95+
pub image: String,
9496
pub name: String,
9597
pub state: ContainerState,
9698
#[serde(default)]
@@ -172,12 +174,33 @@ pub struct ContainerConfig {
172174
pub labels: HashMap<String, String>,
173175
#[serde(default)]
174176
pub user: String,
175-
/// The immutable image ID the container was created from. Podman records
176-
/// the reference used at creation time here; workloads are always created
177-
/// from a resolved image ID, so this pins the image the container runs
178-
/// independently of any later tag movement.
179177
#[serde(default)]
180-
pub image: String,
178+
pub secrets: Option<Vec<ContainerSecret>>,
179+
#[serde(
180+
default,
181+
rename = "Env",
182+
deserialize_with = "provider_spiffe_socket_from_env"
183+
)]
184+
pub provider_spiffe_socket: Option<String>,
185+
}
186+
187+
#[derive(Debug, Clone, serde::Deserialize)]
188+
#[serde(rename_all = "PascalCase")]
189+
pub struct ContainerSecret {
190+
pub name: String,
191+
}
192+
193+
fn provider_spiffe_socket_from_env<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
194+
where
195+
D: serde::Deserializer<'de>,
196+
{
197+
let env = <Option<Vec<String>> as serde::Deserialize>::deserialize(deserializer)?;
198+
Ok(env.into_iter().flatten().find_map(|entry| {
199+
let (name, value) = entry.split_once('=')?;
200+
(name == openshell_core::sandbox_env::PROVIDER_SPIFFE_WORKLOAD_API_SOCKET
201+
&& !value.is_empty())
202+
.then(|| value.to_owned())
203+
}))
181204
}
182205

183206
/// Immutable image metadata needed to bind OCI identity inspection to launch.
@@ -612,6 +635,26 @@ impl PodmanClient {
612635
.await
613636
}
614637

638+
pub(crate) async fn kill_paused_container(&self, name: &str) -> Result<(), PodmanApiError> {
639+
validate_name(name)?;
640+
self.request_ok(
641+
hyper::Method::POST,
642+
&format!("/libpod/containers/{name}/kill?signal=SIGKILL"),
643+
None,
644+
)
645+
.await
646+
}
647+
648+
pub(crate) async fn wait_for_container_exit(&self, name: &str) -> Result<i32, PodmanApiError> {
649+
validate_name(name)?;
650+
self.request_json(
651+
hyper::Method::POST,
652+
&format!("/libpod/containers/{name}/wait?condition=exited"),
653+
None,
654+
)
655+
.await
656+
}
657+
615658
/// Stop a container with a grace period in seconds.
616659
pub async fn stop_container(
617660
&self,
@@ -728,6 +771,28 @@ impl PodmanClient {
728771
}
729772
}
730773

774+
pub(crate) async fn container_path_exists(
775+
&self,
776+
name: &str,
777+
path: &str,
778+
) -> Result<bool, PodmanApiError> {
779+
validate_name(name)?;
780+
let encoded_path = url_encode(path);
781+
let (status, bytes) = self
782+
.request(
783+
hyper::Method::HEAD,
784+
&format!("/libpod/containers/{name}/archive?path={encoded_path}"),
785+
None,
786+
API_TIMEOUT,
787+
)
788+
.await?;
789+
match status {
790+
hyper::StatusCode::NOT_FOUND => Ok(false),
791+
status if status.is_success() => Ok(true),
792+
status => Err(error_from_response(status.as_u16(), &bytes)),
793+
}
794+
}
795+
731796
/// Inspect a container by name or ID.
732797
pub async fn inspect_container(&self, name: &str) -> Result<ContainerInspect, PodmanApiError> {
733798
validate_name(name)?;

0 commit comments

Comments
 (0)