diff --git a/docs/windows-msi-integration.md b/docs/windows-msi-integration.md index 0d97250..fc41ae1 100644 --- a/docs/windows-msi-integration.md +++ b/docs/windows-msi-integration.md @@ -46,9 +46,35 @@ Lokaler Beleg `devstate/windows-msi-integration/local-qualification.json`, SHA256 `b7bced0a341ffb88af8b584cbe8355ff1021add541004347f609f6136a684b74`, bindet13Quelldateien. Unabhängiger Quellenreview ohne weiteren konkreten Blocker. -Weiter offen: Linux-first-Nativevertragsnachweise, getrennte WebUI-Erweiterung, +Weiter offen: Linux-first-Nativevertragsnachweise, tatsächliche WebUI-Abnahme, Windowsdownload und geschützter SYSTEM-Cache, Helper-/Runtimeverdrahtung und jeweils echte WebUI-genehmigte Installation/Upgrade/Noops. Keine Capability, Helperpolicy oder Clock-/Jobkonfiguration auf der VM wurde geöffnet. Die -bisherige UI verweigert SYSTEM-Nicht-SCM-Pläne weiterhin bis zum separaten +vorherige UI verweigerte SYSTEM-Nicht-SCM-Pläne bis zum folgenden separaten Schnitt. Quellen/Units sind keine Paketfreigabe. + +## Getrennter WebUI-Quellenschnitt + +Feste SYSTEM-MSI-Auswahl und eigener kleiner Katalogbereich implementiert; +APT bleibt getrennt. Anzeige enthält Product-/Upgrade-/gegebenenfalls1.1- +PackageCode, Version, Artifact/Rezept/Nutzdateihashes, Vorgänger, feste Argumente +und No-Reboot-/Budgetvertrag. Sie stammt aus kopierter typisierter Projection +hashgeprüfter gespeicherter Planbytes. Alle Preview-Aliase und spätere Änderungen +werden vor Anzeige sowie erneut vor Submit/Genehmigung geprüft. Keine neue +Genehmigungsabkürzung oder Policy-/Capabilityveröffentlichung. + +Rootreview fand einen echten Codecfehler: die erste UI-Fassung erwartete +`apt_manifest:null`, Rust lässt `None` tatsächlich aus. Die ursprünglichen +TS-Fixtures spiegelten diesen Fehler. Eng korrigiert: gespeicherte MSI-Actions +verlangen das fehlende Feld; nur das Formular akzeptiert fehlend/null, kein +APT-Objekt. Zwei echte, vom unveränderten Rust-Domaincodec erzeugte synthetische +PlanPayload-Goldens1.0/1.1 werden nun im bestehenden Webtest verifiziert und +gerendert. Keine Signer, realen Geräte oder Nativewirkungen in diesen Fixtures. + +Abschließend42Webtests, Typecheck und Build bestanden; fünf Webdateien und +sämtliche Webinputs vor/nach gebunden, Rust13 unverändert. Neuer privater Beleg +`devstate/windows-msi-ui/wire-fix-955acab2-35af-4507-bb2b-d7cd1fa49347/qualification.json`, +SHA256 `f84d4962ab9a6ef64ef0327fcf7c524efb0bd4064d2416f174a9dfffb524a8a1`. +Der ursprüngliche `fe02…`-Beleg bleibt historisch und ist ausdrücklich wegen +des Codecfehlers abgelöst. Kein Clouddeployment, Browser-Nativlauf, Installer- +oder tatsächlicher WebUI-Freigabenachweis durch diese Quelltests. diff --git a/web/src/api.ts b/web/src/api.ts index ac8888b..687cd37 100644 --- a/web/src/api.ts +++ b/web/src/api.ts @@ -89,6 +89,66 @@ export function validateWindowsLogLimits(identity: unknown, runtime: unknown, ou || typeof since !== 'string' || Date.parse(since) < 0) throw new Error('Windows-Fixture-Eventlog nur agent_service,10–120s und1024–65536Bytes'); } 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 } +export const windowsMsi = { + package: 'rmm-windows-msi-fixture', installRecipe: 'rmm-windows-msi-fixture-install-1.0', upgradeRecipe: 'rmm-windows-msi-fixture-upgrade-1.1', + product: '{3F070B4B-9C08-4D65-BD41-13D81B884AEC}', upgradedProduct: '{D42BD387-079B-4BBF-A134-0DA7B7A97011}', family: '{C9BF1FB8-E31D-4BD7-BA0D-AB46539BBBAA}', + payload: 'C:\\Program Files\\RustDiscoveryFixtures\\msi-payload.txt', payload10: '0c90c4fc7233017cc88c0e925095d6662ac57abdb303c7527ef59d02b454fca0', payload11: 'ba0c83deff9eed014009bcd45369b2a356ae909ebf0c1434dc836b0e6d759c49', +} as const; +export interface MsiPostcondition { product_code: string; product_version: string; payload_path: string; payload_sha256: string; payload_bytes: number } +export interface WindowsMsiRecipe { + schema_version: 1; recipe_id: string; recipe_version: '1'; platform: 'windows'; upgrade_code: string; architecture: 'x64'; context: 'machine'; command_profile: 'fixture_quiet_no_reboot_v1'; + artifact: { artifact_id: string; sha256: string; bytes: number }; postcondition: MsiPostcondition; no_reboot: true; package_code?: string; predecessor?: MsiPostcondition; +} +export interface WindowsMsiManifest { recipe: WindowsMsiRecipe; recipe_sha256: string } +function exactMsiFields(value: RecordValue, fields: string[]): void { + if (Object.keys(value).some(key => !fields.includes(key)) || fields.some(key => !Object.prototype.hasOwnProperty.call(value, key))) throw new Error('MSI-Schemafelder fehlen oder sind unbekannt'); +} +export function msiDigest(value: unknown): string { if (typeof value !== 'string' || !/^[a-f0-9]{64}$/.test(value)) throw new Error('Exakter MSI-SHA256 erforderlich'); return value; } +export function msiUuid(value: unknown): string { if (typeof value !== 'string' || !/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(value) || value === '00000000-0000-0000-0000-000000000000') throw new Error('Exakte MSI-UUID erforderlich'); return value; } +function msiInteger(value: unknown, min: number, max: number): number { if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < min || value > max) throw new Error('MSI-Limit außerhalb des festen Budgets'); return value; } +/** Reconstruct every nested object in Rust declaration order before hashing. + * No unknown properties, null options, enum objects or caller-supplied argv. + */ +export function windowsMsiManifest(value: unknown): WindowsMsiManifest { + const m = record(value, 'windows_msi_manifest'); exactMsiFields(m, ['recipe', 'recipe_sha256']); + const r = record(m.recipe, 'MSI-Rezept'), upgrade = r.recipe_id === windowsMsi.upgradeRecipe; + exactMsiFields(r, ['schema_version', 'recipe_id', 'recipe_version', 'platform', 'upgrade_code', 'architecture', 'context', 'command_profile', 'artifact', 'postcondition', 'no_reboot', ...(upgrade ? ['package_code', 'predecessor'] : [])]); + if (r.schema_version !== 1 || (!upgrade && r.recipe_id !== windowsMsi.installRecipe) || r.recipe_version !== '1' || r.platform !== 'windows' || r.upgrade_code !== windowsMsi.family || r.architecture !== 'x64' || r.context !== 'machine' || r.command_profile !== 'fixture_quiet_no_reboot_v1' || r.no_reboot !== true) throw new Error('Nur feste Windows-Machine/x64-MSI-Rezepte mit No-Reboot-Vertrag'); + const a = record(r.artifact); exactMsiFields(a, ['artifact_id', 'sha256', 'bytes']); + const post = (value: unknown): MsiPostcondition => { const p = record(value); exactMsiFields(p, ['product_code', 'product_version', 'payload_path', 'payload_sha256', 'payload_bytes']); + if (p.payload_path !== windowsMsi.payload) throw new Error('Exakter MSI-Nutzdateipfad erforderlich'); + return { product_code: text(p.product_code, 'ProductCode'), product_version: text(p.product_version, 'Produktversion'), payload_path: p.payload_path, payload_sha256: msiDigest(p.payload_sha256), payload_bytes: msiInteger(p.payload_bytes, 1, 65536) }; + }; + const p = post(r.postcondition); + if (p.product_code !== (upgrade ? windowsMsi.upgradedProduct : windowsMsi.product) || p.product_version !== (upgrade ? '1.1.0' : '1.0.0')) throw new Error('MSI-Produkt/Version widerspricht festem Rezept'); + const recipe: WindowsMsiRecipe = { schema_version: 1, recipe_id: r.recipe_id as string, recipe_version: '1', platform: 'windows', upgrade_code: windowsMsi.family, architecture: 'x64', context: 'machine', command_profile: 'fixture_quiet_no_reboot_v1', + artifact: { artifact_id: msiUuid(a.artifact_id), sha256: msiDigest(a.sha256), bytes: msiInteger(a.bytes, 1, 262144) }, postcondition: p, no_reboot: true }; + if (upgrade) { + const code = text(r.package_code, 'PackageCode'); + if (!/^\{[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}\}$/.test(code) || code === '{00000000-0000-0000-0000-000000000000}' || [windowsMsi.product, windowsMsi.upgradedProduct, windowsMsi.family].some(x => x === code)) throw new Error('Exakter eigener MSI-PackageCode erforderlich'); + const old = post(r.predecessor); + if (p.payload_sha256 !== windowsMsi.payload11 || p.payload_bytes !== 33 || old.product_code !== windowsMsi.product || old.product_version !== '1.0.0' || old.payload_sha256 !== windowsMsi.payload10 || old.payload_bytes !== 33) throw new Error('MSI1.1 benötigt exakt den bekannten1.0-Vorgänger und die feste1.1-Nutzdatei'); + recipe.package_code = code; recipe.predecessor = old; + } + return { recipe, recipe_sha256: msiDigest(m.recipe_sha256) }; +} +export function validateWindowsMsiLimits(runtime: unknown, output: unknown): void { msiInteger(runtime, 10, 120); msiInteger(output, 1024, 65536); } +/** Stored Action bytes omit apt_manifest=None; WebParameters may accept null. */ +export function windowsMsiAction(value: RecordValue): RecordValue { + exactMsiFields(value, ['action', 'provider', 'package', 'version', 'architecture', 'recipe_version', 'installation_context', 'recipe_id', 'windows_msi_manifest']); + const m = windowsMsiManifest(value.windows_msi_manifest); + if (value.action !== 'ensure_package' || value.provider !== 'msi' || value.package !== windowsMsi.package || value.version !== m.recipe.postcondition.product_version || value.architecture !== 'x64' || value.recipe_version !== m.recipe.recipe_version || value.installation_context !== 'machine' || value.recipe_id !== m.recipe.recipe_id) throw new Error('Äußere MSI-Felder widersprechen Manifest'); + return { action: 'ensure_package', provider: 'msi', package: windowsMsi.package, version: value.version, architecture: 'x64', recipe_version: m.recipe.recipe_version, installation_context: 'machine', recipe_id: m.recipe.recipe_id, windows_msi_manifest: m }; +} +export function validateWindowsMsiInput(input: PlanInput): WindowsMsiManifest { + const p = input.parameters; + exactMsiFields(p, ['execution_identity', 'timeout_seconds', 'max_output_bytes', 'provider', 'package', 'version', 'architecture', 'recipe_version', 'installation_context', 'recipe_id', 'windows_msi_manifest', ...(Object.prototype.hasOwnProperty.call(p, 'apt_manifest') ? ['apt_manifest'] : [])]); + if (input.action !== 'ensure_package' || p.execution_identity !== 'system' || (input.artifact_ids?.length ?? 0) !== 0) throw new Error('MSI ausschließlich als SYSTEM-ensure_package mit automatisch genau einem Artefakt'); + validateWindowsMsiLimits(p.timeout_seconds, p.max_output_bytes); + if (p.apt_manifest !== undefined && p.apt_manifest !== null) throw new Error('APT-Manifest bei MSI nicht zulässig'); + windowsMsiAction({ action: input.action, provider: p.provider, package: p.package, version: p.version, architecture: p.architecture, recipe_version: p.recipe_version, installation_context: p.installation_context, recipe_id: p.recipe_id, windows_msi_manifest: p.windows_msi_manifest }); + return windowsMsiManifest(p.windows_msi_manifest); +} /** Decode explicit escaped CRLF before planning; never alter approved output bytes. */ export function expectedStdout(value: string, format: string): string | null { if (value === '') return null; @@ -118,10 +178,14 @@ export function validateInput(input: PlanInput): void { } 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 !== 'set_service_state') throw new Error('SYSTEM ausschließlich für typisierte eigene Windows-Fixturedienste; keine SYSTEM-Shell'); - validateSystemService(input.parameters.unit, input.parameters.state, input.parameters.timeout_seconds, input.parameters.max_output_bytes); - if (Object.keys(input.parameters).some(k => !['execution_identity', 'unit', 'state', 'timeout_seconds', 'max_output_bytes'].includes(k))) throw new Error('SYSTEM-Dienstauftrag enthält fremde Parameter'); + 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); + if (Object.keys(input.parameters).some(k => !['execution_identity', 'unit', 'state', 'timeout_seconds', 'max_output_bytes'].includes(k))) throw new Error('SYSTEM-Dienstauftrag enthält fremde Parameter'); + } } + if (input.parameters.provider === 'msi' || Object.prototype.hasOwnProperty.call(input.parameters, 'windows_msi_manifest')) validateWindowsMsiInput(input); const required = (key: string) => text(input.parameters[key], `parameters.${key}`); if (input.action === 'refresh_inventory') required('scope'); if (input.action === 'query_logs') { diff --git a/web/src/json-view.test.tsx b/web/src/json-view.test.tsx index d26fc53..c7c5eeb 100644 --- a/web/src/json-view.test.tsx +++ b/web/src/json-view.test.tsx @@ -60,13 +60,17 @@ it('shows fixed SYSTEM identity and service state from stored plan bytes without const fetch = vi.fn(); vi.stubGlobal('fetch', fetch); vi.stubGlobal('document', { getElementById: () => ({}) }); try { const { SystemPlanNotice } = await import('./main'); - const payload = { jobs: [{ payload: { execution_identity: 'system', asset_id: 'fixed-asset', action: { action: 'set_service_state', unit: 'RmmDiscoveryFixtureService', state: 'stopped' } } }] }; - const plan = { plan_payload_bytes: Array.from(new TextEncoder().encode(JSON.stringify(payload))), jobs: [{ payload: { execution_identity: 'root', action: { unit: 'untrusted-view' } } }] }; + const payload = { jobs: [{ payload: { execution_identity: 'system', asset_id: 'fixed-asset', max_runtime_seconds: 30, max_output_bytes: 4096, action: { action: 'set_service_state', unit: 'RmmDiscoveryFixtureService', state: 'stopped' } } }] }; + const raw = new TextEncoder().encode(JSON.stringify(payload)); + const plan = { plan_payload_bytes: Array.from(raw), plan_hash: await sha256(raw), jobs: [{ payload: { execution_identity: 'root', action: { unit: 'untrusted-view' } } }] }; + expect(renderToStaticMarkup()).toContain('role="alert"'); + await verifyPlanIntegrity(plan); const html = renderToStaticMarkup(); expect(html).toContain('SYSTEM'); expect(html).toContain('system:execute'); expect(html).toContain('Identität: system'); for (const expected of ['fixed-asset', 'RmmDiscoveryFixtureService', 'Zielzustand: stopped', 'Keine SYSTEM-Shell']) expect(html).toContain(expected); expect(html).not.toContain('untrusted-view'); expect(html).not.toMatch(/<(button|input|form|pre)\b/); - expect(renderToStaticMarkup()).toBe(''); + const emptyRaw = new TextEncoder().encode('{"jobs":[]}'), empty = { plan_payload_bytes: Array.from(emptyRaw), plan_hash: await sha256(emptyRaw) }; await verifyPlanIntegrity(empty); + expect(renderToStaticMarkup()).toBe(''); for (const plan_payload_bytes of [[255], [123], 'invalid']) { const invalid = renderToStaticMarkup(); expect(invalid).toContain('role="alert"'); expect(invalid).toContain('nicht lesbar'); diff --git a/web/src/main.tsx b/web/src/main.tsx index 0d5cf86..1fcb83d 100644 --- a/web/src/main.tsx +++ b/web/src/main.tsx @@ -3,18 +3,32 @@ import { createRoot } from 'react-dom/client'; import { actions, Action, ApiError, authConfig, approvalBlockers, expectedStdout, objectId, page, Page, PlanInput, pretty, record, RecordValue, request, session, Session, stringField, tenant, tenantPath, validateInput, windowsPowerShellRemoteSignedProfile } from './api'; import './style.css'; import { AdminControl, Catalog, TenantControls } from './management'; -import { allowed, availableActions, parseStrictJson, powerShellApprovalBlockers, powerShellPlanJobs, rootWarning, systemWarning, systemPlanJobs, validateSensitiveInput, verifyPlanIntegrity, queryLogsApprovalBlockers, queryLogsPlanJobs } from './safety'; +import { allowed, availableActions, parseStrictJson, powerShellApprovalBlockers, powerShellPlanJobs, rootWarning, systemWarning, systemPlanJobs, validateSensitiveInput, verifyPlanIntegrity, queryLogsApprovalBlockers, queryLogsPlanJobs, windowsMsiApprovalBlockers, windowsMsiPlanJobs, verifyWindowsMsiManifest } from './safety'; import { Login } from './login'; const errorText = (error: unknown) => error instanceof Error ? error.message : 'Unbekannter Fehler'; export function JsonView({ value, label = 'Vollständige Daten' }: { value: unknown; label?: string }) { return
{label}
{pretty(value)}
; } export function SystemPlanNotice({ plan }: { plan: RecordValue }) { let jobs: RecordValue[]; - try { jobs = systemPlanJobs(plan); } + try { jobs = systemPlanJobs(plan).filter(p => record(p.action).action === 'set_service_state'); } catch { return ; } if (!jobs.length) return null; return ; } +export function WindowsMsiPlanNotice({ plan }: { plan: RecordValue }) { + try { + const jobs = windowsMsiPlanJobs(plan); if (!jobs.length) return null; + return ; + } catch { return ; } +} export function PowerShellPlanNotice({ plan }: { plan: RecordValue }) { try { const jobs = powerShellPlanJobs(plan); @@ -73,33 +87,57 @@ function Planner({ tenantId, auth, selected, showPlan }: { tenantId: string; aut {action === 'query_logs' &&

Windows-MVP nur Quelle windows.eventlog.application.rustdiscovery-mvp-test, Kanal Application, Provider RustDiscovery-MVP-Test, agent_service. Festes UTC-Fenster höchstens24h,1–1000Events,1024–65536Bytes,äußere Joblaufzeit10–120s; inneres kooperatives Abfragebudget höchstens5000ms. Keine freie Kanal-/XPathauswahl und keine Bookmarkfortschreibung. Linux behält seine feste Journalunit.

} {action === 'apt_native_acceptance' &&

NUR SIMULIERTE DEV/TEST-NATIVABNAHME. In Vorbereitung; Backend/Helper/Scope müssen diese eigene Aktion unterstützen. Nur rmm-apt-fixture-install-1.0 oder rmm-apt-fixture-update-1.1, Rezeptversion 1, vollständiges Schema-2-Manifest. null/Platzhalter sind nicht konfiguriert, keine Produktionsaktion, keine automatische Ausführung.

} {action === 'run_script' ? <>{scriptPlatform === 'mixed' ?