From 503229f9146af9aea8b45d6243c1bac61657cfc0 Mon Sep 17 00:00:00 2001 From: mmckeen-nv Date: Thu, 30 Apr 2026 10:30:52 -0700 Subject: [PATCH] Repair OpenClaw exec approvals symlink --- app/api/sandbox/create/route.ts | 17 ++++++++++++++++ app/lib/sandboxMcpManifest.ts | 4 +++- app/lib/sandboxPrivilegedFiles.ts | 32 +++++++++++++++++++++++++++++++ tests/sandbox-lifecycle-check.mjs | 2 ++ 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/app/api/sandbox/create/route.ts b/app/api/sandbox/create/route.ts index c44b723..4323573 100644 --- a/app/api/sandbox/create/route.ts +++ b/app/api/sandbox/create/route.ts @@ -2,6 +2,7 @@ import { NextResponse } from "next/server" import { execFile, spawn } from "node:child_process" import { promisify } from "node:util" import { inspectSandbox } from "@/app/lib/openshellHost" +import { repairOpenClawExecApprovalsFile } from "@/app/lib/sandboxPrivilegedFiles" import { commandExists, HOST_PATH, @@ -437,6 +438,11 @@ export async function POST(request: Request) { error: "Sandbox readiness polling produced no verification result.", } const created = readiness.verified + const execApprovalsRepair = created ? await repairOpenClawExecApprovalsFile(sandboxName).catch((error) => ({ + sandboxName, + path: "/sandbox/.openclaw/exec-approvals.json", + error: error instanceof Error ? error.message : "Failed to repair OpenClaw exec approvals file", + })) : null const deviceApproval = created ? await approveOpenClawDeviceRequests(sandboxName) : null console.log( `[sandbox/create] request:complete sandbox=${sandboxName} created=${created} readinessAttempts=${readiness.attempts} deviceApproval=${deviceApproval?.approved ?? false} elapsedMs=${elapsedMs(requestStartedAt)}`, @@ -458,6 +464,7 @@ export async function POST(request: Request) { attempts: readiness.attempts, elapsedMs: readiness.elapsedMs, }, + execApprovalsRepair, deviceApproval, stdout: result.stdout, stderr: result.stderr, @@ -466,6 +473,8 @@ export async function POST(request: Request) { enableTailscale ? "NemoClaw blueprint workflow completed with Tailscale-enabled prerequisites. Existing healthy OpenShell gateways are reused before any new gateway start is attempted." : "NemoClaw blueprint workflow completed in local/default mode. Existing healthy OpenShell gateways are reused before any new gateway start is attempted.", + execApprovalsRepair && "note" in execApprovalsRepair ? execApprovalsRepair.note : false, + execApprovalsRepair && "error" in execApprovalsRepair ? `OpenClaw exec approvals repair failed: ${execApprovalsRepair.error}` : false, deviceApproval?.note, ) : "Blueprint command reported success, but the sandbox never reached a ready verification state afterward.", @@ -500,6 +509,11 @@ export async function POST(request: Request) { error: "Sandbox readiness polling produced no verification result.", } const created = readiness.verified + const execApprovalsRepair = created ? await repairOpenClawExecApprovalsFile(sandboxName).catch((error) => ({ + sandboxName, + path: "/sandbox/.openclaw/exec-approvals.json", + error: error instanceof Error ? error.message : "Failed to repair OpenClaw exec approvals file", + })) : null const deviceApproval = created ? await approveOpenClawDeviceRequests(sandboxName) : null const policyPrepared = Boolean(policy) console.log( @@ -526,6 +540,7 @@ export async function POST(request: Request) { attempts: readiness.attempts, elapsedMs: readiness.elapsedMs, }, + execApprovalsRepair, deviceApproval, policyPrepared, note: created @@ -535,6 +550,8 @@ export async function POST(request: Request) { : (policyPrepared ? "Custom sandbox created. Policy draft is prepared, but applying it live should be a follow-up action." : "Custom sandbox created."), + execApprovalsRepair && "note" in execApprovalsRepair ? execApprovalsRepair.note : false, + execApprovalsRepair && "error" in execApprovalsRepair ? `OpenClaw exec approvals repair failed: ${execApprovalsRepair.error}` : false, deviceApproval?.note, ) : "Create command started, but the sandbox never reached a ready verification state afterward.", diff --git a/app/lib/sandboxMcpManifest.ts b/app/lib/sandboxMcpManifest.ts index e934874..f835147 100644 --- a/app/lib/sandboxMcpManifest.ts +++ b/app/lib/sandboxMcpManifest.ts @@ -5,7 +5,7 @@ import { syncSandboxOpenClawMcpConfig, revokeSandboxOpenClawMcpConfig, } from "./sandboxOpenClawMcpConfig" -import { writeSandboxFilePrivileged } from "./sandboxPrivilegedFiles" +import { repairOpenClawExecApprovalsFile, writeSandboxFilePrivileged } from "./sandboxPrivilegedFiles" export const SANDBOX_MCP_MANIFEST_PATH = "/sandbox/openshell_control_mcp.md" @@ -88,6 +88,7 @@ export async function syncSandboxMcpManifest( options.brokerBaseUrl, handoff.token, ) + const execApprovals = await repairOpenClawExecApprovalsFile(sandboxName) return { path: uploaded.path, @@ -101,6 +102,7 @@ export async function syncSandboxMcpManifest( expiresAt: handoff.session.expiresAt, }, openClaw, + execApprovals, markdown: handoff.markdown, } } diff --git a/app/lib/sandboxPrivilegedFiles.ts b/app/lib/sandboxPrivilegedFiles.ts index 2b1fc85..e60b7a2 100644 --- a/app/lib/sandboxPrivilegedFiles.ts +++ b/app/lib/sandboxPrivilegedFiles.ts @@ -50,6 +50,38 @@ export async function writeSandboxFilePrivileged( } } +export async function repairOpenClawExecApprovalsFile(sandboxName: string) { + const normalizeScript = [ + `const fs = require("fs")`, + `const approval = "/sandbox/.openclaw/exec-approvals.json"`, + `const tmp = process.argv[1]`, + `let source = ""`, + `try { source = fs.readFileSync(approval, "utf8") } catch {}`, + `const trimmed = source.trim()`, + `let payload = "{}\\n"`, + `if (trimmed) { try { payload = JSON.stringify(JSON.parse(trimmed), null, 2) + "\\n" } catch {} }`, + `fs.writeFileSync(tmp, payload)`, + ].join("; ") + const script = [ + `mkdir -p /sandbox/.openclaw`, + `tmp="/sandbox/.openclaw/.exec-approvals.json.$$"`, + `node -e ${shellQuote(normalizeScript)} "$tmp"`, + `rm -f /sandbox/.openclaw/exec-approvals.json`, + `mv "$tmp" /sandbox/.openclaw/exec-approvals.json`, + `chown sandbox:sandbox /sandbox/.openclaw/exec-approvals.json 2>/dev/null || chown 998:998 /sandbox/.openclaw/exec-approvals.json`, + `chmod 0600 /sandbox/.openclaw/exec-approvals.json`, + ].join(" && ") + const result = await runDockerKubectl( + ["exec", "-n", OPENSHELL_NAMESPACE, sandboxName, "--", "sh", "-lc", script], + ) + if (result.code !== 0) throw new Error(result.stderr || "failed to repair OpenClaw exec approvals file") + return { + sandboxName, + path: "/sandbox/.openclaw/exec-approvals.json", + note: "Replaced OpenClaw exec approvals symlink with a real sandbox-owned file for newer OpenClaw versions.", + } +} + export async function stabilizeOpenClawGatewayConfig(sandboxName: string) { const patchConfig = [ `const fs = require("fs")`, diff --git a/tests/sandbox-lifecycle-check.mjs b/tests/sandbox-lifecycle-check.mjs index 2576a8a..ba05cd4 100644 --- a/tests/sandbox-lifecycle-check.mjs +++ b/tests/sandbox-lifecycle-check.mjs @@ -70,6 +70,8 @@ assert.match(versionedInstallerSource, /OPENCLAW_VERSION="\$\{OPENCLAW_VERSION:- assert.match(versionedInstallerSource, /docker build[\s\S]*Dockerfile\.base[\s\S]*--build-arg "OPENCLAW_VERSION=\$OPENCLAW_VERSION"[\s\S]*"\$source_dir"/, 'versioned installer must rebuild the stock NemoClaw base image with the pinned OpenClaw version') assert.doesNotMatch(createRouteSource, /repairOpenClawRuntimePolicy|runtimePolicyRepair/, 'sandbox create must not mutate OpenShell filesystem policy for OpenClaw') assert.doesNotMatch(createRouteSource, /stabilizeOpenClawGatewayConfig|gatewayConfigRepair|repairOpenClawWorkspacePermissions|workspaceRepair/, 'sandbox create must not patch OpenClaw internals after the Monday rollback') +assert.match(createRouteSource, /repairOpenClawExecApprovalsFile/, 'sandbox create may apply the narrow exec approvals symlink compatibility repair') +assert.match(createRouteSource, /execApprovalsRepair/, 'sandbox create response must report the narrow exec approvals compatibility repair') assert.doesNotMatch(sandboxPrivilegedFilesSource, /openshell-openclaw-policy-|"policy", "set"|withoutReadOnlyOpenClaw/, 'OpenClaw repair must not mutate OpenShell filesystem policy') assert.match(sandboxPrivilegedFilesSource, /plugins\.entries\.bonjour/, 'gateway config stabilization must disable the crashing Bonjour plugin') assert.match(sandboxPrivilegedFilesSource, /sha256sum openclaw\.json > \.config-hash/, 'gateway config stabilization must refresh OpenClaw config hash')