Skip to content

Commit 889e878

Browse files
committed
fix(vm): repair gateway vm startup
1 parent c13c1cd commit 889e878

7 files changed

Lines changed: 86 additions & 39 deletions

File tree

‎.markdownlint-cli2.jsonc‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
{
22
"globs": [
3-
"**/*.md",
4-
"**/*.mdx"
3+
"*.md",
4+
"architecture/**/*.md",
5+
"crates/**/*.md",
6+
"deploy/**/*.md",
7+
"docs/**/*.md",
8+
"docs/**/*.mdx",
9+
"e2e/**/*.md",
10+
"examples/**/*.md",
11+
"rfc/**/*.md"
512
],
6-
"gitignore": true,
13+
"gitignore": false,
714
"ignores": [
815
".agents/**",
916
".claude/**",
1017
".opencode/**",
1118
".github/**",
19+
"**/node_modules/**",
20+
"target/**",
21+
".pytest_cache/**",
1222
"THIRD-PARTY-NOTICES/**",
1323
"CLAUDE.md",
1424
// Man page sources use pandoc markdown with multiple H1 sections

‎crates/openshell-server/src/compute/vm.rs‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,15 @@ fn prepare_vm_state_dir(state_dir: &Path, expected_uid: u32) -> Result<()> {
280280
})?;
281281
let metadata = checked_directory_metadata(state_dir, expected_uid, "vm driver state dir")?;
282282
let mode = metadata.permissions().mode() & 0o777;
283-
if mode & 0o022 != 0 {
284-
return Err(Error::execution(format!(
285-
"vm driver state dir '{}' must not be group/world-writable (mode {mode:03o})",
286-
state_dir.display()
287-
)));
283+
if mode != 0o700 {
284+
std::fs::set_permissions(state_dir, std::fs::Permissions::from_mode(0o700)).map_err(
285+
|err| {
286+
Error::execution(format!(
287+
"failed to restrict vm driver state dir '{}': {err}",
288+
state_dir.display()
289+
))
290+
},
291+
)?;
288292
}
289293
Ok(())
290294
}
@@ -720,7 +724,7 @@ mod tests {
720724
}
721725

722726
#[test]
723-
fn prepare_compute_driver_socket_path_rejects_writable_state_dir() {
727+
fn prepare_compute_driver_socket_path_restricts_existing_state_dir() {
724728
let dir = tempdir().unwrap();
725729
let vm_config = VmComputeConfig {
726730
state_dir: dir.path().join("state"),
@@ -731,10 +735,14 @@ mod tests {
731735
.unwrap();
732736
let socket_path = compute_driver_socket_path(&vm_config);
733737

734-
let err = prepare_compute_driver_socket_path(&vm_config, &socket_path)
735-
.expect_err("world-writable state dir should be rejected")
736-
.to_string();
737-
assert!(err.contains("must not be group/world-writable"));
738+
prepare_compute_driver_socket_path(&vm_config, &socket_path).unwrap();
739+
740+
let mode = std::fs::metadata(vm_config.state_dir)
741+
.unwrap()
742+
.permissions()
743+
.mode()
744+
& 0o777;
745+
assert_eq!(mode, 0o700);
738746
}
739747

740748
#[test]

‎tasks/scripts/gateway-vm.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ fi
307307

308308
mkdir -p "${STATE_DIR}"
309309
mkdir -p "${VM_DRIVER_STATE_DIR}"
310+
chmod 700 "${VM_DRIVER_STATE_DIR}"
310311
CONFIG_PATH="${STATE_DIR}/gateway.toml"
311312
cat >"${CONFIG_PATH}" <<EOF
312313
[openshell]

‎tasks/scripts/vm/_lib.sh‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,50 @@ detect_platform() {
3030
esac
3131
}
3232

33+
# ── Runtime dependency downloads ────────────────────────────────────────
34+
35+
# Download a Linux guest umoci binary for the requested architecture.
36+
# Usage: download_umoci_binary <output> <version> <guest_arch>
37+
download_umoci_binary() {
38+
local output="$1"
39+
local version="$2"
40+
local guest_arch="$3"
41+
local suffix
42+
43+
case "$guest_arch" in
44+
arm64|aarch64) suffix="arm64" ;;
45+
amd64|x86_64) suffix="amd64" ;;
46+
*)
47+
echo "Error: Unsupported guest architecture for umoci: ${guest_arch}" >&2
48+
return 1
49+
;;
50+
esac
51+
52+
local base_url="https://github.com/opencontainers/umoci/releases/download/${version}"
53+
local candidates=("umoci.linux.${suffix}" "umoci.${suffix}")
54+
local error_log last_error asset
55+
error_log="$(mktemp)"
56+
last_error=""
57+
58+
echo " Downloading umoci ${version} for linux/${suffix}..."
59+
for asset in "${candidates[@]}"; do
60+
if curl -fsSL -o "$output" "${base_url}/${asset}" 2>"$error_log"; then
61+
chmod +x "$output"
62+
rm -f "$error_log"
63+
return 0
64+
fi
65+
last_error="$(cat "$error_log")"
66+
rm -f "$output"
67+
done
68+
69+
rm -f "$error_log"
70+
echo "Error: failed to download umoci ${version} for linux/${suffix}" >&2
71+
if [ -n "$last_error" ]; then
72+
echo "$last_error" >&2
73+
fi
74+
return 1
75+
}
76+
3377
# ── Compression helpers ─────────────────────────────────────────────────
3478

3579
# Compress a single file with zstd level 19, reporting sizes.

‎tasks/scripts/vm/compress-vm-runtime.sh‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,7 @@ mkdir -p "$OUTPUT_DIR"
6161
download_umoci_for_guest() {
6262
local output="$1"
6363
local guest_arch="$2"
64-
local suffix
65-
66-
case "$guest_arch" in
67-
arm64|aarch64) suffix="arm64" ;;
68-
amd64|x86_64) suffix="amd64" ;;
69-
*)
70-
echo "Error: Unsupported guest architecture for umoci: ${guest_arch}" >&2
71-
exit 1
72-
;;
73-
esac
74-
75-
echo " Downloading umoci ${UMOCI_VERSION} for ${suffix}..."
76-
curl -fsSL -o "$output" \
77-
"https://github.com/opencontainers/umoci/releases/download/${UMOCI_VERSION}/umoci.${suffix}"
78-
chmod +x "$output"
64+
download_umoci_binary "$output" "${UMOCI_VERSION}" "$guest_arch"
7965
}
8066

8167
# ── Fast path: compressed artifacts already present (e.g. from vm:setup) ──

‎tasks/scripts/vm/download-kernel-runtime.sh‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,17 @@ mkdir -p "$EXTRACT_DIR"
112112
zstd -d "${DOWNLOAD_DIR}/${TARBALL_NAME}" --stdout | tar -xf - -C "$EXTRACT_DIR"
113113

114114
if [ ! -f "${EXTRACT_DIR}/umoci" ]; then
115+
UMOCI_GUEST_ARCH=""
115116
case "$PLATFORM" in
116-
linux-aarch64|darwin-aarch64) UMOCI_SUFFIX="arm64" ;;
117-
linux-x86_64) UMOCI_SUFFIX="amd64" ;;
117+
linux-aarch64|darwin-aarch64) UMOCI_GUEST_ARCH="arm64" ;;
118+
linux-x86_64) UMOCI_GUEST_ARCH="amd64" ;;
118119
*)
119120
echo "Error: Unsupported platform for umoci guest binary: ${PLATFORM}" >&2
120121
exit 1
121122
;;
122123
esac
123-
echo " Runtime tarball has no umoci; downloading ${UMOCI_VERSION} for ${UMOCI_SUFFIX}"
124-
curl -fsSL -o "${EXTRACT_DIR}/umoci" \
125-
"https://github.com/opencontainers/umoci/releases/download/${UMOCI_VERSION}/umoci.${UMOCI_SUFFIX}"
126-
chmod +x "${EXTRACT_DIR}/umoci"
124+
echo " Runtime tarball has no umoci"
125+
download_umoci_binary "${EXTRACT_DIR}/umoci" "${UMOCI_VERSION}" "${UMOCI_GUEST_ARCH}"
127126
fi
128127

129128
echo " Extracted files:"

‎tasks/scripts/vm/package-vm-runtime.sh‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,13 @@ chmod +x "${PACKAGE_DIR}/gvproxy"
122122
# ── Download umoci for the Linux guest ───────────────────────────────────
123123

124124
echo "==> Downloading umoci ${UMOCI_VERSION} for ${PLATFORM} guest..."
125+
UMOCI_GUEST_ARCH=""
125126
case "$PLATFORM" in
126-
linux-aarch64|darwin-aarch64) UMOCI_SUFFIX="arm64" ;;
127-
linux-x86_64) UMOCI_SUFFIX="amd64" ;;
127+
linux-aarch64|darwin-aarch64) UMOCI_GUEST_ARCH="arm64" ;;
128+
linux-x86_64) UMOCI_GUEST_ARCH="amd64" ;;
128129
esac
129130

130-
curl -fsSL -o "${PACKAGE_DIR}/umoci" \
131-
"https://github.com/opencontainers/umoci/releases/download/${UMOCI_VERSION}/umoci.${UMOCI_SUFFIX}"
132-
chmod +x "${PACKAGE_DIR}/umoci"
131+
download_umoci_binary "${PACKAGE_DIR}/umoci" "${UMOCI_VERSION}" "${UMOCI_GUEST_ARCH}"
133132

134133
# ── Write provenance metadata ───────────────────────────────────────────
135134

0 commit comments

Comments
 (0)