Skip to content

Commit 7d38aa8

Browse files
authored
fix(homebrew): repair local driver bootstrap state (ai-openshell#1527)
* fix(homebrew): repair local driver bootstrap state * fix(bootstrap): satisfy default SAN doc lint
1 parent 0dc08a1 commit 7d38aa8

6 files changed

Lines changed: 343 additions & 17 deletions

File tree

‎crates/openshell-bootstrap/src/pki.rs‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ pub struct PkiBundle {
2424
pub jwt_key_id: String,
2525
}
2626

27-
/// Default SANs always included on the server certificate. Covers the host
28-
/// aliases used by every supported runtime: Kubernetes service DNS,
27+
/// Default SANs always included on the server certificate.
28+
///
29+
/// Covers the host aliases used by every supported runtime: Kubernetes service DNS,
2930
/// `host.docker.internal` for Docker Desktop and rootless Docker on Linux,
3031
/// and `host.containers.internal` for Podman containers reaching their host.
31-
const DEFAULT_SERVER_SANS: &[&str] = &[
32+
pub const DEFAULT_SERVER_SANS: &[&str] = &[
3233
"openshell",
3334
"openshell.openshell.svc",
3435
"openshell.openshell.svc.cluster.local",
@@ -184,4 +185,10 @@ mod tests {
184185
// Should have all default SANs + 2 extras
185186
assert_eq!(sans.len(), DEFAULT_SERVER_SANS.len() + 2);
186187
}
188+
189+
#[test]
190+
fn default_server_sans_include_local_container_hostnames() {
191+
assert!(DEFAULT_SERVER_SANS.contains(&"host.docker.internal"));
192+
assert!(DEFAULT_SERVER_SANS.contains(&"host.containers.internal"));
193+
}
187194
}

‎crates/openshell-driver-docker/src/lib.rs‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1869,10 +1869,27 @@ fn linux_supervisor_candidates(daemon_arch: &str) -> Vec<PathBuf> {
18691869
/// inside the digest-keyed directory and renamed into place, so concurrent
18701870
/// gateway starts don't observe a partial file.
18711871
async fn extract_supervisor_bin_from_image(docker: &Docker, image: &str) -> CoreResult<PathBuf> {
1872+
let refresh_attempted = if supervisor_image_should_refresh(image) {
1873+
info!(image = image, "Refreshing mutable docker supervisor image");
1874+
match pull_supervisor_image(docker, image).await {
1875+
Ok(()) => true,
1876+
Err(err) => {
1877+
warn!(
1878+
image = image,
1879+
error = %err,
1880+
"failed to refresh mutable docker supervisor image; falling back to local image if present",
1881+
);
1882+
true
1883+
}
1884+
}
1885+
} else {
1886+
false
1887+
};
1888+
18721889
// Inspect first to see if the image is already present; only pull on miss.
18731890
let inspect = match docker.inspect_image(image).await {
18741891
Ok(inspect) => inspect,
1875-
Err(err) if is_not_found_error(&err) => {
1892+
Err(err) if is_not_found_error(&err) && !refresh_attempted => {
18761893
info!(image = image, "Pulling docker supervisor image");
18771894
pull_supervisor_image(docker, image).await?;
18781895
docker.inspect_image(image).await.map_err(|err| {
@@ -1881,6 +1898,11 @@ async fn extract_supervisor_bin_from_image(docker: &Docker, image: &str) -> Core
18811898
))
18821899
})?
18831900
}
1901+
Err(err) if is_not_found_error(&err) => {
1902+
return Err(Error::config(format!(
1903+
"docker supervisor image '{image}' is not present locally after refresh attempt",
1904+
)));
1905+
}
18841906
Err(err) => {
18851907
return Err(Error::config(format!(
18861908
"failed to inspect docker supervisor image '{image}': {err}",
@@ -1926,6 +1948,23 @@ async fn extract_supervisor_bin_from_image(docker: &Docker, image: &str) -> Core
19261948
Ok(cache_path)
19271949
}
19281950

1951+
fn supervisor_image_should_refresh(image: &str) -> bool {
1952+
matches!(supervisor_image_tag(image), Some("dev" | "latest"))
1953+
}
1954+
1955+
fn supervisor_image_tag(image: &str) -> Option<&str> {
1956+
if image.contains('@') {
1957+
return None;
1958+
}
1959+
1960+
let image_name = image.rsplit('/').next().unwrap_or(image);
1961+
image_name
1962+
.rsplit_once(':')
1963+
.map_or(Some("latest"), |(_, tag)| {
1964+
if tag.is_empty() { None } else { Some(tag) }
1965+
})
1966+
}
1967+
19291968
async fn pull_supervisor_image(docker: &Docker, image: &str) -> CoreResult<()> {
19301969
let mut stream = docker.create_image(
19311970
Some(CreateImageOptions {

‎crates/openshell-driver-docker/src/tests.rs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,25 @@ fn docker_supervisor_image_tag_sanitizes_build_metadata_for_docker() {
903903
);
904904
}
905905

906+
#[test]
907+
fn docker_supervisor_image_refreshes_mutable_tags_only() {
908+
assert!(supervisor_image_should_refresh(
909+
"ghcr.io/nvidia/openshell/supervisor:dev"
910+
));
911+
assert!(supervisor_image_should_refresh(
912+
"ghcr.io/nvidia/openshell/supervisor:latest"
913+
));
914+
assert!(supervisor_image_should_refresh(
915+
"ghcr.io/nvidia/openshell/supervisor"
916+
));
917+
assert!(!supervisor_image_should_refresh(
918+
"ghcr.io/nvidia/openshell/supervisor:0.0.47-dev.13-g57b71c68f"
919+
));
920+
assert!(!supervisor_image_should_refresh(
921+
"ghcr.io/nvidia/openshell/supervisor@sha256:abc123"
922+
));
923+
}
924+
906925
#[test]
907926
fn supervisor_cache_path_namespaces_by_digest_under_openshell_data_dir() {
908927
let base = PathBuf::from("/var/cache/share");

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

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,16 @@ impl PodmanComputeDriver {
328328

329329
// 1a. Pull the supervisor image if needed. The supervisor binary
330330
// is shipped in a standalone OCI image and mounted into sandbox
331-
// containers via Podman's type=image mount. Using "missing"
332-
// policy so the image is only pulled once and then cached.
331+
// containers via Podman's type=image mount. Refresh mutable tags
332+
// like latest/dev, but avoid registry checks for pinned images.
333+
let supervisor_pull_policy = supervisor_image_pull_policy(&self.config.supervisor_image);
333334
info!(
334335
image = %self.config.supervisor_image,
335-
policy = "missing",
336+
policy = supervisor_pull_policy,
336337
"Ensuring supervisor image"
337338
);
338339
self.client
339-
.pull_image(&self.config.supervisor_image, "missing")
340+
.pull_image(&self.config.supervisor_image, supervisor_pull_policy)
340341
.await
341342
.map_err(ComputeDriverError::from)?;
342343

@@ -589,6 +590,31 @@ impl PodmanComputeDriver {
589590
}
590591
}
591592

593+
fn supervisor_image_pull_policy(image: &str) -> &'static str {
594+
if supervisor_image_should_refresh(image) {
595+
"newer"
596+
} else {
597+
"missing"
598+
}
599+
}
600+
601+
fn supervisor_image_should_refresh(image: &str) -> bool {
602+
matches!(supervisor_image_tag(image), Some("dev" | "latest"))
603+
}
604+
605+
fn supervisor_image_tag(image: &str) -> Option<&str> {
606+
if image.contains('@') {
607+
return None;
608+
}
609+
610+
let image_name = image.rsplit('/').next().unwrap_or(image);
611+
image_name
612+
.rsplit_once(':')
613+
.map_or(Some("latest"), |(_, tag)| {
614+
if tag.is_empty() { None } else { Some(tag) }
615+
})
616+
}
617+
592618
/// Check whether the current user has subuid/subgid ranges configured.
593619
///
594620
/// Rootless Podman requires entries in `/etc/subuid` and `/etc/subgid` for
@@ -719,6 +745,32 @@ mod tests {
719745
assert_eq!(cfg.grpc_endpoint, "https://gateway.internal:9000");
720746
}
721747

748+
#[test]
749+
fn supervisor_pull_policy_refreshes_mutable_tags_only() {
750+
assert_eq!(
751+
supervisor_image_pull_policy("ghcr.io/nvidia/openshell/supervisor:dev"),
752+
"newer"
753+
);
754+
assert_eq!(
755+
supervisor_image_pull_policy("ghcr.io/nvidia/openshell/supervisor:latest"),
756+
"newer"
757+
);
758+
assert_eq!(
759+
supervisor_image_pull_policy("ghcr.io/nvidia/openshell/supervisor"),
760+
"newer"
761+
);
762+
assert_eq!(
763+
supervisor_image_pull_policy(
764+
"ghcr.io/nvidia/openshell/supervisor:0.0.47-dev.13-g57b71c68f"
765+
),
766+
"missing"
767+
);
768+
assert_eq!(
769+
supervisor_image_pull_policy("ghcr.io/nvidia/openshell/supervisor@sha256:abc123"),
770+
"missing"
771+
);
772+
}
773+
722774
fn test_driver(socket_path: PathBuf) -> PodmanComputeDriver {
723775
let config = PodmanComputeConfig {
724776
socket_path,

0 commit comments

Comments
 (0)