Add fresh device trust, installer recovery and scoped patch runtime
This commit is contained in:
@@ -45,9 +45,11 @@ export function ConsoleOutput({ job }: { job: RecordValue }) {
|
||||
function Result({ value }: { value: unknown }) {
|
||||
try {
|
||||
const result = record(value, 'Jobergebnis');
|
||||
const evidence = result.evidence && typeof result.evidence === 'object' ? record(result.evidence) : {};
|
||||
const reboot = Object.hasOwn(evidence, 'windows_update_reboot_required') ? evidence.windows_update_reboot_required : result.reboot_required;
|
||||
return <><p>Exitcode: {typeof result.exit_code === 'number' && Number.isInteger(result.exit_code) ? result.exit_code : 'unknown / nicht gemeldet'} · Fehlercode: {typeof result.error_code === 'string' && result.error_code ? result.error_code : 'nicht gemeldet'}</p>
|
||||
<p className={result.output_truncated === false ? 'muted' : 'warning'}>Ausgabe begrenzt: {typeof result.output_truncated === 'boolean' ? String(result.output_truncated) : 'unknown'}. {result.output_truncated === true ? 'Die gespeicherten Bytes sind nur ein Ausschnitt.' : result.output_truncated !== false ? 'Vollständigkeit ist nicht bestätigt.' : 'Keine Trunkierung gemeldet.'}</p>
|
||||
<p>Neustartbedarf: {typeof result.reboot_required === 'boolean' ? String(result.reboot_required) : 'unknown'}. Ein Exitcode 0 bestätigt Prozessabschluss; fachliche Nachbedingungen stehen im vollständigen Ergebnis.</p>
|
||||
<p>Neustartbedarf: {typeof reboot === 'boolean' ? String(reboot) : 'unknown'}. Ein Exitcode 0 bestätigt Prozessabschluss; fachliche Nachbedingungen stehen im vollständigen Ergebnis.</p>
|
||||
<p>Ausgabe ist nicht vertrauenswürdiger Text vom Zielgerät. Sie erteilt keine Genehmigung und wird nicht als Anweisung ausgeführt.</p>
|
||||
<OutputChannel name="stdout" value={result.stdout}/><OutputChannel name="stderr" value={result.stderr}/></>;
|
||||
} catch { return <p className="error" role="alert">Ergebnisformat unbekannt; vollständige Originaldaten stehen darunter.</p>; }
|
||||
|
||||
@@ -51,6 +51,26 @@ it('shows the immutable library revision and rejects a different catalog script
|
||||
await expect(verifyScriptPlan(await stored('f'.repeat(64)))).rejects.toThrow('Bibliotheksversion');
|
||||
});
|
||||
|
||||
it('accepts one hour only for the exact Windows Update revision', async () => {
|
||||
const source = readFileSync(new URL('../../crates/domain/src/windows_update.ps1', import.meta.url), 'utf8');
|
||||
async function windowPlan(script: string, fixed: boolean, seconds: number) {
|
||||
const original = plan('windows_system_full');
|
||||
const parsed = record(JSON.parse(new TextDecoder().decode(new Uint8Array(original.plan_payload_bytes as number[]))));
|
||||
const job = (parsed.jobs as RecordValue[])[0]!, payload = record(job.payload), action = record(payload.action);
|
||||
action.script_utf8 = script; action.arguments = []; action.expected_stdout = null; payload.max_runtime_seconds = seconds;
|
||||
job.script_sha256 = await sha256(new TextEncoder().encode(script));
|
||||
job.job_payload_hash = await sha256(new TextEncoder().encode(JSON.stringify(payload)));
|
||||
if (fixed) parsed.script_revision = { revision_id: parsed.plan_id, name: 'Windows-Updates installieren', version: 1, script_sha256: job.script_sha256 };
|
||||
const raw = new TextEncoder().encode(JSON.stringify(parsed));
|
||||
return { plan_hash: await sha256(raw), plan_payload_bytes: Array.from(raw) };
|
||||
}
|
||||
const valid = await windowPlan(source, true, 3600);
|
||||
await verifyScriptPlan(valid); expect(scriptPlanJobs(valid)[0]?.runtimeSeconds).toBe(3600);
|
||||
for (const bad of [await windowPlan(source+'\n',true,3600), await windowPlan(source,false,3600), await windowPlan(source,true,3601)]) {
|
||||
await expect(verifyScriptPlan(bad)).rejects.toThrow();
|
||||
}
|
||||
});
|
||||
|
||||
it('rejects view, byte and fixed identity/budget/profile tampering before and after display', async () => {
|
||||
for (const alias of ['payload', 'plan_payload', 'jobs', 'resolved_targets']) {
|
||||
const p = plan('linux_root_full'); await verifyScriptPlan(p); p[alias] = [];
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { canonicalJson, record, RecordValue, text, windowsScriptProfile, privilegedScriptProfile, fullMaintenanceScriptProfile, validateScriptIdentityProfile } from './api';
|
||||
import { bytes, hashPattern, parseStrictJson, sha256 } from './safety';
|
||||
|
||||
export const windowsUpdateScriptHash = '0fa5f513a06b6cf902a3f9ac1989987642c181eedd6c305b3912771bd10f2ebf';
|
||||
export interface ScriptPlanJob {
|
||||
revision?: { id: string; name: string; version: number };
|
||||
assetId: string; agentId: string; jobId: string; attemptId: string;
|
||||
@@ -99,7 +100,9 @@ export async function verifyScriptPlan(plan: RecordValue): Promise<void> {
|
||||
const notBefore = text(p.not_before, 'Frühester Start'), startBefore = text(p.start_before, 'Startfrist');
|
||||
if (!Number.isFinite(Date.parse(notBefore)) || !Number.isFinite(Date.parse(startBefore)) || Date.parse(notBefore) >= Date.parse(startBefore) || (plan.expires_at !== undefined && plan.expires_at !== startBefore)) throw new Error('Skriptplan: widersprüchliche feste Fristen');
|
||||
const full = privilegedProfile === fullMaintenanceScriptProfile;
|
||||
const runtimeSeconds = integer(p.max_runtime_seconds, 1, full ? interpreter === 'powershell' ? 120 : 300 : 3600), outputBytes = integer(p.max_output_bytes, 1, full ? 65536 : 262144);
|
||||
const windowsUpdate = revisionHash === windowsUpdateScriptHash && interpreter === 'powershell' && identity === 'system'
|
||||
&& full && windowsProfile === 'powershell_51_remote_signed' && !action.arguments.length && action.expected_stdout === null;
|
||||
const runtimeSeconds = integer(p.max_runtime_seconds, 1, windowsUpdate ? 3600 : full ? interpreter === 'powershell' ? 120 : 300 : 3600), outputBytes = integer(p.max_output_bytes, 1, full ? 65536 : 262144);
|
||||
const orderedAction = { action: 'run_script', interpreter, script_utf8: script, arguments: action.arguments, expected_stdout: action.expected_stdout, ...(hasWindowsProfile ? { windows_execution_profile: action.windows_execution_profile } : {}), ...(hasPrivilegedProfile ? { privileged_script_profile: action.privileged_script_profile } : {}) };
|
||||
const ordered = { schema_version: p.schema_version, tenant_id: p.tenant_id, asset_id: assetId, agent_id: agentId, enrollment_generation: p.enrollment_generation, assignment_version: p.assignment_version, job_id: jobId, attempt_id: attemptId, action: orderedAction, execution_identity: identity, not_before: notBefore, start_before: startBefore, max_runtime_seconds: runtimeSeconds, max_output_bytes: outputBytes };
|
||||
const scriptHash = digest(job.script_sha256), jobHash = digest(job.job_payload_hash);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import React, { FormEvent, useEffect, useState } from 'react';
|
||||
import { objectId, page, record, request, Session, tenantPath, text } from './api';
|
||||
import { allowed } from './safety';
|
||||
import { windowsUpdateScriptHash } from './script-console';
|
||||
|
||||
interface Draft {
|
||||
name: string;
|
||||
@@ -79,7 +80,8 @@ export function ScriptLibrary({ tenantId, auth, selected, showPlan }: { tenantId
|
||||
});
|
||||
}
|
||||
if (!canRead) return null;
|
||||
const limit = stored?.execution_identity === 'system' ? 120 : stored?.execution_identity === 'root' ? 300 : 3600;
|
||||
const windowsUpdate = stored?.execution_identity === 'system' && stored.interpreter === 'powershell' && stored.script_sha256 === windowsUpdateScriptHash;
|
||||
const limit = windowsUpdate ? 3600 : stored?.execution_identity === 'system' ? 120 : stored?.execution_identity === 'root' ? 300 : 3600;
|
||||
return <section aria-label="Skriptbibliothek"><h2>Skriptbibliothek</h2>
|
||||
{error && <p role="alert" className="error">{error}</p>}{notice && <p role="status">{notice}</p>}
|
||||
{items.length > 0 && <label>Gespeicherte Skriptversion<select value={chosen} disabled={busy || !!draft} onChange={e => setChosen(e.target.value)}>
|
||||
@@ -101,9 +103,10 @@ export function ScriptLibrary({ tenantId, auth, selected, showPlan }: { tenantId
|
||||
</fieldset></form>}
|
||||
{canPlan && stored && !draft && <form key={stored.revision_id} onSubmit={plan}><fieldset disabled={busy}><legend>Auftrag für {stored.name} · v{stored.version} vorbereiten</legend>
|
||||
<p>{selected.length} ausgewählte Geräte · Ein Gerät gleichzeitig · Stopp beim ersten Fehler · 65536 Byte Ausgabe je Gerät</p>
|
||||
{windowsUpdate && <p>Diese Version installiert verfügbare Softwareupdates ohne eigenen Neustart. Sie meldet Neustartbedarf. Laufzeiten über 120 Sekunden erfordern die passende Windows-Update-Freigabe in Server- und Helperpolicy.</p>}
|
||||
<label>Begründung<input name="reason" required maxLength={1024}/></label>
|
||||
<label>Startfrist in Minuten<input name="minutes" type="number" min={1} max={1440} defaultValue={60} required/></label>
|
||||
<label>Laufzeit je Gerät in Sekunden<input name="runtime" type="number" min={1} max={limit} defaultValue={Math.min(limit,120)} required/></label>
|
||||
<label>Laufzeit je Gerät in Sekunden<input name="runtime" type="number" min={1} max={limit} defaultValue={windowsUpdate ? 3600 : Math.min(limit,120)} required/></label>
|
||||
<button disabled={!selected.length}>Plan vorbereiten</button>
|
||||
</fieldset></form>}
|
||||
</section>;
|
||||
|
||||
Reference in New Issue
Block a user