Share signed job core and verify native Linux then Windows contracts
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
+16
-4
@@ -60,6 +60,13 @@ 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 interface PlanInput { tenant_id: string; action: Action; targets: { asset_ids: string[] }; parameters: RecordValue; artifact_ids?: string[]; schedule: { not_before: string; start_before: string; offline_policy: 'wait_until_deadline' }; rollout: { max_parallel: number; halt_after_failures: number }; reason: string }
|
||||
/** Decode explicit escaped CRLF before planning; never alter approved output bytes. */
|
||||
export function expectedStdout(value: string, format: string): string | null {
|
||||
if (value === '') return null;
|
||||
const output: unknown = format === 'json' ? JSON.parse(value) : format === 'text' ? value : undefined;
|
||||
if (typeof output !== 'string' || new TextEncoder().encode(output).length > 65536) throw new Error('stdout-Nachbedingung benötigt einen String (max.64KiB UTF-8)');
|
||||
return output;
|
||||
}
|
||||
export function validateInput(input: PlanInput): void {
|
||||
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');
|
||||
@@ -68,10 +75,15 @@ export function validateInput(input: PlanInput): void {
|
||||
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 variants = input.parameters.variants;
|
||||
if (!Array.isArray(variants) || !variants.length || !variants.every(v => {
|
||||
const variant = record(v), bytes = typeof variant.script_utf8 === 'string' ? new TextEncoder().encode(variant.script_utf8).length : 0;
|
||||
return bytes > 0 && bytes <= 32768 && !String(variant.script_utf8).includes('\0') && variant.os_family === 'linux' && variant.encoding === 'utf-8' && ['posix_sh', 'bash'].includes(String(variant.interpreter));
|
||||
})) throw new Error('Exakte Linux UTF-8 Skriptbytes und Interpreter erforderlich (max. 32 KiB)');
|
||||
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 : '';
|
||||
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 (!['agent_service', 'root'].includes(String(input.parameters.execution_identity))) throw new Error('Explizite Ausführungsidentität erforderlich');
|
||||
const required = (key: string) => text(input.parameters[key], `parameters.${key}`);
|
||||
|
||||
Reference in New Issue
Block a user