Route OPNsense library and custom jobs through the standard order composer

This commit is contained in:
2026-11-20 08:15:07 +01:00
parent 8a1ea58d86
commit 1f3cd5ea0c
5 changed files with 12 additions and 58 deletions
+6 -1
View File
@@ -493,6 +493,10 @@ impl Action {
privileged_script_profile:Some(PrivilegedScriptProfile::FullMaintenanceV1), ..}
if interpreter=="posix_sh") && self.validate()
}
pub fn opnsense_service_script(&self) -> bool {
matches!(self, Self::RunScript {interpreter,windows_execution_profile:None,privileged_script_profile:None,..}
if interpreter=="posix_sh") && self.validate()
}
/// Shared plan/revalidation/start gate. Passive inventory never implies job support.
pub fn available_for(&self, identity: &str, capabilities: &[String]) -> bool {
@@ -506,7 +510,8 @@ impl Action {
let has = |cap: &str| capabilities.iter().any(|c| c == cap);
if has("opnsense.base/1") {
return has("run_script") && has("rmm.sync.v1") && !has("windows.base/1") && !has("linux.base/1")
&& ((identity=="agent_service" && has("opnsense.uname/1") && self.opnsense_kernel_probe())
&& ((identity=="agent_service" && ((has("opnsense.uname/1") && self.opnsense_kernel_probe())
|| (has("opnsense.posix/1") && self.opnsense_service_script())))
|| (identity=="root" && has("opnsense.root.posix/1") && has(FULL_MAINTENANCE_CAPABILITY)
&& has("helper.root.v1") && has("root:run_script") && self.opnsense_root_script()));
}
+1 -1
View File
@@ -441,7 +441,7 @@ pub(crate) async fn plan_resolved(
let row = &rows[0];
let caps = capabilities(row.get("capabilities"))?;
let action = target_action(&input, &caps)?;
if input.execution_identity=="agent_service" && caps.iter().any(|s| s=="opnsense.base/1") &&
if input.execution_identity=="agent_service" && caps.iter().any(|s| s=="opnsense.base/1") && !caps.iter().any(|s| s=="opnsense.posix/1") &&
(input.max_runtime_seconds != 10 || input.max_output_bytes != 1024) {
return Err(fail("UNSUPPORTED_CAPABILITY"));
}
+1 -3
View File
@@ -18,7 +18,6 @@ import { CatalogCheckNotice } from './catalog-check';
import { devicePlatform } from './script-catalog';
import { DeviceInventoryPanels, systemDetails } from './device-inventory';
import { OPNsenseDetails } from './opnsense';
import { OPNsenseProbe } from './opnsense-probe';
import { DeviceCustomerTransfer } from './device-customer-transfer';
import { HypervisorAssignment, HypervisorLabel } from './device-hypervisor';
import { ErrorBox, errorText, useResource } from './resource';
@@ -206,7 +205,7 @@ function reportedScriptProfiles(device: RecordValue) {
if (!caps.has('run_script')) return 'Nicht gemeldet';
const windows = os === 'windows';
const identity = windows ? 'system' : 'root';
const service = os==='opnsense' ? 'Kernelabfrage als Dienstkonto' : windows ? 'PowerShell als Dienstkonto' : 'Shell als Dienstkonto';
const service = os==='opnsense' && !caps.has('opnsense.posix/1') ? 'Kernelabfrage als Dienstkonto' : windows ? 'PowerShell als Dienstkonto' : 'Shell als Dienstkonto';
if (!caps.has(os + '.base/1') || caps.has(windows ? 'linux.base/1' : 'windows.base/1')) return 'Nicht gemeldet';
if (windows && !['rmm.sync.v1', 'script.powershell/1', 'script.powershell.process_remote_signed/1'].every(cap => caps.has(cap)))
return 'Nicht gemeldet';
@@ -303,7 +302,6 @@ function DeviceDetail({
onSaved={() => { setPurposeSaved(true); detail.reload(); }}
/>
<OPNsenseDetails device={d} />
{scoped && <OPNsenseProbe key={`${customer}/${asset}/${agent}`} device={d} auth={scoped}/>}
<DeviceInventoryPanels device={d} />
{volumes.length > 0 && (
<section>
-48
View File
@@ -1,48 +0,0 @@
import { useState } from 'react';
import { objectId, record, request, tenantPath, type RecordValue, type Session } from './api';
import { allowed } from './safety';
import { verifiedScriptOrder } from './order-composer';
import { ErrorBox, errorText } from './resource';
export function OPNsenseProbe({ device, auth }: {device: RecordValue; auth: Session}) {
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [ticket, setTicket] = useState<{id:string; hash:string} | null>(null);
const [operation, setOperation] = useState<string | null>(null);
if (device.source_id !== 'opnsense.base' || device.lifecycle !== 'current' ||
!Array.isArray(device.capabilities) || !device.capabilities.includes('opnsense.uname/1') ||
!allowed(auth,'operations:plan') || !allowed(auth,'scripts:execute')) return null;
const customer = objectId(device,'tenant'), asset = objectId(device,'asset'), agent = objectId(device,'agent');
const path = tenantPath(customer,'/operation-plans');
async function submit() {
setBusy(true); setError(null);
try {
let pending = ticket;
if (!pending) {
const now = Date.now(), start = new Date(now).toISOString(), end = new Date(now+86400000).toISOString();
const reason = 'OPNsense: Kernelname auf dem Dienstkonto prüfen';
const raw = await request(path, {csrf:auth.csrf_token,body:{tenant_id:customer,action:'run_script',
targets:{asset_ids:[asset]},parameters:{execution_identity:'agent_service',timeout_seconds:10,
max_output_bytes:1024,arguments:[],expected_stdout:'FreeBSD\n',
variants:[{os_family:'opnsense',interpreter:'posix_sh',encoding:'utf-8',script_utf8:'uname -s\n'}]},
schedule:{not_before:start,start_before:end,offline_policy:'wait_until_deadline'},
rollout:{max_parallel:1,halt_after_failures:1},reason}});
const checked = await verifiedScriptOrder(raw,customer,auth.principal.id), j = checked.jobs[0];
if (!j || checked.jobs.length!==1 || j.assetId!==asset || j.agentId!==agent || j.identity!=='agent_service' ||
j.script!=='uname -s\n' || j.expectedStdout!=='FreeBSD\n' || j.interpreter!=='posix_sh' ||
j.arguments.length || j.runtimeSeconds!==10 || j.outputBytes!==1024 || checked.reason!==reason ||
Date.parse(j.notBefore)!==now || Date.parse(j.startBefore)!==Date.parse(end) ||
checked.maxParallel!==1 || checked.halt!==1) throw Error('Plan weicht von der Kernelabfrage ab.');
pending = {id:objectId(checked.plan,'plan'),hash:String(checked.plan.plan_hash)};
setTicket(pending);
}
const r = record(await request(path+'/'+pending.id+'/submit',{csrf:auth.csrf_token,body:{idempotency_key:pending.id}}));
if (r.plan_id!==pending.id || r.plan_hash!==pending.hash) throw Error('Planbindung stimmt nicht.');
setOperation(objectId(r,'operation'));
} catch (e) { setError(errorText(e)); } finally { setBusy(false); }
}
return <section><h2>OPNsense-Kernelabfrage</h2><p><code>uname -s</code> als Dienstkonto · ein Versuch · 10 Sekunden · 1 KiB Ausgabe.</p>
{operation && ticket ? <p>Auftrag eingereicht. <a href={`#genehmigungen/pruefen/${customer}/${ticket.id}`}>Zur Genehmigung</a></p>
: <button disabled={busy} onClick={submit}>Kernelabfrage zur Genehmigung einreichen</button>}
<ErrorBox error={error}/></section>;
}
+4 -5
View File
@@ -81,7 +81,7 @@ function resumeTicket(key: string): Ticket | null {
}
return data;
}
export async function verifiedScriptOrder(value: unknown, tenantId: string, principal: string) {
async function verifiedScriptOrder(value: unknown, tenantId: string, principal: string) {
const plan = record(value, 'Auftragsplan');
await verifyPlanIntegrity(plan);
await verifyScriptPlan(plan);
@@ -143,7 +143,7 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
const [libraryIdentity, setLibraryIdentity] = useState<Identity | null>(null);
const [linux, setLinux] = useState<Script>(() => emptyScript('posix_sh'));
const [windows, setWindows] = useState<Script>(() => emptyScript('powershell'));
const [opnsense,setOpnsense] = useState<Script>(() => ({...emptyScript('posix_sh'),execution_identity:'root'}));
const [opnsense,setOpnsense] = useState<Script>(() => emptyScript('posix_sh'));
const [reason, setReason] = useState('');
const [start, setStart] = useState(() => localDate(Date.now()));
const [end, setEnd] = useState(() => localDate(Date.now() + 3600000));
@@ -236,8 +236,6 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
);
const issues: string[] = [];
if (hasOPNsense && (hasLinux || hasWindows)) issues.push('OPNsense-Geräte bitte in einem eigenen Auftrag planen.');
if (hasOPNsense && (!allowed(auth,'root:execute') || identity!=='root'))
issues.push('OPNsense-Skripte benötigen die Ausführungsidentität root und das Recht root:execute.');
if (targets.some((d) => !d?.current))
issues.push('Ein Zielgerät fehlt im aktuellen Bestand. Entfernen Sie es aus der Auswahl.');
const unidentified = targets.filter((d) => d && !d.platform);
@@ -710,7 +708,8 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
{hasLinux && <ScriptFieldsForPlatform script={linux} change={setLinux} auth={auth} windows={false} />}
{hasWindows && <ScriptFieldsForPlatform script={windows} change={setWindows} auth={auth} windows />}
{hasOPNsense && <fieldset><legend>OPNsense-Skript</legend>
<ScriptFields script={opnsense} change={setOpnsense} ids={['root']} interpreters={['posix_sh']} />
<ScriptFields script={opnsense} change={setOpnsense}
ids={allowed(auth,'root:execute') ? ['agent_service','root'] : ['agent_service']} interpreters={['posix_sh']} />
</fieldset>}
</>
)}