feat: add approval bound full maintenance script console and executors
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
+18
-6
@@ -1,8 +1,9 @@
|
||||
import { Action, PlanInput, RecordValue, Session, planTargetPreviews, record, text, validateSystemService, windowsScriptProfile, logWindow, validateWindowsLogLimits, windowsEventLogFixtureSource, windowsEventLogFixtureChannel, windowsEventLogFixtureProvider, WindowsMsiManifest, MsiPostcondition, windowsMsi, windowsMsiManifest, windowsMsiAction, validateWindowsMsiInput, validateWindowsMsiLimits, msiUuid } from './api';
|
||||
import { Action, PlanInput, RecordValue, Session, planTargetPreviews, record, text, validateSystemService, windowsScriptProfile, logWindow, validateWindowsLogLimits, windowsEventLogFixtureSource, windowsEventLogFixtureChannel, windowsEventLogFixtureProvider, WindowsMsiManifest, MsiPostcondition, windowsMsi, windowsMsiManifest, windowsMsiAction, validateWindowsMsiInput, validateWindowsMsiLimits, msiUuid, fullMaintenanceScriptProfile, privilegedScriptProfile, validateScriptIdentityProfile } from './api';
|
||||
|
||||
export const hashPattern = /^[0-9a-f]{64}$/;
|
||||
export const rootWarning = 'HOHES RISIKO: root kann das Zielsystem verändern. Keine automatische Rechteerhöhung; eigener expliziter Plan, Scope, Helper und Genehmigung erforderlich.';
|
||||
export const systemWarning = 'SYSTEM: ausschließlich fest benannter Windows-Fixturedienst (running/stopped) oder eigenes festes MSI-Rezept. Eigenes system:execute, unabhängiger Helper und konkrete WebUI-Genehmigung erforderlich. Keine SYSTEM-Shell, kein impliziter Reboot oder Retry.';
|
||||
export const fullMaintenanceWarning = 'VOLLE HOSTWARTUNG · full_maintenance_v1: Das genehmigte Skript läuft als root/SYSTEM mit vollständiger Hostautorität, einschließlich Netzwerk, Dateisystem und Diensten. Es kann auch Agent, PKI und Schutzmechanismen ändern oder einen Neustart auslösen. Keine Sandbox- oder No-Reboot-Zusage. scripts:execute plus root:execute/system:execute, lokaler und zentraler Opt-in, passende Capability, unabhängiger Helper und konkrete WebUI-Genehmigung bleiben erforderlich.';
|
||||
export function permissions(auth: Session): string[] | null { return auth.permissions ?? null; }
|
||||
export function allowed(auth: Session, permission: string): boolean { return permissions(auth)?.includes(permission) === true; }
|
||||
export function availableActions(auth: Session, base: readonly Action[]): Action[] { return base.filter(a => a !== 'apt_native_acceptance' || auth.principal.simulated === true); }
|
||||
@@ -72,10 +73,13 @@ export function validateAptManifest(value: unknown, acceptance: boolean): Record
|
||||
}
|
||||
export async function verifyAptManifest(value: unknown, acceptance: boolean) { const m = validateAptManifest(value, acceptance); if (await sha256(bytes(m.transaction_bytes)) !== m.transaction_sha256) throw new Error('APT Transaktionshash stimmt nicht überein'); }
|
||||
export async function validateSensitiveInput(input: PlanInput, auth: Session) {
|
||||
if (input.action === 'run_script' && privilegedScriptProfile(input.parameters, input.parameters.execution_identity) === fullMaintenanceScriptProfile && !allowed(auth, 'scripts:execute')) throw new Error('scripts:execute für Vollwartung unbekannt oder nicht erteilt');
|
||||
if (input.parameters.execution_identity === 'root' && !allowed(auth, 'root:execute')) throw new Error('root:execute unbekannt oder nicht erteilt; keine Rechteerhöhung');
|
||||
if (input.parameters.execution_identity === 'system') {
|
||||
if (!allowed(auth, 'system:execute')) throw new Error('system:execute unbekannt oder nicht erteilt; root:execute enthält dieses Recht nicht');
|
||||
if (input.action !== 'set_service_state' && input.action !== 'ensure_package') throw new Error('SYSTEM ausschließlich für typisierte Dienstaktionen oder feste MSI-Rezepte');
|
||||
if (input.action === 'run_script') {
|
||||
if (privilegedScriptProfile(input.parameters, 'system') !== fullMaintenanceScriptProfile) throw new Error('SYSTEM ausschließlich für typisierte Aktionen oder explizit full_maintenance_v1');
|
||||
} else if (input.action !== 'set_service_state' && input.action !== 'ensure_package') throw new Error('SYSTEM ausschließlich für typisierte Dienstaktionen oder feste MSI-Rezepte');
|
||||
if (input.action === 'set_service_state') validateSystemService(input.parameters.unit, input.parameters.state, input.parameters.timeout_seconds, input.parameters.max_output_bytes);
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(input.parameters, 'windows_msi_manifest') || (input.action === 'ensure_package' && input.parameters.execution_identity === 'system')) {
|
||||
@@ -104,7 +108,7 @@ export function systemPlanJobs(plan: RecordValue): RecordValue[] {
|
||||
powerShellPlanJobs(plan);
|
||||
return structuredClone(verifiedPowerShellPlans.get(plan)!.systemJobs);
|
||||
}
|
||||
export interface PowerShellPlanJob { readonly assetId: string; readonly profile: 'inherited' | 'powershell_51_remote_signed' }
|
||||
export interface PowerShellPlanJob { readonly assetId: string; readonly profile: 'inherited' | 'powershell_51_remote_signed'; readonly identity?: 'system' }
|
||||
// Only successful verification writes this cache. Projection is copied from the
|
||||
// verified bytes; later mutations of API views cannot change the displayed plan.
|
||||
interface VerifiedPowerShellPlan { readonly jobs: readonly PowerShellPlanJob[]; readonly logJobs: readonly QueryLogsPlanJob[]; readonly msiJobs: readonly WindowsMsiPlanJob[]; readonly systemJobs: RecordValue[]; readonly planHash: unknown; readonly planBytes: readonly number[] }
|
||||
@@ -146,13 +150,14 @@ function hasPowerShellProfile(payload: RecordValue): boolean {
|
||||
function projectPowerShellJobs(jobs: unknown): PowerShellPlanJob[] {
|
||||
return scriptPayloads(jobs).filter(hasPowerShellProfile).map(payload => {
|
||||
const action = record(payload.action);
|
||||
if (action.action !== 'run_script' || action.interpreter !== 'powershell' || payload.execution_identity !== 'agent_service') throw new Error('PowerShell-Profil benötigt Windows PowerShell5.1 als agent_service');
|
||||
exact(action, ['action', 'interpreter', 'script_utf8', 'arguments', 'expected_stdout', ...(Object.prototype.hasOwnProperty.call(action, 'windows_execution_profile') ? ['windows_execution_profile'] : [])]);
|
||||
if (action.action !== 'run_script' || action.interpreter !== 'powershell') throw new Error('PowerShell-Profil benötigt Windows PowerShell5.1 als agent_service oder explizit SYSTEM');
|
||||
validateScriptIdentityProfile(action, payload.execution_identity, action.interpreter);
|
||||
exact(action, ['action', 'interpreter', 'script_utf8', 'arguments', 'expected_stdout', ...(Object.prototype.hasOwnProperty.call(action, 'windows_execution_profile') ? ['windows_execution_profile'] : []), ...(Object.hasOwn(action, 'privileged_script_profile') ? ['privileged_script_profile'] : [])]);
|
||||
if (typeof action.script_utf8 !== 'string' || !action.script_utf8 || new TextEncoder().encode(action.script_utf8).length > 32768 || action.script_utf8.includes('\0')
|
||||
|| (!/^[\x00-\x7f]*$/.test(action.script_utf8) && !action.script_utf8.startsWith('\ufeff'))
|
||||
|| !Array.isArray(action.arguments) || action.arguments.length > 32 || action.arguments.some(arg => typeof arg !== 'string' || new TextEncoder().encode(arg).length > 4096 || arg.includes('\0'))
|
||||
|| !(action.expected_stdout === null || (typeof action.expected_stdout === 'string' && new TextEncoder().encode(action.expected_stdout).length <= 65536))) throw new Error('Vollständige unveränderte PowerShell-Skriptaktion erforderlich');
|
||||
return { assetId: text(payload.asset_id, 'PowerShell-Zielasset'), profile: windowsScriptProfile(action) };
|
||||
return { assetId: text(payload.asset_id, 'PowerShell-Zielasset'), profile: windowsScriptProfile(action), ...(payload.execution_identity === 'system' ? { identity: 'system' as const } : {}) };
|
||||
});
|
||||
}
|
||||
function validatePlanAliases(plan: RecordValue, parsed: unknown): void {
|
||||
@@ -352,6 +357,13 @@ export async function verifyPlanIntegrity(plan: RecordValue) {
|
||||
for (const payload of systemJobs) {
|
||||
const action = record(payload.action);
|
||||
if (isMsi(payload)) continue; // Fully validated, hash-bound package projection above.
|
||||
if (action.action === 'run_script') {
|
||||
validateScriptIdentityProfile(action, payload.execution_identity, action.interpreter);
|
||||
if (privilegedScriptProfile(action, payload.execution_identity) !== fullMaintenanceScriptProfile || action.interpreter !== 'powershell'
|
||||
|| !Number.isInteger(payload.max_runtime_seconds) || Number(payload.max_runtime_seconds) < 1 || Number(payload.max_runtime_seconds) > 120
|
||||
|| !Number.isInteger(payload.max_output_bytes) || Number(payload.max_output_bytes) < 1 || Number(payload.max_output_bytes) > 65536) throw new Error('SYSTEM-Skript benötigt explizites Vollwartungsprofil und feste Budgets');
|
||||
continue;
|
||||
}
|
||||
exact(action, ['action', 'unit', 'state']);
|
||||
if (action.action !== 'set_service_state') throw new Error('SYSTEM-Plan enthält keine typisierte Dienstaktion');
|
||||
validateSystemService(action.unit, action.state, payload.max_runtime_seconds, payload.max_output_bytes);
|
||||
|
||||
Reference in New Issue
Block a user