From 22998e6da7803e37bdc780338aaa0475b052106a Mon Sep 17 00:00:00 2001 From: Mark McKeen Date: Sun, 29 Mar 2026 08:47:20 -0600 Subject: [PATCH] feat: add preset picker for new and existing sandboxes - add security preset selector to policy editor - surface canned exec allowlists per preset - add danger warnings for Spicy and Ultra-Lobster - reuse preset-driven policy editor in create sandbox flow --- app/components/ConfigurationPanel.tsx | 121 +++++++++++++++++--------- app/page.tsx | 19 ++-- 2 files changed, 90 insertions(+), 50 deletions(-) diff --git a/app/components/ConfigurationPanel.tsx b/app/components/ConfigurationPanel.tsx index 31c8e1b..52a3e63 100644 --- a/app/components/ConfigurationPanel.tsx +++ b/app/components/ConfigurationPanel.tsx @@ -1,5 +1,6 @@ "use client" import { useEffect, useMemo, useState } from "react" +import { SECURITY_PRESETS, getSecurityPreset, type OpenShellPolicyShape, type SecurityPresetId } from "../lib/securityPresets" type LandlockCompatibility = "best_effort" | "hard_requirement" type EndpointProtocol = "" | "rest" @@ -33,37 +34,11 @@ interface NetworkPolicyBlock { binaries: NetworkBinary[] } -interface OpenShellPolicy { - version: number - filesystem_policy: { - include_workdir: boolean - read_only: string[] - read_write: string[] - } - landlock: { - compatibility: LandlockCompatibility - } - process: { - run_as_user: string - run_as_group: string - } - network_policies: Record - }> - binaries: Array<{ path: string }> - }> -} +type OpenShellPolicy = OpenShellPolicyShape interface ConfigurationPanelProps { sandboxId: string + mode?: 'existing' | 'create' } function FieldHelp({ text }: { text: string }) { @@ -77,10 +52,12 @@ function FieldHelp({ text }: { text: string }) { ) } -function Badge({ children, tone }: { children: React.ReactNode; tone: "dynamic" | "static" }) { +function Badge({ children, tone }: { children: React.ReactNode; tone: "dynamic" | "static" | "danger" }) { const cls = tone === "dynamic" ? "bg-[rgba(118,185,0,0.12)] text-[var(--nvidia-green)] border-[rgba(118,185,0,0.35)]" - : "bg-[rgba(245,158,11,0.10)] text-amber-400 border-[rgba(245,158,11,0.35)]" + : tone === "danger" + ? "bg-[rgba(220,38,38,0.12)] text-red-400 border-[rgba(220,38,38,0.35)]" + : "bg-[rgba(245,158,11,0.10)] text-amber-400 border-[rgba(245,158,11,0.35)]" return {children} } @@ -184,14 +161,19 @@ function blocksToPolicy(blocks: NetworkPolicyBlock[]): OpenShellPolicy["network_ return out } -export default function ConfigurationPanel({ sandboxId }: ConfigurationPanelProps) { +export default function ConfigurationPanel({ sandboxId, mode = 'existing' }: ConfigurationPanelProps) { const [policy, setPolicy] = useState(defaultPolicy) const [blocks, setBlocks] = useState([]) - const [loading, setLoading] = useState(true) + const [loading, setLoading] = useState(mode === 'existing') const [saving, setSaving] = useState(false) const [message, setMessage] = useState("") + const [selectedPreset, setSelectedPreset] = useState('') useEffect(() => { + if (mode === 'create') { + setLoading(false) + return + } let active = true ;(async () => { try { @@ -211,9 +193,20 @@ export default function ConfigurationPanel({ sandboxId }: ConfigurationPanelProp } })() return () => { active = false } - }, [sandboxId]) + }, [sandboxId, mode]) const assembledPolicy = useMemo(() => ({ ...policy, network_policies: blocksToPolicy(blocks) }), [policy, blocks]) + const activePreset = selectedPreset ? getSecurityPreset(selectedPreset) : null + const showDangerWarning = activePreset?.id === 'spicy' || activePreset?.id === 'ultra-lobster' + + function applyPreset(presetId: SecurityPresetId) { + const preset = getSecurityPreset(presetId) + if (!preset) return + setSelectedPreset(presetId) + setPolicy(preset.policy) + setBlocks(policyBlocksFromPolicy(preset.policy)) + setMessage(`${preset.label} applied. Review before saving.${preset.id === 'spicy' || preset.id === 'ultra-lobster' ? ' Warning: this preset is intentionally permissive.' : ''}`) + } async function savePolicy() { try { @@ -222,11 +215,13 @@ export default function ConfigurationPanel({ sandboxId }: ConfigurationPanelProp const res = await fetch(`/api/sandbox/${encodeURIComponent(sandboxId)}/config`, { method: "POST", headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ policy: assembledPolicy }), + body: JSON.stringify({ policy: assembledPolicy, preset: selectedPreset || null, mode }), }) const data = await res.json() if (!res.ok) throw new Error(data.error || "Failed to save policy") - setMessage("Policy saved. Dynamic network policy can apply live; static sections require sandbox recreation.") + setMessage(mode === 'create' + ? 'Preset and policy prepared for new sandbox creation. Static sections will apply at create time.' + : 'Policy saved. Dynamic network policy can apply live; static sections require sandbox recreation.') } catch (err) { setMessage(err instanceof Error ? err.message : "Failed to save policy") } finally { @@ -250,7 +245,7 @@ export default function ConfigurationPanel({ sandboxId }: ConfigurationPanelProp return (
-

{sandboxId} — OPENSHELL POLICY

+

{sandboxId} — {mode === 'create' ? 'NEW SANDBOX PRESET + POLICY' : 'OPENSHELL POLICY'}

Static / Recreate Required Dynamic / Apply Live @@ -259,6 +254,51 @@ export default function ConfigurationPanel({ sandboxId }: ConfigurationPanelProp {loading ?
Loading policy…
: (
+
+
+
+
Security Presets
+

Use a canned profile for new sandboxes or switch an existing sandbox policy baseline on the fly.

+
+
+ +
+
+ + {activePreset && ( +
+
+ {activePreset.label} + {activePreset.danger.replace('-', ' ')} + {showDangerWarning && Dangerous / Permissive} +
+

{activePreset.summary}

+ {(activePreset.id === 'spicy' || activePreset.id === 'ultra-lobster') && ( +
+ Warning: {activePreset.label} may be dangerous due to its permissive security stance. Use only on trusted lab workloads. +
+ )} +
+

Preset exec allowlist

+
{activePreset.execAllowlist.paths.join('\n')}
+
+
+ )} +
+
Filesystem Policy
Static
- setPolicy({ ...policy, filesystem_policy: { ...policy.filesystem_policy, read_only: v } })} placeholder="/usr -/lib -/etc" /> - setPolicy({ ...policy, filesystem_policy: { ...policy.filesystem_policy, read_write: v } })} placeholder="/sandbox -/tmp" /> + setPolicy({ ...policy, filesystem_policy: { ...policy.filesystem_policy, read_only: v } })} placeholder="/usr\n/lib\n/etc" /> + setPolicy({ ...policy, filesystem_policy: { ...policy.filesystem_policy, read_write: v } })} placeholder="/sandbox\n/tmp" />
@@ -332,7 +369,7 @@ export default function ConfigurationPanel({ sandboxId }: ConfigurationPanelProp
-
Policy JSON Preview
+
Policy JSON Preview
{JSON.stringify(assembledPolicy, null, 2)}
{message &&
{message}
}
diff --git a/app/page.tsx b/app/page.tsx index 4abc112..e45747e 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -2,6 +2,7 @@ import { useState } from 'react' import Sidebar from './components/Sidebar' import SandboxList from './components/SandboxList' +import ConfigurationPanel from './components/ConfigurationPanel' export default function Dashboard() { const [theme, setTheme] = useState<'light' | 'dark'>('dark') @@ -83,14 +84,16 @@ export default function Dashboard() {
{isCreateMode ? ( -
-

- CREATE SANDBOX -

-

- Sandbox creation workflow will appear here. Configure parameters and deploy a new sandbox instance. -

- {/* TODO: Add creation form */} +
+
+

+ CREATE SANDBOX +

+

+ Start from a named security preset, then refine the OpenShell policy before creating the sandbox. +

+
+
) : isDestroyMode ? (