Bind approved Windows PowerShell process policy and prove Linux-first contracts
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
+36
-1
@@ -1,10 +1,45 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { actions, PlanInput, Session, request, session } from './api';
|
||||
import { adminIntent, allowed, availableActions, parseStrictJson, recipeInput, rootWarning, sha256, validateAptManifest, validateSensitiveInput, verifyAptManifest, verifyPlanIntegrity } from './safety';
|
||||
import { adminIntent, allowed, availableActions, parseStrictJson, powerShellApprovalBlockers, powerShellPlanJobs, recipeInput, rootWarning, sha256, validateAptManifest, validateSensitiveInput, verifyAptManifest, verifyPlanIntegrity } from './safety';
|
||||
import { AdminControl } from './management';
|
||||
|
||||
const auth: Session = { principal: { id: 'test', display_name: 'SIMULIERT', simulated: true }, csrf_token: 'csrf', tenants: [], permissions: ['root:execute', 'devices:revoke'] };
|
||||
describe('immutable PowerShell process profile', () => {
|
||||
async function plan(profile: unknown = 'powershell_51_remote_signed', identity = 'agent_service', interpreter = 'powershell') {
|
||||
const action = { action: 'run_script', interpreter, script_utf8: 'Write-Output 1\r\n', arguments: [], expected_stdout: '1\r\n', ...(profile === undefined ? {} : { windows_execution_profile: profile }) };
|
||||
const payload = { asset_id: 'fixed-windows', execution_identity: identity, action }, jobs = [{ asset_id: 'fixed-windows', job_payload_hash: 'a'.repeat(64), payload }];
|
||||
const plan_payload = { jobs }, raw = new TextEncoder().encode(JSON.stringify(plan_payload));
|
||||
return { plan_payload, plan_payload_bytes: Array.from(raw), plan_hash: await sha256(raw), jobs };
|
||||
}
|
||||
it('requires verified bytes, rejects all profile/view mutations and preserves inherited plans', async () => {
|
||||
const value = await plan(); expect(() => powerShellPlanJobs(value)).toThrow('nicht aus hashgeprüften');
|
||||
await verifyPlanIntegrity(value); expect(powerShellPlanJobs(value)).toEqual([{ assetId: 'fixed-windows', profile: 'powershell_51_remote_signed' }]);
|
||||
expect(powerShellApprovalBlockers(value)).toEqual([]);
|
||||
const changed = structuredClone(value); changed.jobs[0]!.payload.action.windows_execution_profile = 'Bypass';
|
||||
await expect(verifyPlanIntegrity(changed)).rejects.toThrow('widerspricht');
|
||||
const viewOnly = { ...value, jobs: [{ ...value.jobs[0]!, payload: { ...value.jobs[0]!.payload, action: { ...value.jobs[0]!.payload.action, windows_execution_profile: 'Bypass' } } }] };
|
||||
await expect(verifyPlanIntegrity(viewOnly)).rejects.toThrow('widerspricht');
|
||||
const extraAlias = { ...value, resolved_targets: value.jobs, jobs: viewOnly.jobs };
|
||||
await expect(verifyPlanIntegrity(extraAlias)).rejects.toThrow('widerspricht');
|
||||
await expect(verifyPlanIntegrity({ ...value, payloads: viewOnly.jobs })).rejects.toThrow('widerspricht');
|
||||
await expect(verifyPlanIntegrity({ ...value, payload: { jobs: viewOnly.jobs } })).rejects.toThrow('widerspricht');
|
||||
const idsOnly = { ...value, resolved_targets: ['fixed-windows'] }; await verifyPlanIntegrity(idsOnly);
|
||||
for (const alias of ['plan_payload', 'payload']) {
|
||||
const later: Record<string, unknown> = { ...value, [alias]: value.plan_payload };
|
||||
await verifyPlanIntegrity(later); later[alias] = { jobs: viewOnly.jobs };
|
||||
expect(powerShellApprovalBlockers(later).length).toBeGreaterThan(0); expect(() => powerShellPlanJobs(later)).toThrow('widerspricht');
|
||||
}
|
||||
await expect(verifyPlanIntegrity({ ...value, plan_payload_bytes: undefined })).rejects.toThrow('gespeicherte Planbytes');
|
||||
for (const profile of ['Bypass', null, {}, 'powershell_7_remote_signed']) await expect(verifyPlanIntegrity(await plan(profile))).rejects.toThrow('Windows-Ausführungsprofil');
|
||||
for (const identity of ['root', 'system']) await expect(verifyPlanIntegrity(await plan('powershell_51_remote_signed', identity))).rejects.toThrow('agent_service');
|
||||
await expect(verifyPlanIntegrity(await plan('powershell_51_remote_signed', 'agent_service', 'bash'))).rejects.toThrow();
|
||||
const inherited = await plan(undefined); delete inherited.plan_payload.jobs[0]!.payload.action.windows_execution_profile;
|
||||
const raw = new TextEncoder().encode(JSON.stringify(inherited.plan_payload)); inherited.plan_payload_bytes = Array.from(raw); inherited.plan_hash = await sha256(raw);
|
||||
await verifyPlanIntegrity(inherited); expect(powerShellPlanJobs(inherited)[0]?.profile).toBe('inherited');
|
||||
value.plan_payload_bytes[0] = 0; expect(powerShellApprovalBlockers(value).length).toBeGreaterThan(0); expect(() => powerShellPlanJobs(value)).toThrow('verändert');
|
||||
});
|
||||
});
|
||||
async function manifest(acceptance = true) {
|
||||
const transaction = { schema_version: 1, recipe_id: 'rmm-apt-fixture-install-1.0', recipe_version: '1', platform: 'ubuntu-24.04-amd64', resolver_config_version: 'rmm-apt-local-v1', no_reboot: true, status_fingerprint: 'a'.repeat(64), baseline_sha256: 'b'.repeat(64), packages: [{ name: 'rmm-mvp-test', architecture: 'all', old_version: null, new_version: '1.0', origin: 'rmm-test', sha256: '74036ae81223deab3aae994fd2a2a695af408741777e1ce17dcb4e32f1235867', size: 20672, archive_path: '/var/lib/rmm-apt-transaction/archives/74036ae81223deab3aae994fd2a2a695af408741777e1ce17dcb4e32f1235867.deb' }] };
|
||||
const raw = new TextEncoder().encode(JSON.stringify(transaction));
|
||||
|
||||
Reference in New Issue
Block a user