Commit Graph

18 Commits

Author SHA1 Message Date
Oliver Kieselbach e88c825b56 feat(agent,rules): VM detection on hardware_spec + ANALYZE-SEC-001 skip on VMs
Adds a coarse virtual-machine flag to every hardware_spec event so the rule
engine's preconditions feature can filter device-specific rules. Wires the
new flag into ANALYZE-SEC-001 (Secure Boot UEFI CA 2023): the rule no longer
fires on Hyper-V / VMware / VirtualBox / Xen / QEMU / Parallels / KVM
guests, where the firmware DB is host-controlled and the inside-the-VM
UEFICA2023Status registry value is not actionable.

Agent (V1 + V2)
- Centralized VM detection in DeviceInfoProvider.IsVirtualMachine(mfr, model)
  alongside the existing GetManufacturer / GetModel helpers (which already
  handle Lenovo's Win32_ComputerSystemProduct.Version quirk). Reused, not
  duplicated — same source of truth as SessionRegistration / DiagnosticsPackage
  / GatherRulesMode.
- New CollectSystemInfo step in DeviceInfoCollector.HardwareSpec emits
  systemManufacturer, systemModel, isVirtualMachine onto the hardware_spec
  event. No new WMI query — calls into DeviceInfoProvider.
- Conservative bias: Microsoft Corporation manufacturer is shared between
  Hyper-V VMs and physical Surface devices, disambiguated via model
  ("Virtual Machine" → VM, "Surface Laptop 5" → physical).

Rule
- ANALYZE-SEC-001 gains a precondition (equals isVirtualMachine=false) and
  bumps to v1.1.0 so EnsureBuiltInRulesSeededAsync re-saves it for tenants
  on next backend cold start.
- Old agents (no isVirtualMachine field on hardware_spec) → fail-closed →
  rule is silently skipped on those devices until the agent updates. Safe
  default for a security rule.

Tests
- DeviceInfoProviderVmDetectionTests (V1 + V2 mirror, 18 cases each):
  Hyper-V / Cloud PC / VMware / VirtualBox / Xen / QEMU / Parallels / KVM
  positive + Surface Laptop/Pro/Book + Lenovo / Dell / HP negative + null/empty
  edge cases. Pinned at the central DeviceInfoProvider so all consumers benefit.
- 781/781 backend, 525/525 V1 agent, 800/800 V2 agent.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 23:35:00 +02:00
Oliver Kieselbach bba5761d14 refactor(v2): app_tracking_summary back to flat V1 schema
V2 had drifted to a renamed bucket schema (installedApps/failedApps/...)
plus nested perApp/byPhase. The nested objects were dead — no Web
component or rule consumed them — and the renamed counters needed a
fallback chain in every reader. Single flat schema is simpler:

- Builder rewritten to emit only the flat V1 keys: installed/failed/
  skipped/postponed (final), downloading/installing/pending (live),
  errorCount/deviceErrors/userErrors/hasErrors/isAllCompleted/
  ignoredCount (aggregate helpers), plus name lists per bucket
  (installedNames/failedNames/skippedNames/postponedNames/pendingNames).
  perApp + byPhase removed. The includePerAppDetail flag is gone — all
  emits ship the same shape (live snapshots stay cheap because the
  names lists are short strings, not per-app timing objects).

- ignoredCount needed a separate accessor: it lives on the live
  AppPackageStateList, not on the deduped phase-snapshot+live union
  used by the termination accessor. New ImeIgnoredCount property on
  DefaultComponentFactory + ignoredCountAccessor parameter on
  EnrollmentTerminationHandler.ctor (default () => 0 keeps existing
  test rigs unaffected).

- ANALYZE-APP-007.dataField back to errorCount (flat), dist regenerated.

- Web hooks (useSessionDerivedData, useProgressDerivedData) drop the
  V2 fallback chain — single-schema reads only.

- Tests rewritten for V1 schema: counter validation, device/user
  error split, hasErrors/isAllCompleted bool helpers, name-list
  population per bucket. EnrollmentTerminationHandlerTests collapsed
  the three V2-perApp tests into one V1-counts+split-errors test;
  per-app timing detail now lives only in FinalStatusBuilder /
  final-status.json, not in the event payload.

Per-transition emit cadence and ImmediateUpload=false on live
snapshots are unchanged from the previous commit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 22:39:09 +02:00
Oliver Kieselbach d295eea390 fix(rules): align ANALYZE-APP-007 + SEC-001 with V2 emit + flat data lookup
ANALYZE-APP-007: dataField errorCount -> failedApps. V1 emitted errorCount
in app_tracking_summary; V2 emits failedApps. Pulling the rule to V2-naming
removes the V1-compat alias debt from the agent.

ANALYZE-SEC-001: drop the data. prefix from dataField. RuleEngine's
GetDataFieldValue does flat dictionary lookup; the data. prefix matched
nothing under V1 or V2. Both V1 and V2 emit uefiCA2023Status /
uefiSecureBootEnabled at the root of Data, so the rule was a long-standing
no-match.

Regenerated rules/dist/analyze-rules.json from the source files via
rules/scripts/combine.js.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 21:55:05 +02:00
Oliver Kieselbach 45edbab0e1 feat: enhanced analyze rule engine (in not_in support) MarkSessionAsFailed support, new ESP rule for cert errors 2026-04-14 21:46:20 +02:00
Oliver Kieselbach 625809423f Better app failure detection and reporting 2026-04-10 18:12:30 +02:00
Oliver Kieselbach 0976a6e45e new template analyze rule fix 2026-04-03 20:05:19 +02:00
Oliver Kieselbach ed0e19fa36 added template vars to analyze rules for better user journey 2026-04-03 19:52:58 +02:00
Oliver Kieselbach f6ed4660d1 agent: secureboot certs incl. analyze rule, timezone auto set, NTP offset check 2026-03-26 09:23:12 +01:00
Oliver Kieselbach f977f7a31c debounce esp_provisioning_status, re-check vulnerabilities, save button fixes, rule engine fix min one condition required 2026-03-20 22:43:58 +01:00
Oliver Kieselbach 709905fac9 fix rule 2026-03-20 14:56:10 +01:00
Oliver Kieselbach dc3a3a5923 added security category to rule schema 2026-03-20 14:49:47 +01:00
Oliver Kieselbach 26e5925672 feat: Software Inventory Analyzer with Vulnerability Correlation 2026-03-20 14:43:58 +01:00
Oliver Kieselbach 767b2d7807 changed link reference in admin analyze 2026-03-18 11:17:08 +01:00
Oliver Kieselbach 1bb0aea6c3 fix admin analyze rule 2026-03-18 11:06:09 +01:00
Oliver Kieselbach 09998249fa added local admin analyze rule, 2026-03-18 10:57:04 +01:00
Oliver Kieselbach 4dc61b4728 fix IsDeviceOnlyDeployment completion event, added community rules 2026-03-17 22:31:49 +01:00
Oliver Kieselbach ae47161be5 fix summary cleanup, added old OS warning analyze rule 2026-03-09 17:49:55 +01:00
Oliver Kieselbach 1f796bf6e3 feat: externalize rules to GitHub + API consolidation + preview mode
## Rules as GitHub single source of truth
- Add 75 individual JSON rule files (2 gather, 18 analyze, 55 IME patterns)
  under rules/gather/, rules/analyze/, rules/ime-log-patterns/
- Add JSON Schemas for all three rule types with VS Code IntelliSense support
- Add CI combine script (rules/scripts/combine.js) + GitHub Action that
  validates schemas with ajv-cli and generates rules/dist/ combined files
- Convert BuiltIn*.cs from hardcoded C# objects to embedded JSON resource loaders
- Add GitHubRuleRepository service to fetch dist/ files from raw.githubusercontent.com
- Add ReseedFromGitHubFunction: POST /api/rules/reseed-from-github?type=all|gather|analyze|ime

## IME Log Patterns
- Extend ImeLogPattern model with Description and IsBuiltIn properties
- Add ImeLogPatterns table + API constants
- Add TableStorageService CRUD methods for IME log patterns
- Add ImeLogPatternService (CRUD, merge, auto-seed from embedded JSON)
- Add ImeLogPatternsFunction: GET/PUT /api/rules/ime-log-patterns (Phase 1: read-only
  for tenants, Galactic Admin can enable/disable/edit globally)
- Add IME Log Patterns management page (/ime-log-patterns)
- Wire GetAgentConfigFunction to use ImeLogPatternService instead of static class

## API route consolidation
- All rule endpoints now under /api/rules/* for single certificate exclusion path:
  /api/rules/gather, /api/rules/analyze, /api/rules/ime-log-patterns,
  /api/rules/reseed-from-github

## Export buttons
- Add per-rule and export-all JSON download buttons to gather-rules,
  analyze-rules, and ime-log-patterns pages

## Admin configuration
- Replace old individual reseed buttons with unified "Fetch & Reseed from GitHub"
  (calls new GitHub endpoint) plus compact individual-type reseed buttons
- Add CDN cache hint: GitHub raw.githubusercontent.com caches up to 5 minutes

## Preview mode
- ?preview=1 URL param seeds localStorage.previewMode (persists across navigation)
- ?preview=0 clears it; toggle in Navbar settings dropdown (indigo, eye icon)
- IME Log Patterns nav link gated behind galacticAdminMode OR previewMode
- Preview badge shown on nav link when active for normal users

## Tests
- Add xUnit test project (net8.0) with 5 tests for embedded resource loading,
  known IME actions validation, and valid categories check

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 13:12:09 +01:00