From c156d3805fce194cbc0c5186615325daa67a9e89 Mon Sep 17 00:00:00 2001 From: Florent Benoit Date: Tue, 5 May 2026 20:58:17 +0200 Subject: [PATCH] fix(vm): correct /sandbox ownership when rootfs is built by non-root host When the VM driver extracts OCI image layers on a non-root host (e.g. macOS UID 501), fs::copy and tar::unpack create files owned by the host user. The sandbox user inside the VM then cannot write to its own home directory. Add a conditional chown in the VM init script that detects the mismatch and fixes ownership before the supervisor starts. The check is skipped when ownership is already correct (e.g. Linux-as-root extraction). Signed-off-by: Florent Benoit --- .../scripts/openshell-vm-sandbox-init.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/openshell-driver-vm/scripts/openshell-vm-sandbox-init.sh b/crates/openshell-driver-vm/scripts/openshell-vm-sandbox-init.sh index b61fd4900..25365a312 100644 --- a/crates/openshell-driver-vm/scripts/openshell-vm-sandbox-init.sh +++ b/crates/openshell-driver-vm/scripts/openshell-vm-sandbox-init.sh @@ -395,6 +395,20 @@ fi export HOME=/sandbox export USER=sandbox +# Fix /sandbox ownership. The host-side CLI extracts OCI layers as a non-root +# user (e.g. UID 501 on macOS), so /sandbox may be owned by the host UID. +if [ -d /sandbox ]; then + _sb_uid=$(id -u sandbox 2>/dev/null || true) + _sb_gid=$(id -g sandbox 2>/dev/null || true) + if [ -n "$_sb_uid" ] && [ -n "$_sb_gid" ]; then + _cur_uid=$(stat -c '%u' /sandbox 2>/dev/null || true) + if [ -n "$_cur_uid" ] && [ "$_cur_uid" != "$_sb_uid" ]; then + ts "fixing /sandbox ownership (was uid=${_cur_uid}, setting to sandbox=${_sb_uid}:${_sb_gid})" + chown -R "${_sb_uid}:${_sb_gid}" /sandbox + fi + fi +fi + rewrite_openshell_endpoint_if_needed # Log supervisor connectivity state for debugging stuck-in-Provisioning issues