Skip to content

Commit 8e4ea44

Browse files
committed
feat(podman): rotate launch-scoped authentication
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent 2043b32 commit 8e4ea44

4 files changed

Lines changed: 195 additions & 47 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,7 @@ pub fn build_isolation_specs(
14661466
"--topology-payload-file={}",
14671467
crate::isolation::TOPOLOGY_PATH
14681468
),
1469+
format!("--auth-bundle-file={}", crate::isolation::AUTH_BUNDLE_PATH),
14691470
"--health-socket-path=/run/openshell/supervisor-health.sock".into(),
14701471
]);
14711472
supervisor.env.insert(

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

Lines changed: 104 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@ use url::Url;
4040
const STOP_COMPLETION_POLL_INTERVAL: Duration = Duration::from_millis(50);
4141
const STOP_COMPLETION_TIMEOUT_HEADROOM: Duration = Duration::from_secs(5);
4242

43+
fn decode_launch_authentication(
44+
encoded: &[u8],
45+
) -> Result<openshell_core::jwt::SandboxLaunchAuthentication, ComputeDriverError> {
46+
let authentication =
47+
serde_json::from_slice::<openshell_core::jwt::SandboxLaunchAuthentication>(encoded)
48+
.map_err(|error| {
49+
ComputeDriverError::Precondition(format!(
50+
"decode Podman sandbox launch authentication: {error}"
51+
))
52+
})?;
53+
authentication.validate().map_err(|error| {
54+
ComputeDriverError::Precondition(format!(
55+
"validate Podman sandbox launch authentication: {error}"
56+
))
57+
})?;
58+
Ok(authentication)
59+
}
60+
4361
impl From<PodmanApiError> for ComputeDriverError {
4462
fn from(value: PodmanApiError) -> Self {
4563
match value {
@@ -1012,11 +1030,24 @@ impl PodmanComputeDriver {
10121030
.map(|(key, value)| (key.into(), value.into()))
10131031
})
10141032
.collect();
1033+
let launch_authentication = sandbox
1034+
.spec
1035+
.as_ref()
1036+
.filter(|spec| !spec.launch_authentication.is_empty())
1037+
.ok_or_else(|| {
1038+
ComputeDriverError::Precondition(
1039+
"Podman sandbox launch authentication is required".to_string(),
1040+
)
1041+
})
1042+
.and_then(|spec| {
1043+
decode_launch_authentication(&spec.launch_authentication)
1044+
})?;
10151045
let archives = crate::isolation::bootstrap_archives(
10161046
&sandbox.id,
10171047
&workload_id,
10181048
&identity,
10191049
child_env,
1050+
&launch_authentication,
10201051
)?;
10211052
self.client
10221053
.copy_to_container(
@@ -1273,8 +1304,13 @@ impl PodmanComputeDriver {
12731304
sandbox.id = %sandbox_id,
12741305
)
12751306
)]
1276-
pub async fn start_sandbox(&self, sandbox_id: &str) -> Result<(), ComputeDriverError> {
1307+
pub async fn start_sandbox(
1308+
&self,
1309+
sandbox_id: &str,
1310+
encoded_authentication: &[u8],
1311+
) -> Result<(), ComputeDriverError> {
12771312
let span_status = openshell_otel::ErrorStatusGuard::current();
1313+
let launch_authentication = decode_launch_authentication(encoded_authentication)?;
12781314
let container = self
12791315
.find_container(sandbox_id)
12801316
.await?
@@ -1322,8 +1358,23 @@ impl PodmanComputeDriver {
13221358
.await?;
13231359
let bundle =
13241360
extract_first_tar_entry(&archive).map_err(ComputeDriverError::Precondition)?;
1361+
let previous_config = crate::isolation::boundary_config_from_channel_archive(&bundle)?;
1362+
let archives = crate::isolation::bootstrap_archives(
1363+
sandbox_id,
1364+
&container_id,
1365+
&previous_config.workload_identity,
1366+
previous_config.child_env,
1367+
&launch_authentication,
1368+
)?;
1369+
self.client
1370+
.copy_to_container(
1371+
&container_id,
1372+
crate::isolation::CHANNEL_ROOT,
1373+
archives.channel,
1374+
)
1375+
.await?;
13251376
self.client
1326-
.copy_to_container(&container_id, crate::isolation::CHANNEL_ROOT, bundle)
1377+
.copy_to_container(&supervisor, "/", archives.supervisor)
13271378
.await?;
13281379
self.client.verify_isolation_fence(&container_id).await?;
13291380
self.client.start_container(&container_id).await?;
@@ -1770,13 +1821,39 @@ mod tests {
17701821
use super::*;
17711822
use crate::test_utils::{StubResponse, spawn_podman_stub};
17721823
use hyper::StatusCode;
1824+
use openshell_core::jwt::{
1825+
CredentialEpoch, SandboxLaunchAuthentication, SecretJwt, SessionVerificationKey,
1826+
SupervisorAuthBundle,
1827+
};
17731828
use openshell_core::proto::compute::v1::{
17741829
DriverSandboxSpec, DriverSandboxTemplate, ResourceRequirements,
17751830
};
17761831
use std::collections::HashMap;
17771832
use std::fs;
17781833
use std::path::{Path, PathBuf};
17791834

1835+
fn launch_authentication() -> SandboxLaunchAuthentication {
1836+
SandboxLaunchAuthentication {
1837+
supervisor: SupervisorAuthBundle {
1838+
session_id: openshell_core::SandboxSessionId::new(),
1839+
gateway_token: SecretJwt::parse("gateway.token.value").unwrap(),
1840+
gateway_expires_at: i64::MAX,
1841+
sandbox_token: SecretJwt::parse("sandbox.token.value").unwrap(),
1842+
sandbox_expires_at: i64::MAX,
1843+
credential_epoch: CredentialEpoch::new(1).unwrap(),
1844+
},
1845+
gateway_id: "gateway-test".to_string(),
1846+
verification_keys: vec![SessionVerificationKey {
1847+
key_id: "test-key".to_string(),
1848+
public_key_pem: b"public-key".to_vec(),
1849+
}],
1850+
}
1851+
}
1852+
1853+
fn encoded_launch_authentication() -> Vec<u8> {
1854+
serde_json::to_vec(&launch_authentication()).unwrap()
1855+
}
1856+
17801857
// ── socket resolution ───────────────────────────────────────────────
17811858
//
17821859
// These test resolve_socket_path directly with an injected detector, so
@@ -1893,8 +1970,9 @@ mod tests {
18931970
),
18941971
].into_iter().chain(restart_responses()).collect(),
18951972
);
1973+
let authentication = encoded_launch_authentication();
18961974
test_driver(start_socket.clone())
1897-
.start_sandbox("sandbox-1")
1975+
.start_sandbox("sandbox-1", &authentication)
18981976
.await
18991977
.expect("start should succeed");
19001978
start_handle.await.expect("start stub should finish");
@@ -1905,10 +1983,16 @@ mod tests {
19051983
.filter(|request| request.starts_with("PUT "))
19061984
.cloned()
19071985
.collect::<Vec<_>>(),
1908-
vec![format!(
1909-
"PUT {}",
1910-
api_path("/libpod/containers/ctr-1/archive?path=%2F.openshell%2Fchannel")
1911-
)]
1986+
vec![
1987+
format!(
1988+
"PUT {}",
1989+
api_path("/libpod/containers/ctr-1/archive?path=%2F.openshell%2Fchannel")
1990+
),
1991+
format!(
1992+
"PUT {}",
1993+
api_path("/libpod/containers/openshell-supervisor-sandbox-1/archive?path=%2F")
1994+
),
1995+
]
19121996
);
19131997
assert!(
19141998
!restart_requests
@@ -2192,8 +2276,9 @@ mod tests {
21922276
),
21932277
].into_iter().chain(restart_responses()).collect(),
21942278
);
2279+
let authentication = encoded_launch_authentication();
21952280
test_driver(start_socket.clone())
2196-
.start_sandbox("sandbox-1")
2281+
.start_sandbox("sandbox-1", &authentication)
21972282
.with_subscriber(subscriber)
21982283
.await
21992284
.expect("start should succeed");
@@ -3135,10 +3220,16 @@ mod tests {
31353220
"sha256:image".into(),
31363221
)
31373222
.unwrap();
3138-
let bundle =
3139-
crate::isolation::bootstrap_archives("sandbox-1", "ctr-1", &identity, HashMap::new())
3140-
.unwrap()
3141-
.channel;
3223+
let authentication = launch_authentication();
3224+
let bundle = crate::isolation::bootstrap_archives(
3225+
"sandbox-1",
3226+
"ctr-1",
3227+
&identity,
3228+
HashMap::new(),
3229+
&authentication,
3230+
)
3231+
.unwrap()
3232+
.channel;
31423233
let mut header = tar::Header::new_gnu();
31433234
header.set_size(bundle.len() as u64);
31443235
header.set_mode(0o600);
@@ -3154,6 +3245,7 @@ mod tests {
31543245
),
31553246
StubResponse::new(StatusCode::OK, archive.into_inner().unwrap()),
31563247
StubResponse::new(StatusCode::OK, "").with_archive_members(channel_archive_members()),
3248+
StubResponse::new(StatusCode::OK, ""), // refreshed supervisor auth and topology
31573249
fence_response(),
31583250
StubResponse::new(StatusCode::NO_CONTENT, ""), // workload start
31593251
StubResponse::new(StatusCode::NO_CONTENT, ""), // supervisor start
@@ -3267,7 +3359,6 @@ mod tests {
32673359
"sandbox/bootstrap.json",
32683360
"sandbox/server.crt",
32693361
"sandbox/server.key",
3270-
"sandbox/client-ca.crt",
32713362
]
32723363
}
32733364

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl ComputeDriver for ComputeDriverService {
200200
return Err(Status::invalid_argument("sandbox_id is required"));
201201
}
202202
self.driver
203-
.start_sandbox(&request.sandbox_id)
203+
.start_sandbox(&request.sandbox_id, &request.launch_authentication)
204204
.await
205205
.map_err(Status::from)?;
206206
Ok(Response::new(StartSandboxResponse {}))

0 commit comments

Comments
 (0)