Repair OpenClaw exec approvals symlink
This commit is contained in:
@@ -2,6 +2,7 @@ import { NextResponse } from "next/server"
|
|||||||
import { execFile, spawn } from "node:child_process"
|
import { execFile, spawn } from "node:child_process"
|
||||||
import { promisify } from "node:util"
|
import { promisify } from "node:util"
|
||||||
import { inspectSandbox } from "@/app/lib/openshellHost"
|
import { inspectSandbox } from "@/app/lib/openshellHost"
|
||||||
|
import { repairOpenClawExecApprovalsFile } from "@/app/lib/sandboxPrivilegedFiles"
|
||||||
import {
|
import {
|
||||||
commandExists,
|
commandExists,
|
||||||
HOST_PATH,
|
HOST_PATH,
|
||||||
@@ -437,6 +438,11 @@ export async function POST(request: Request) {
|
|||||||
error: "Sandbox readiness polling produced no verification result.",
|
error: "Sandbox readiness polling produced no verification result.",
|
||||||
}
|
}
|
||||||
const created = readiness.verified
|
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 deviceApproval = created ? await approveOpenClawDeviceRequests(sandboxName) : null
|
||||||
console.log(
|
console.log(
|
||||||
`[sandbox/create] request:complete sandbox=${sandboxName} created=${created} readinessAttempts=${readiness.attempts} deviceApproval=${deviceApproval?.approved ?? false} elapsedMs=${elapsedMs(requestStartedAt)}`,
|
`[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,
|
attempts: readiness.attempts,
|
||||||
elapsedMs: readiness.elapsedMs,
|
elapsedMs: readiness.elapsedMs,
|
||||||
},
|
},
|
||||||
|
execApprovalsRepair,
|
||||||
deviceApproval,
|
deviceApproval,
|
||||||
stdout: result.stdout,
|
stdout: result.stdout,
|
||||||
stderr: result.stderr,
|
stderr: result.stderr,
|
||||||
@@ -466,6 +473,8 @@ export async function POST(request: Request) {
|
|||||||
enableTailscale
|
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 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.",
|
: "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,
|
deviceApproval?.note,
|
||||||
)
|
)
|
||||||
: "Blueprint command reported success, but the sandbox never reached a ready verification state afterward.",
|
: "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.",
|
error: "Sandbox readiness polling produced no verification result.",
|
||||||
}
|
}
|
||||||
const created = readiness.verified
|
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 deviceApproval = created ? await approveOpenClawDeviceRequests(sandboxName) : null
|
||||||
const policyPrepared = Boolean(policy)
|
const policyPrepared = Boolean(policy)
|
||||||
console.log(
|
console.log(
|
||||||
@@ -526,6 +540,7 @@ export async function POST(request: Request) {
|
|||||||
attempts: readiness.attempts,
|
attempts: readiness.attempts,
|
||||||
elapsedMs: readiness.elapsedMs,
|
elapsedMs: readiness.elapsedMs,
|
||||||
},
|
},
|
||||||
|
execApprovalsRepair,
|
||||||
deviceApproval,
|
deviceApproval,
|
||||||
policyPrepared,
|
policyPrepared,
|
||||||
note: created
|
note: created
|
||||||
@@ -535,6 +550,8 @@ export async function POST(request: Request) {
|
|||||||
: (policyPrepared
|
: (policyPrepared
|
||||||
? "Custom sandbox created. Policy draft is prepared, but applying it live should be a follow-up action."
|
? "Custom sandbox created. Policy draft is prepared, but applying it live should be a follow-up action."
|
||||||
: "Custom sandbox created."),
|
: "Custom sandbox created."),
|
||||||
|
execApprovalsRepair && "note" in execApprovalsRepair ? execApprovalsRepair.note : false,
|
||||||
|
execApprovalsRepair && "error" in execApprovalsRepair ? `OpenClaw exec approvals repair failed: ${execApprovalsRepair.error}` : false,
|
||||||
deviceApproval?.note,
|
deviceApproval?.note,
|
||||||
)
|
)
|
||||||
: "Create command started, but the sandbox never reached a ready verification state afterward.",
|
: "Create command started, but the sandbox never reached a ready verification state afterward.",
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
syncSandboxOpenClawMcpConfig,
|
syncSandboxOpenClawMcpConfig,
|
||||||
revokeSandboxOpenClawMcpConfig,
|
revokeSandboxOpenClawMcpConfig,
|
||||||
} from "./sandboxOpenClawMcpConfig"
|
} from "./sandboxOpenClawMcpConfig"
|
||||||
import { writeSandboxFilePrivileged } from "./sandboxPrivilegedFiles"
|
import { repairOpenClawExecApprovalsFile, writeSandboxFilePrivileged } from "./sandboxPrivilegedFiles"
|
||||||
|
|
||||||
export const SANDBOX_MCP_MANIFEST_PATH = "/sandbox/openshell_control_mcp.md"
|
export const SANDBOX_MCP_MANIFEST_PATH = "/sandbox/openshell_control_mcp.md"
|
||||||
|
|
||||||
@@ -88,6 +88,7 @@ export async function syncSandboxMcpManifest(
|
|||||||
options.brokerBaseUrl,
|
options.brokerBaseUrl,
|
||||||
handoff.token,
|
handoff.token,
|
||||||
)
|
)
|
||||||
|
const execApprovals = await repairOpenClawExecApprovalsFile(sandboxName)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
path: uploaded.path,
|
path: uploaded.path,
|
||||||
@@ -101,6 +102,7 @@ export async function syncSandboxMcpManifest(
|
|||||||
expiresAt: handoff.session.expiresAt,
|
expiresAt: handoff.session.expiresAt,
|
||||||
},
|
},
|
||||||
openClaw,
|
openClaw,
|
||||||
|
execApprovals,
|
||||||
markdown: handoff.markdown,
|
markdown: handoff.markdown,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
export async function stabilizeOpenClawGatewayConfig(sandboxName: string) {
|
||||||
const patchConfig = [
|
const patchConfig = [
|
||||||
`const fs = require("fs")`,
|
`const fs = require("fs")`,
|
||||||
|
|||||||
@@ -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.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, /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.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.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, /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')
|
assert.match(sandboxPrivilegedFilesSource, /sha256sum openclaw\.json > \.config-hash/, 'gateway config stabilization must refresh OpenClaw config hash')
|
||||||
|
|||||||
Reference in New Issue
Block a user