diff --git a/crates/domain/src/jobs.rs b/crates/domain/src/jobs.rs index 29487b7..12b405a 100644 --- a/crates/domain/src/jobs.rs +++ b/crates/domain/src/jobs.rs @@ -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())); } diff --git a/crates/server/src/jobs.rs b/crates/server/src/jobs.rs index 4853e6f..f4f7d22 100644 --- a/crates/server/src/jobs.rs +++ b/crates/server/src/jobs.rs @@ -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")); } diff --git a/web/src/devices.tsx b/web/src/devices.tsx index 8dfcf52..72ee059 100644 --- a/web/src/devices.tsx +++ b/web/src/devices.tsx @@ -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(); }} /> - {scoped && } {volumes.length > 0 && (
diff --git a/web/src/opnsense-probe.tsx b/web/src/opnsense-probe.tsx deleted file mode 100644 index 587b4f2..0000000 --- a/web/src/opnsense-probe.tsx +++ /dev/null @@ -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(null); - const [ticket, setTicket] = useState<{id:string; hash:string} | null>(null); - const [operation, setOperation] = useState(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

OPNsense-Kernelabfrage

uname -s als Dienstkonto · ein Versuch · 10 Sekunden · 1 KiB Ausgabe.

- {operation && ticket ?

Auftrag eingereicht. Zur Genehmigung

- : } -
; -} diff --git a/web/src/order-composer.tsx b/web/src/order-composer.tsx index a723e7d..7cee763 100644 --- a/web/src/order-composer.tsx +++ b/web/src/order-composer.tsx @@ -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(null); const [linux, setLinux] = useState