Plan OPNsense POSIX root scripts with explicit device policy, profile and approval
This commit is contained in:
@@ -43,7 +43,7 @@ type Target = {
|
||||
id: string;
|
||||
name: string;
|
||||
os: string;
|
||||
platform: 'linux' | 'windows' | null;
|
||||
platform: 'linux' | 'windows' | 'opnsense' | null;
|
||||
state: string;
|
||||
current: boolean;
|
||||
};
|
||||
@@ -143,6 +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 [reason, setReason] = useState('');
|
||||
const [start, setStart] = useState(() => localDate(Date.now()));
|
||||
const [end, setEnd] = useState(() => localDate(Date.now() + 3600000));
|
||||
@@ -217,6 +218,7 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
|
||||
const targets = selected.map((id) => directory.get(id));
|
||||
const hasLinux = targets.some((d) => d?.platform === 'linux');
|
||||
const hasWindows = targets.some((d) => d?.platform === 'windows');
|
||||
const hasOPNsense = targets.some((d) => d?.platform === 'opnsense');
|
||||
const scripts = useResource(
|
||||
(signal) => (canPlan && step === 2 && !ticket && mode === 'library' ? loadRevisions(tenantId, signal) : Promise.resolve([])),
|
||||
[tenantId, canPlan, step, !!ticket, mode]
|
||||
@@ -225,21 +227,25 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
|
||||
const heads = latestRevisions(scripts.data ?? []);
|
||||
const identity = mode === 'library'
|
||||
? libraryIdentity ?? revision?.execution_identity
|
||||
: (hasWindows ? windows : linux).execution_identity;
|
||||
const restartPlatform = hasLinux === hasWindows ? null : hasWindows ? 'windows' : 'linux';
|
||||
: (hasOPNsense ? opnsense : hasWindows ? windows : linux).execution_identity;
|
||||
const restartPlatform = hasOPNsense || hasLinux === hasWindows ? null : hasWindows ? 'windows' : 'linux';
|
||||
const restartScript = restartPlatform && heads.find(revision =>
|
||||
revision.name === (hasWindows ? 'Windows neu starten' : 'Linux neu starten') &&
|
||||
scriptPlatform(revision.interpreter) === restartPlatform &&
|
||||
revision.execution_identity === (hasWindows ? 'system' : 'root')
|
||||
);
|
||||
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);
|
||||
if (unidentified.length)
|
||||
issues.push('Das Betriebssystem ist noch nicht bestätigt: ' + unidentified.map((d) => d?.name).join(', '));
|
||||
if (mode === 'library' && revision) {
|
||||
const incompatible = targets.filter((d) => d?.platform && d.platform !== scriptPlatform(revision.interpreter));
|
||||
const incompatible = targets.filter((d) => d?.platform && (d.platform==='opnsense'
|
||||
? revision.interpreter!=='posix_sh' : d.platform !== scriptPlatform(revision.interpreter)));
|
||||
if (incompatible.length)
|
||||
issues.push(
|
||||
`Dieses Skript unterstützt ${interpreterNames[revision.interpreter]}. Inkompatible Geräte: ${incompatible.map((d) => d?.name).join(', ')}.`
|
||||
@@ -304,10 +310,10 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
|
||||
}
|
||||
});
|
||||
} else {
|
||||
const variants = [hasLinux ? linux : null, hasWindows ? windows : null]
|
||||
const variants = [hasLinux ? linux : null, hasWindows ? windows : null, hasOPNsense ? opnsense : null]
|
||||
.filter((s): s is Script => !!s)
|
||||
.map((s) => ({
|
||||
os_family: scriptPlatform(s.interpreter),
|
||||
os_family: s===opnsense ? 'opnsense' : scriptPlatform(s.interpreter),
|
||||
interpreter: s.interpreter,
|
||||
encoding: 'utf-8',
|
||||
script_utf8: s.script_utf8,
|
||||
@@ -341,7 +347,7 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
|
||||
const checked = await verifiedScriptOrder(raw, tenantId, auth.principal.id);
|
||||
const mismatchedJob = checked.jobs.some((j) => {
|
||||
const script =
|
||||
mode === 'library' ? revision : directory.get(j.assetId)?.platform === 'windows' ? windows : linux;
|
||||
mode === 'library' ? revision : hasOPNsense ? opnsense : directory.get(j.assetId)?.platform === 'windows' ? windows : linux;
|
||||
return (
|
||||
!selected.includes(j.assetId) ||
|
||||
j.revision?.id !== (mode === 'library' ? revisionId : undefined) ||
|
||||
@@ -703,6 +709,9 @@ 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']} />
|
||||
</fieldset>}
|
||||
</>
|
||||
)}
|
||||
{identity && identity !== 'agent_service' && (
|
||||
|
||||
Reference in New Issue
Block a user