Harden MCP broker sandbox handoff

This commit is contained in:
Codex
2026-04-27 21:33:05 +00:00
parent fdb18300eb
commit fd0959d994
18 changed files with 634 additions and 101 deletions
+2 -2
View File
@@ -361,10 +361,10 @@ export default function McpConfigurationPanel({ sandboxes = [] }: McpConfigurati
</div>
</div>
<div className="mt-4 grid grid-cols-1 gap-3 md:grid-cols-2">
{pagedRegistryResults.map((entry) => {
{pagedRegistryResults.map((entry, index) => {
const installed = installedIds.has(entry.id)
return (
<div key={`${entry.id}-${entry.command}`} className="metric flex min-h-44 flex-col p-4">
<div key={`${entry.id}-${entry.command}-${entry.args.join("|")}-${index}`} className="metric flex min-h-44 flex-col p-4">
<div className="flex items-start justify-between gap-3">
<div className="min-w-0">
<h3 className="truncate text-sm font-semibold text-[var(--foreground)]">{entry.name}</h3>
+45 -13
View File
@@ -47,6 +47,8 @@ export default function SandboxFilesPanel({
showHeader?: boolean
}) {
const [selectedFile, setSelectedFile] = useState<File | null>(null)
const [selectedDirectoryFiles, setSelectedDirectoryFiles] = useState<File[]>([])
const [uploadMode, setUploadMode] = useState<"file" | "directory">("file")
const [uploadPath, setUploadPath] = useState("/sandbox/")
const [downloadPath, setDownloadPath] = useState("/sandbox/")
const [busy, setBusy] = useState<"upload" | "download" | null>(null)
@@ -59,6 +61,7 @@ export default function SandboxFilesPanel({
if (!selectedFile) return uploadPath
return uploadPath.endsWith("/") ? `${uploadPath}${selectedFile.name}` : uploadPath
}, [selectedFile, uploadPath])
const uploadCount = uploadMode === "directory" ? selectedDirectoryFiles.length : selectedFile ? 1 : 0
const sortedEntries = useMemo(() => {
return [...(listing?.entries || [])].sort((left, right) => {
@@ -99,21 +102,32 @@ export default function SandboxFilesPanel({
}, [sandbox.id])
async function uploadFile() {
if (!selectedFile || busy) return
if (uploadCount === 0 || busy) return
try {
setBusy("upload")
setMessage("")
const form = new FormData()
form.set("file", selectedFile)
form.set("path", uploadPath)
if (uploadMode === "directory") {
form.set("relativePaths", JSON.stringify(selectedDirectoryFiles.map((file) => file.webkitRelativePath || file.name)))
for (const file of selectedDirectoryFiles) {
form.append("files", file, file.name)
}
} else if (selectedFile) {
form.set("file", selectedFile)
}
const response = await fetch(`/api/sandbox/${encodeURIComponent(sandbox.id)}/files/upload`, {
method: "POST",
body: form,
})
const data = await response.json()
if (!response.ok) throw new Error(data.error || "Failed to upload file")
setMessage(data.note || `Uploaded to ${data.uploaded?.path || suggestedUploadPath}.`)
setDownloadPath(data.uploaded?.path || suggestedUploadPath)
setMessage(data.note || "Upload complete.")
if (uploadMode === "directory") {
setDownloadPath(uploadPath)
} else {
setDownloadPath(data.uploaded?.path || suggestedUploadPath)
}
await loadFileList(listPath)
} catch (error) {
setMessage(error instanceof Error ? error.message : "Failed to upload file")
@@ -188,7 +202,22 @@ export default function SandboxFilesPanel({
</div>
<input
type="file"
onChange={(event) => setSelectedFile(event.target.files?.[0] || null)}
onChange={(event) => {
setUploadMode("file")
setSelectedFile(event.target.files?.[0] || null)
setSelectedDirectoryFiles([])
}}
className="block w-full text-xs text-[var(--foreground-dim)] file:mr-3 file:rounded-sm file:border file:border-[var(--border-subtle)] file:bg-[var(--background)] file:px-3 file:py-2 file:text-xs file:font-mono file:uppercase file:text-[var(--foreground)]"
/>
<input
type="file"
multiple
{...({ webkitdirectory: "", directory: "" } as Record<string, string>)}
onChange={(event) => {
setUploadMode("directory")
setSelectedDirectoryFiles(Array.from(event.target.files || []))
setSelectedFile(null)
}}
className="block w-full text-xs text-[var(--foreground-dim)] file:mr-3 file:rounded-sm file:border file:border-[var(--border-subtle)] file:bg-[var(--background)] file:px-3 file:py-2 file:text-xs file:font-mono file:uppercase file:text-[var(--foreground)]"
/>
<div className="space-y-2">
@@ -202,20 +231,25 @@ export default function SandboxFilesPanel({
{selectedFile && (
<p className="text-[11px] font-mono text-[var(--foreground-dim)]">Target: {suggestedUploadPath}</p>
)}
{uploadMode === "directory" && selectedDirectoryFiles.length > 0 && (
<p className="text-[11px] font-mono text-[var(--foreground-dim)]">
Directory upload: {selectedDirectoryFiles.length} file{selectedDirectoryFiles.length === 1 ? "" : "s"} into {uploadPath}
</p>
)}
</div>
<button
onClick={uploadFile}
disabled={!selectedFile || busy !== null}
disabled={uploadCount === 0 || busy !== null}
className="rounded-sm bg-[var(--nvidia-green)] px-4 py-2 text-xs font-mono uppercase tracking-wider text-black disabled:opacity-50"
>
{busy === "upload" ? "Uploading..." : "Upload File"}
{busy === "upload" ? "Uploading..." : uploadMode === "directory" ? "Upload Directory" : "Upload File"}
</button>
</section>
<section className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4 space-y-4">
<div>
<h5 className="text-xs font-semibold uppercase tracking-wider text-[var(--foreground)]">Download</h5>
<p className="mt-1 text-xs text-[var(--foreground-dim)]">Browse sandbox files or enter a regular file path under /sandbox or /tmp.</p>
<p className="mt-1 text-xs text-[var(--foreground-dim)]">Browse sandbox files or enter a file or directory path under /sandbox or /tmp.</p>
</div>
<div className="grid grid-cols-1 gap-2 md:grid-cols-[1fr_auto_auto]">
<input
@@ -282,11 +316,9 @@ export default function SandboxFilesPanel({
type="button"
onClick={() => {
setDownloadPath(entry.path)
if (entry.type !== "directory") {
downloadFile(entry.path)
}
downloadFile(entry.path)
}}
disabled={entry.type === "directory" || busy !== null}
disabled={(entry.type !== "file" && entry.type !== "directory") || busy !== null}
className="action-button px-2 py-1 text-right disabled:opacity-30"
>
Get
@@ -315,7 +347,7 @@ export default function SandboxFilesPanel({
disabled={!downloadPath.trim() || busy !== null}
className="action-button px-4 py-2"
>
{busy === "download" ? "Downloading..." : "Download File"}
{busy === "download" ? "Downloading..." : "Download Path"}
</button>
</section>
</div>
+115 -58
View File
@@ -274,20 +274,25 @@ export default function SandboxList({
}
}
const syncMcpManifest = async (sandbox: SandboxInventoryItem) => {
const syncMcpManifest = async (sandbox: SandboxInventoryItem, action: 'sync' | 'revoke' = 'sync') => {
try {
setMcpSyncing(true)
setMcpMessage(`Issuing MCP broker config for ${sandbox.name}...`)
setMcpMessage(action === 'revoke' ? `Revoking MCP broker config for ${sandbox.name}...` : `Issuing MCP broker config for ${sandbox.name}...`)
const response = await fetch(`/api/sandbox/${encodeURIComponent(sandbox.id)}/mcp`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ sandboxName: sandbox.name }),
body: JSON.stringify({ sandboxName: sandbox.name, action }),
})
const data = await response.json()
if (!response.ok) throw new Error(data.error || 'Failed to issue MCP broker config')
setMcpMessage(data.note || 'MCP broker config issued.')
if (!response.ok) throw new Error(data.error || 'Failed to update MCP broker config')
const networkNote = data.network?.approved?.length
? ` Approved ${data.network.approved.length} broker network rule${data.network.approved.length === 1 ? '' : 's'}.`
: data.network?.rejected?.length
? ` Removed ${data.network.rejected.length} broker network rule${data.network.rejected.length === 1 ? '' : 's'}.`
: ''
setMcpMessage(`${data.note || 'MCP broker config updated.'}${networkNote}`)
} catch (error) {
setMcpMessage(error instanceof Error ? error.message : 'Failed to issue MCP broker config')
setMcpMessage(error instanceof Error ? error.message : 'Failed to update MCP broker config')
} finally {
setMcpSyncing(false)
}
@@ -304,6 +309,7 @@ export default function SandboxList({
}
const revokeMcpForSandbox = (sandbox: SandboxInventoryItem, server: McpServerAccess) => {
const hasOtherMcpAccess = mcpServers.some((candidate) => candidate.id !== server.id && sandboxCanAccessMcpServer(sandbox, candidate))
const current = new Set(server.allowedSandboxIds)
current.delete(sandbox.id)
current.delete(sandbox.name)
@@ -315,7 +321,7 @@ export default function SandboxList({
return updateMcpServerAccess(server, {
accessMode: 'allow_only',
allowedSandboxIds: Array.from(current),
}, `${server.name} revoked from ${sandbox.name}.`).then(() => syncMcpManifest(sandbox))
}, `${server.name} revoked from ${sandbox.name}.`).then(() => syncMcpManifest(sandbox, hasOtherMcpAccess ? 'sync' : 'revoke'))
}
const resolvePermissionRequest = async (sandbox: SandboxInventoryItem, action: 'approve' | 'reject', chunkId: string) => {
@@ -613,10 +619,10 @@ export default function SandboxList({
<button
type="button"
disabled={mcpSyncing}
onClick={() => syncMcpManifest(selectedSandbox)}
onClick={() => syncMcpManifest(selectedSandbox, allowedMcpServersForSandbox(selectedSandbox).length > 0 ? 'sync' : 'revoke')}
className="action-button px-3 py-2 max-sm:w-full"
>
{mcpSyncing ? 'Issuing...' : 'Issue Broker Config'}
{mcpSyncing ? 'Updating...' : 'Sync Broker Config'}
</button>
</div>
{mcpMessage && (
@@ -699,58 +705,109 @@ export default function SandboxList({
Refresh Requests
</button>
</div>
{(() => {
const feed = permissionFeeds[selectedSandbox.id]
const pending = feed?.pending || []
if (pending.length === 0) {
return (
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4 text-xs text-[var(--foreground-dim)]">
No pending network permission requests for this sandbox.
</div>
)
}
{(() => {
const feed = permissionFeeds[selectedSandbox.id]
const pending = feed?.pending || []
const recent = feed?.recent || []
const recentRules = recent.filter((request) => !pending.some((pendingRequest) => pendingRequest.chunkId === request.chunkId))
const renderRecentRules = () => recentRules.length > 0 && (
<div className="space-y-3">
<h4 className="text-[10px] font-semibold uppercase tracking-wider text-[var(--foreground-dim)]">Recent Network Rules</h4>
<div className="max-h-[26rem] space-y-3 overflow-y-auto pr-1">
{recentRules.map((request) => {
const approved = /approved/i.test(request.status)
const rejected = /rejected/i.test(request.status)
return (
<div key={`${request.status}-${request.chunkId}`} className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4">
<div className="flex items-start justify-between gap-4 max-md:flex-col">
<div className="min-w-0 space-y-2">
<div className="flex flex-wrap items-center gap-2">
<span className="break-all text-xs font-mono font-semibold text-[var(--foreground)]">
{request.endpoints.join(', ') || request.rule}
</span>
<span className={`status-chip px-2 py-1 ${approved ? 'bg-[var(--status-running-bg)] text-[var(--status-running)]' : rejected ? 'bg-[var(--status-stopped)] text-white' : 'bg-[var(--status-pending-bg)] text-[var(--status-pending)]'}`}>
{request.status || 'unknown'}
</span>
</div>
<p className="text-xs text-[var(--foreground-dim)]">{request.rationale || 'Sandbox network rule.'}</p>
<p className="text-[10px] font-mono text-[var(--foreground-dim)]">
{request.binary || request.binaries.join(', ') || 'unknown binary'} / {request.chunkId}
</p>
</div>
{(approved || rejected) && (
<button
type="button"
disabled={grantingSandboxId === selectedSandbox.id}
onClick={() => resolvePermissionRequest(selectedSandbox, approved ? 'reject' : 'approve', request.chunkId)}
className={`${rejected ? 'rounded-sm border border-[var(--nvidia-green)] bg-[var(--nvidia-green)] text-black' : 'rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] text-[var(--foreground)]'} px-3 py-2 text-xs font-mono uppercase tracking-wider disabled:opacity-50 max-md:w-full`}
>
{approved ? 'Revoke' : 'Approve'}
</button>
)}
</div>
</div>
)
})}
</div>
</div>
)
if (pending.length === 0) {
return (
<>
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4 text-xs text-[var(--foreground-dim)]">
No pending network permission requests for this sandbox.
</div>
{renderRecentRules()}
</>
)
}
return pending.map((request) => (
<div key={request.chunkId} className="rounded-sm border border-amber-400/60 bg-amber-400/10 p-4">
<div className="flex items-start justify-between gap-4 max-md:flex-col">
<div className="min-w-0 space-y-2">
<div className="flex items-center gap-2 flex-wrap">
<span className="text-xs font-mono font-semibold text-[var(--foreground)]">
{request.endpoints.join(', ') || request.rule}
</span>
{request.confidence ? (
<span className="rounded-sm border border-[var(--border-subtle)] px-1.5 py-0.5 text-[10px] text-[var(--foreground-dim)]">
{request.confidence}
</span>
) : null}
return (
<div className="space-y-3">
{pending.map((request) => (
<div key={request.chunkId} className="rounded-sm border border-amber-400/60 bg-amber-400/10 p-4">
<div className="flex items-start justify-between gap-4 max-md:flex-col">
<div className="min-w-0 space-y-2">
<div className="flex items-center gap-2 flex-wrap">
<span className="text-xs font-mono font-semibold text-[var(--foreground)]">
{request.endpoints.join(', ') || request.rule}
</span>
{request.confidence ? (
<span className="rounded-sm border border-[var(--border-subtle)] px-1.5 py-0.5 text-[10px] text-[var(--foreground-dim)]">
{request.confidence}
</span>
) : null}
</div>
<p className="text-xs text-[var(--foreground-dim)]">{request.rationale || 'Sandbox requested a network policy rule.'}</p>
<p className="text-[10px] font-mono text-[var(--foreground-dim)]">
{request.binary || request.binaries.join(', ') || 'unknown binary'} / {request.chunkId}
</p>
</div>
<div className="flex shrink-0 items-center gap-2 max-md:w-full max-md:[&>button]:flex-1">
<button
type="button"
disabled={grantingSandboxId === selectedSandbox.id}
onClick={() => resolvePermissionRequest(selectedSandbox, 'approve', request.chunkId)}
className="rounded-sm border border-[var(--nvidia-green)] bg-[var(--nvidia-green)] px-3 py-2 text-xs font-mono uppercase tracking-wider text-black disabled:opacity-50"
>
Grant
</button>
<button
type="button"
disabled={grantingSandboxId === selectedSandbox.id}
onClick={() => resolvePermissionRequest(selectedSandbox, 'reject', request.chunkId)}
className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-3 py-2 text-xs font-mono uppercase tracking-wider text-[var(--foreground)] disabled:opacity-50"
>
Reject
</button>
</div>
</div>
<p className="text-xs text-[var(--foreground-dim)]">{request.rationale || 'Sandbox requested a network policy rule.'}</p>
<p className="text-[10px] font-mono text-[var(--foreground-dim)]">
{request.binary || request.binaries.join(', ') || 'unknown binary'} / {request.chunkId}
</p>
</div>
<div className="flex shrink-0 items-center gap-2 max-md:w-full max-md:[&>button]:flex-1">
<button
type="button"
disabled={grantingSandboxId === selectedSandbox.id}
onClick={() => resolvePermissionRequest(selectedSandbox, 'approve', request.chunkId)}
className="rounded-sm border border-[var(--nvidia-green)] bg-[var(--nvidia-green)] px-3 py-2 text-xs font-mono uppercase tracking-wider text-black disabled:opacity-50"
>
Grant
</button>
<button
type="button"
disabled={grantingSandboxId === selectedSandbox.id}
onClick={() => resolvePermissionRequest(selectedSandbox, 'reject', request.chunkId)}
className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-3 py-2 text-xs font-mono uppercase tracking-wider text-[var(--foreground)] disabled:opacity-50"
>
Reject
</button>
</div>
</div>
</div>
))
})()}
))}
{renderRecentRules()}
</div>
)
})()}
<ConfigurationPanel sandboxId={selectedSandbox.id} mode="existing" embedded showHeader={false} />
</div>
</DrawerSection>