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:
+20
-2
@@ -60,6 +60,18 @@ export const pretty = (v: unknown) => JSON.stringify(v, null, 2);
|
||||
export const actions = ['run_script', 'refresh_inventory', 'query_logs', 'set_service_state', 'ensure_package', 'apply_updates', 'reboot', 'apt_native_acceptance'] as const;
|
||||
export type Action = typeof actions[number];
|
||||
export const windowsPowerShellRemoteSignedProfile = 'powershell_51_remote_signed' as const;
|
||||
export const fullMaintenanceScriptProfile = 'full_maintenance_v1' as const;
|
||||
export function privilegedScriptProfile(value: RecordValue, identity: unknown): 'bounded' | typeof fullMaintenanceScriptProfile {
|
||||
if (!Object.hasOwn(value, 'privileged_script_profile')) return 'bounded';
|
||||
if (value.privileged_script_profile !== fullMaintenanceScriptProfile || !['root', 'system'].includes(String(identity))) throw new Error('Vollwartungsprofil ausschließlich full_maintenance_v1 mit root/system; kein null oder geerbtes Privileg');
|
||||
return fullMaintenanceScriptProfile;
|
||||
}
|
||||
export function validateScriptIdentityProfile(value: RecordValue, identity: unknown, interpreter: unknown): void {
|
||||
const profile = privilegedScriptProfile(value, identity);
|
||||
if (interpreter === 'powershell') {
|
||||
if (identity !== 'agent_service' && !(identity === 'system' && profile === fullMaintenanceScriptProfile)) throw new Error('PowerShell nur agent_service oder ausdrücklich SYSTEM/full_maintenance_v1');
|
||||
} else if (!['posix_sh', 'bash'].includes(String(interpreter)) || !['agent_service', 'root'].includes(String(identity))) throw new Error('Linux-Skript benötigt agent_service/root und festen Shellinterpreter');
|
||||
}
|
||||
/** A missing field is inherited policy; a present field is never silently coerced. */
|
||||
export function windowsScriptProfile(value: RecordValue): 'inherited' | typeof windowsPowerShellRemoteSignedProfile {
|
||||
if (!Object.prototype.hasOwnProperty.call(value, 'windows_execution_profile')) return 'inherited';
|
||||
@@ -157,6 +169,7 @@ export function expectedStdout(value: string, format: string): string | null {
|
||||
return output;
|
||||
}
|
||||
export function validateInput(input: PlanInput): void {
|
||||
if (Object.hasOwn(input.parameters, 'privileged_script_profile') && input.action !== 'run_script') throw new Error('Vollwartungsprofil ausschließlich für run_script');
|
||||
if (Object.prototype.hasOwnProperty.call(input.parameters, 'windows_execution_profile')) throw new Error('Windows-Ausführungsprofil muss an der festen Windows-Skriptvariante stehen');
|
||||
if (!input.targets.asset_ids.length || new Set(input.targets.asset_ids).size !== input.targets.asset_ids.length) throw new Error('Feste eindeutige Ziele erforderlich');
|
||||
if (!input.reason.trim()) throw new Error('Begründung erforderlich');
|
||||
@@ -164,21 +177,26 @@ export function validateInput(input: PlanInput): void {
|
||||
if (!Number.isFinite(start) || !Number.isFinite(end) || end <= start || end <= Date.now()) throw new Error('Ungültige oder abgelaufene Frist');
|
||||
for (const n of [input.rollout.max_parallel, input.rollout.halt_after_failures, input.parameters.timeout_seconds, input.parameters.max_output_bytes]) if (typeof n !== 'number' || !Number.isSafeInteger(n) || n < 1) throw new Error('Limits müssen positive Ganzzahlen sein');
|
||||
if (input.action === 'run_script') {
|
||||
const profile = privilegedScriptProfile(input.parameters, input.parameters.execution_identity);
|
||||
const variants = input.parameters.variants;
|
||||
if (!Array.isArray(variants) || !variants.length || variants.length > 2 || !variants.every(v => {
|
||||
const variant = record(v), script = typeof variant.script_utf8 === 'string' ? variant.script_utf8 : '';
|
||||
if (Object.hasOwn(variant, 'privileged_script_profile')) throw new Error('Privilegiertes Skriptprofil muss aktionsweit in parameters stehen');
|
||||
windowsScriptProfile(variant);
|
||||
validateScriptIdentityProfile(input.parameters, input.parameters.execution_identity, variant.interpreter);
|
||||
const bytes = new TextEncoder().encode(script).length;
|
||||
const platform = variant.os_family === 'linux' && ['posix_sh', 'bash'].includes(String(variant.interpreter))
|
||||
|| variant.os_family === 'windows' && variant.interpreter === 'powershell';
|
||||
return bytes > 0 && bytes <= 32768 && !script.includes('\0') && variant.encoding === 'utf-8' && platform
|
||||
&& (variant.os_family !== 'windows' || /^[\x00-\x7f]*$/.test(script) || script.startsWith('\ufeff'));
|
||||
}) || new Set(variants.map(v => record(v).os_family)).size !== variants.length) throw new Error('Je Plattform genau eine passende UTF-8 Variante (max.32KiB); PowerShell5.1: ASCII oder explizites UTF-8-BOM vor Hashbildung');
|
||||
if (variants.some(v => record(v).os_family === 'windows') && input.parameters.execution_identity !== 'agent_service') throw new Error('Windows PowerShell benötigt agent_service; kein SYSTEM-/Root-Fallback');
|
||||
if (profile === fullMaintenanceScriptProfile && (Number(input.parameters.timeout_seconds) > (variants.some(v => record(v).os_family === 'windows') ? 120 : 300) || Number(input.parameters.max_output_bytes) > 65536)) throw new Error('Vollwartung: Linux höchstens300s / Windows höchstens120s und65536Ausgabebytes');
|
||||
}
|
||||
if (!['agent_service', 'root', 'system'].includes(String(input.parameters.execution_identity))) throw new Error('Explizite Ausführungsidentität erforderlich');
|
||||
if (input.parameters.execution_identity === 'system') {
|
||||
if (input.action === 'ensure_package') validateWindowsMsiInput(input);
|
||||
if (input.action === 'run_script') {
|
||||
if (privilegedScriptProfile(input.parameters, 'system') !== fullMaintenanceScriptProfile) throw new Error('SYSTEM-Skript benötigt ausdrücklich full_maintenance_v1');
|
||||
} else if (input.action === 'ensure_package') validateWindowsMsiInput(input);
|
||||
else {
|
||||
if (input.action !== 'set_service_state') throw new Error('SYSTEM ausschließlich für typisierte eigene Windows-Fixturedienste oder feste MSI-Rezepte; keine SYSTEM-Shell');
|
||||
validateSystemService(input.parameters.unit, input.parameters.state, input.parameters.timeout_seconds, input.parameters.max_output_bytes);
|
||||
|
||||
Reference in New Issue
Block a user