Skip to content

Harden state integrity: Dry-Run rollback, profile import, batch apply (v1.121.11)#79

Merged
TheAbider merged 1 commit into
masterfrom
fix/state-integrity-hardening
Jul 1, 2026
Merged

Harden state integrity: Dry-Run rollback, profile import, batch apply (v1.121.11)#79
TheAbider merged 1 commit into
masterfrom
fix/state-integrity-hardening

Conversation

@TheAbider

Copy link
Copy Markdown
Owner

Fixes from an adversarial audit of the Dry-Run engine, configuration-profile import/export, and the batch (scripted) apply. Verified findings only; 1 finder finding was refuted and dropped.

Dry-Run (70-DryRun.ps1)

  • Rolled-back atomic commit no longer silently drops changes (HIGH). After a mid-commit failure, Invoke-DryRunCommitAtomic correctly reverses the applied steps — but left them Status = "Applied", so a retry's Status -ne "Applied" filter skipped them (and the queue view rendered them green [A]). The reverted steps are now reset to Queued, so a retry re-applies them instead of reporting "all steps applied" with changes missing.

Config profile import / export (45-ConfigExport.ps1)

  • Network apply can't strand a host with no IPv4 (HIGH). Both the profile-import network step and the drift-remediation IP fix removed the current address/route before adding the new one, with no rollback — a failed New-NetIPAddress (duplicate IP, off-subnet gateway) left the box with no IPv4 and no gateway. They now capture the prior IP + gateway and restore it on failure, then re-throw so the outer handler still logs it.
  • Declining one step no longer aborts the whole import (MED). A bare return on the network-reconfig decline (and on an invalid domain name) skipped every remaining step and the summary. Now scoped to skip just that step.
  • Export no longer fabricates a DNS server (MED). With no source DNS it wrote 8.8.8.8; it now leaves DNS null (like Hostname/IP/Gateway), and import skips DNS when null.
  • Text export uses -ErrorAction Stop (LOW) so a truncated write isn't renamed into place and reported as success.

Batch apply (50-EntryPoint.ps1 + 14-WindowsUpdates.ps1)

  • Shared-storage honors its boolean result (HIGH) — a refused/failed Initialize-StorageBackendBatch was counted as an applied change.
  • Windows-Updates checks a status flag (MED)Install-WindowsUpdates signals no-network/gallery/scan failure by return (not throw), so the batch was counting a failed run as applied. It now reads $script:LastWindowsUpdateStatus.
  • Power-plan failure counts as an error, not a skip (LOW) (the summary/exit code derive success from $errors).
  • DNS-only fast path registers an undo (LOW) so 'Undo all reversible changes' restores DNS.

Verification

  • New Section 198 (14 asserts) + widened one distance-tight pre-existing remediation assertion.
  • Structural 5332/5332; full Pester 312/312; PSSA 0. Monolithic rebuilt, parse check passed. Version → 1.121.11.

… (v1.121.11)

Fixes from an adversarial audit of the Dry-Run engine, config-profile import/export,
and the batch (scripted) apply.

70-DryRun.ps1:
- Atomic rollback now resets each reverted step to Queued. It was left "Applied",
  so a retry's pending filter skipped it (and the queue view showed it green) --
  silently dropping rolled-back changes while reporting "all steps applied".

45-ConfigExport.ps1:
- Profile-import + drift-remediation network apply capture the prior IP/gateway and
  restore them if New-NetIPAddress fails, instead of leaving the host with no IPv4
  address / default route (remote box drops off the network, no in-band recovery).
- Declining the network sub-step (or an invalid domain name) skips only that step
  and continues; a bare return previously aborted the entire profile import.
- Export leaves DNS null when the source has none rather than fabricating 8.8.8.8;
  import skips DNS when null.
- Interactive text export write uses -ErrorAction Stop (no truncated-file success).

50-EntryPoint.ps1 (batch) + 14-WindowsUpdates.ps1:
- Batch shared-storage honors Initialize-StorageBackendBatch's boolean result.
- Batch Windows-Updates checks a status flag (Install-WindowsUpdates returns, not
  throws, on no-network/gallery/scan failure) instead of always counting success.
- Batch power-plan failure counts as an error, not a skip.
- Batch DNS-only fast path registers a DNS-restore undo entry.

Tests: Section 198 (14 asserts) + widened one distance-tight remediation assertion.
Structural 5332/5332; full Pester 312/312; PSSA 0. Version stamps -> 1.121.11.
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@TheAbider TheAbider merged commit 89473b8 into master Jul 1, 2026
7 checks passed
@TheAbider TheAbider deleted the fix/state-integrity-hardening branch July 1, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant