diff --git a/CHANGELOG.md b/CHANGELOG.md index fd4e54f..613b3e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Releases are tagged `vX.Y.Z` and published with a zip and a SHA256 checksum. ### Fixed +- ♻️ **Enable repairs "do not overwrite" retention.** Test failed a kit log set to "do not overwrite events" (logging stops when it fills), but nothing fixed it. Enable now switches such a log to overwrite as needed, with a warning in case it was kept that way on purpose, and records the original mode so `-Rollback` restores it; rollback copies from earlier versions gain the mode on the next run. "Archive when full" is left alone. [#73](https://github.com/spydisec/WinLogKit/issues/73) - 🔢 **SMB audit event numbers corrected.** The settings table had signing and encryption swapped: per the SMB providers' own event definitions, 3021 / 31998 are signing and 3022 / 31999 encryption. The Reference page and the Safety FAQ now match, and the SMB settings are described as Windows 11 24H2 / Server 2025 and later rather than Server 2025 only. [#72](https://github.com/spydisec/WinLogKit/issues/72) - 🧯 **Failed log changes are reported as failures.** Enable sent `wevtutil` output to nowhere and never checked its exit code, so a log resize or enable that failed was reported as Changed (and `-Rollback` had the same gap). It now reports an Error with `wevtutil`'s own message and exits non-zero. [#70](https://github.com/spydisec/WinLogKit/issues/70) @@ -46,6 +47,7 @@ Simpler fleet delivery, documented setting by setting: Intune through the Settin ### Fixed +- ♻️ **Enable repairs "do not overwrite" retention.** Test failed a kit log set to "do not overwrite events" (logging stops when it fills), but nothing fixed it. Enable now switches such a log to overwrite as needed, with a warning in case it was kept that way on purpose, and records the original mode so `-Rollback` restores it; rollback copies from earlier versions gain the mode on the next run. "Archive when full" is left alone. [#73](https://github.com/spydisec/WinLogKit/issues/73) - 🌍 **Verification works in any Windows language.** Test and Enable read audit policy from `auditpol /backup`'s numeric setting values instead of the `auditpol /get` text, which is translated on non-English Windows (only English said "Success and Failure"), so a correctly configured non-English host no longer fails its audit checks or gets re-applied on every run. [#45](https://github.com/spydisec/WinLogKit/issues/45) - ↩️ **Rollback covers settings added by later versions.** The rollback copy is taken on the first run, so a setting added by a later kit version, like the PowerShell 7 ones, was left behind by `-Rollback`. Every later run now records any setting the copy doesn't know yet, in its current state, before changing anything. [#44](https://github.com/spydisec/WinLogKit/issues/44) @@ -98,6 +100,7 @@ A scope reset ([ADR-002](docs/adr/0002-scope-and-simplification.md)): WinLogKit ### Fixed +- ♻️ **Enable repairs "do not overwrite" retention.** Test failed a kit log set to "do not overwrite events" (logging stops when it fills), but nothing fixed it. Enable now switches such a log to overwrite as needed, with a warning in case it was kept that way on purpose, and records the original mode so `-Rollback` restores it; rollback copies from earlier versions gain the mode on the next run. "Archive when full" is left alone. [#73](https://github.com/spydisec/WinLogKit/issues/73) - 🏷️ **Reference labels for the former Optional items.** Moving IPsec Driver and the DPAPI debug channel to HighVolume had relabelled them as high volume and as part of Yamato's set; they are back to their 1.0.0 labels. [#54](https://github.com/spydisec/WinLogKit/pull/54) - 🧪 **Self-checks run from the release zip.** The zip ships `tests\` but not `docs\`, so the Reference page drift check failed there; it now skips with a message when `docs\` is absent. [#54](https://github.com/spydisec/WinLogKit/pull/54) - 🔐 **Security policy scope.** SECURITY.md no longer lists a download path that doesn't exist, and says plainly that the scripts make no outbound requests while the WEF subscription you deploy forwards events by design. [#54](https://github.com/spydisec/WinLogKit/pull/54) @@ -172,6 +175,7 @@ The 1.0 restructure ([ADR-001](docs/adr/0001-v1-layout.md)): a docs cut, one cop ### Fixed +- ♻️ **Enable repairs "do not overwrite" retention.** Test failed a kit log set to "do not overwrite events" (logging stops when it fills), but nothing fixed it. Enable now switches such a log to overwrite as needed, with a warning in case it was kept that way on purpose, and records the original mode so `-Rollback` restores it; rollback copies from earlier versions gain the mode on the next run. "Archive when full" is left alone. [#73](https://github.com/spydisec/WinLogKit/issues/73) - 🛡️ **Registry writes can't wipe sibling values.** After reviewing an upstream WELA bug where `New-Item -Force` wiped existing registry values, every kit registry write goes through `Registry::SetValue`, and a CI check keeps it that way. The WELA download was also made forward-compatible. [#19](https://github.com/spydisec/WinLogKit/pull/19) ## [0.7.0] - 2026-08-31 @@ -191,6 +195,7 @@ The 1.0 restructure ([ADR-001](docs/adr/0001-v1-layout.md)): a docs cut, one cop ### Fixed +- ♻️ **Enable repairs "do not overwrite" retention.** Test failed a kit log set to "do not overwrite events" (logging stops when it fills), but nothing fixed it. Enable now switches such a log to overwrite as needed, with a warning in case it was kept that way on purpose, and records the original mode so `-Rollback` restores it; rollback copies from earlier versions gain the mode on the next run. "Archive when full" is left alone. [#73](https://github.com/spydisec/WinLogKit/issues/73) - 📦 **Release zip contents.** The zip left out `data\`, `presets\`, `tools\` and `tests\`, so coverage and presets failed from a zip install; it now carries them. [#12](https://github.com/spydisec/WinLogKit/pull/12) ## [0.5.0] - 2026-08-31 @@ -221,6 +226,7 @@ The 1.0 restructure ([ADR-001](docs/adr/0001-v1-layout.md)): a docs cut, one cop ### Fixed +- ♻️ **Enable repairs "do not overwrite" retention.** Test failed a kit log set to "do not overwrite events" (logging stops when it fills), but nothing fixed it. Enable now switches such a log to overwrite as needed, with a warning in case it was kept that way on purpose, and records the original mode so `-Rollback` restores it; rollback copies from earlier versions gain the mode on the next run. "Archive when full" is left alone. [#73](https://github.com/spydisec/WinLogKit/issues/73) - 🔧 **Field-test fixes.** WELA staging, DevSkim TLS alerts, and a baseline tree view in the builder. [#4](https://github.com/spydisec/WinLogKit/pull/4) ## [0.2.0] - 2026-08-31 diff --git a/Enable-LoggingBaseline.ps1 b/Enable-LoggingBaseline.ps1 index 27bbefa..0141561 100644 --- a/Enable-LoggingBaseline.ps1 +++ b/Enable-LoggingBaseline.ps1 @@ -235,10 +235,16 @@ try { try { $log = Get-WinEvent -ListLog $ch.Name -ErrorAction SilentlyContinue if ($null -eq $log) { Add-Result 'Channel' $ch.Name 'NotApplicable' 'Channel no longer present'; continue } - if ($PSCmdlet.ShouldProcess($ch.Name, "Restore size=$($ch.MaximumSizeInBytes) enabled=$($ch.IsEnabled)")) { + # The kit only ever changes retention from Retain to circular (#73), + # so Retain is the one mode to put back; older baselines have no + # LogMode and leave retention alone. + $restoreRetain = ($ch.PSObject.Properties.Name -contains 'LogMode' -and $ch.LogMode -eq 'Retain') + if ($PSCmdlet.ShouldProcess($ch.Name, "Restore size=$($ch.MaximumSizeInBytes) enabled=$($ch.IsEnabled)$(if ($restoreRetain) { ' retention=Retain' })")) { $enabledText = 'false'; if ($ch.IsEnabled) { $enabledText = 'true' } - Invoke-Wevtutil @('sl', $ch.Name, "/ms:$($ch.MaximumSizeInBytes)", "/e:$enabledText") - Add-Result 'Channel' $ch.Name 'Changed' "Restored to $([math]::Round($ch.MaximumSizeInBytes/1MB)) MB, enabled=$($ch.IsEnabled)" + $wevArgs = @('sl', $ch.Name, "/ms:$($ch.MaximumSizeInBytes)", "/e:$enabledText") + if ($restoreRetain) { $wevArgs += '/rt:true' } + Invoke-Wevtutil $wevArgs + Add-Result 'Channel' $ch.Name 'Changed' "Restored to $([math]::Round($ch.MaximumSizeInBytes/1MB)) MB, enabled=$($ch.IsEnabled)$(if ($restoreRetain) { ', retention=Retain' })" } } catch { Add-Result 'Channel' $ch.Name 'Error' $_.Exception.Message; $exitCode = 1 } } @@ -290,7 +296,7 @@ try { foreach ($ch in $script:BaselineChannels) { $log = Get-WinEvent -ListLog $ch.Name -ErrorAction SilentlyContinue if ($null -ne $log) { - $chState += @{ Name = $ch.Name; MaximumSizeInBytes = $log.MaximumSizeInBytes; IsEnabled = $log.IsEnabled } + $chState += @{ Name = $ch.Name; MaximumSizeInBytes = $log.MaximumSizeInBytes; IsEnabled = $log.IsEnabled; LogMode = "$($log.LogMode)" } } } @@ -358,9 +364,20 @@ try { $newCh = @($now.Channels | Where-Object { -not $known.ContainsKey(("C|$($_.Name)").ToUpper()) } | ForEach-Object { $_.AddedUtc = $addedUtc; $_ }) $newSmb = @($now.SmbAudit | Where-Object { -not $known.ContainsKey(("S|$($_.Id)").ToUpper()) } | ForEach-Object { $_.AddedUtc = $addedUtc; $_ }) $count = $newReg.Count + $newCh.Count + $newSmb.Count - if ($count -eq 0) { return 0 } $smbOld = @(); if ($first.PSObject.Properties.Name -contains 'SmbAudit') { $smbOld = @($first.SmbAudit | Where-Object { $null -ne $_ }) } $chOld = @(); if ($first.PSObject.Properties.Name -contains 'Channels') { $chOld = @($first.Channels | Where-Object { $null -ne $_ }) } + # Baselines from before #73 have no retention mode. Earlier versions + # never changed it, so the current mode is the pre-kit mode: record it + # so -Rollback can restore a Retain log the kit makes circular. + $nowCh = @{}; foreach ($c in @($now.Channels)) { $nowCh[$c.Name.ToUpper()] = $c } + $backfilled = 0 + foreach ($c in $chOld) { + if ($c.PSObject.Properties.Name -notcontains 'LogMode' -and $nowCh.ContainsKey($c.Name.ToUpper())) { + $c | Add-Member -NotePropertyName LogMode -NotePropertyValue $nowCh[$c.Name.ToUpper()].LogMode + $backfilled++ + } + } + if ($count + $backfilled -eq 0) { return 0 } $json = @{ CapturedUtc = $first.CapturedUtc Host = $first.Host @@ -447,8 +464,12 @@ try { $needSize = ($log.MaximumSizeInBytes -lt $ch.TargetBytes) # only ever raise, never shrink $needEnable = ($ch.MustEnable -and -not $log.IsEnabled) + # "Do not overwrite events" stops logging when the log fills, and Test + # fails it (#73). Only Retain is changed: AutoBackup keeps logging by + # archiving full logs, which is a deliberate choice. + $needCircular = ("$($log.LogMode)" -eq 'Retain') - if (-not $needSize -and -not $needEnable) { + if (-not $needSize -and -not $needEnable -and -not $needCircular) { Add-Result 'Channel' $ch.Name 'AlreadyCorrect' "$([math]::Round($log.MaximumSizeInBytes/1MB)) MB, enabled=$($log.IsEnabled)" continue } @@ -456,12 +477,17 @@ try { $desc = @() if ($needSize) { $desc += "size $([math]::Round($log.MaximumSizeInBytes/1MB)) MB -> $([math]::Round($ch.TargetBytes/1MB)) MB" } if ($needEnable) { $desc += 'enable (currently disabled)' } + if ($needCircular) { $desc += 'retention "do not overwrite" -> overwrite as needed' } $descText = $desc -join ', ' if ($PSCmdlet.ShouldProcess($ch.Name, $descText)) { try { if ($needSize) { Invoke-Wevtutil @('sl', $ch.Name, "/ms:$($ch.TargetBytes)") } if ($needEnable) { Invoke-Wevtutil @('sl', $ch.Name, '/e:true') } + if ($needCircular) { + Invoke-Wevtutil @('sl', $ch.Name, '/rt:false') + Write-Host " $($ch.Name) was set to 'do not overwrite' (logging stops when full). Now overwrites the oldest events; -Rollback restores it. If it was kept that way on purpose for archiving, set it back and exclude this log." -ForegroundColor Yellow + } Add-Result 'Channel' $ch.Name 'Changed' $descText } catch { Add-Result 'Channel' $ch.Name 'Error' $_.Exception.Message; $exitCode = 1 } } else { diff --git a/Test-LoggingBaseline.ps1 b/Test-LoggingBaseline.ps1 index ada5211..4661197 100644 --- a/Test-LoggingBaseline.ps1 +++ b/Test-LoggingBaseline.ps1 @@ -150,7 +150,7 @@ foreach ($ch in $script:BaselineChannels) { $problems = @() if ($ch.MustEnable -and -not $log.IsEnabled) { $problems += 'disabled' } if ($log.MaximumSizeInBytes -lt $ch.TargetBytes) { $problems += "size $actualMB MB below target $targetMB MB" } - if ($log.LogMode -eq 'Retain') { $problems += 'retention set to "do not overwrite" - log will stop recording when full' } + if ($log.LogMode -eq 'Retain') { $problems += 'retention set to "do not overwrite" - log will stop recording when full (Enable-LoggingBaseline.ps1 sets it to overwrite as needed)' } $actual = "enabled=$($log.IsEnabled), $actualMB MB, mode=$($log.LogMode)" if ($problems.Count -eq 0) { diff --git a/docs/commands.md b/docs/commands.md index 546a332..81680a0 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -36,7 +36,11 @@ left alone; log sizes are only ever raised. - Checks disk space first: whether the selected logs, once full at their new maximum sizes, still leave enough free space on their drive (warns only; see [Disk space](safety.md#disk-space)). -- First real run captures the rollback baseline; `-Rollback` restores it. +- A kit log set to "do not overwrite" (logging stops when it fills) is + switched to overwrite as needed, with a warning; "archive when full" is + left alone. +- First real run captures the rollback baseline; `-Rollback` restores it, + including a log's original "do not overwrite" setting. - Never reboots, never restarts services; the one setting needing a service restart (AD CS AuditFilter) is set with a warning and left to your change window. diff --git a/docs/safety.md b/docs/safety.md index 0236f77..45bc939 100644 --- a/docs/safety.md +++ b/docs/safety.md @@ -12,7 +12,7 @@ kit never touches them, in any mode: | Never touched | Why | |---|---| | `CrashOnAuditFail` ("Audit: Shut down system immediately if unable to log security audits") | A full Security log **halts the machine** with `STOP C0000244`; until reset, only Administrators can log on - IIS fails, AD replication fails. ([Microsoft KB832981](https://learn.microsoft.com/troubleshoot/developer/webapps/iis/health-diagnostic-performance/users-cannot-access-web-sites-when-log-full)) The test **fails** if another policy has turned it on. | -| "Do not overwrite events" retention | Logging silently stops when the log fills; with CrashOnAuditFail it crashes the host. The test **fails** this mode wherever found. | +| "Do not overwrite events" retention | Logging silently stops when the log fills; with CrashOnAuditFail it crashes the host. The test **fails** this mode on the kit's logs, and Enable sets them back to overwrite as needed, with a warning (`-Rollback` restores the original). | | Global object access auditing | SACLs on every kernel/file/registry object - extreme volume, measurable performance degradation. | | Blanket File System / Registry SACLs | A careless wildcard SACL can bury a file server. Scoping SACLs is a design decision, never a default. | | Shrinking logs, rebooting, restarting services | Sizes are only raised; the one restart-requiring setting (AD CS AuditFilter) is set with a warning and left to your change window. | diff --git a/tests/Kit.Tests.ps1 b/tests/Kit.Tests.ps1 index 3f4e58c..e232a83 100644 --- a/tests/Kit.Tests.ps1 +++ b/tests/Kit.Tests.ps1 @@ -424,6 +424,24 @@ Describe 'Rollback baseline' { @($After.Registry).Count | Should -Be @($AllState.Registry).Count } + # #73: baselines from before retention repair have no LogMode. + It 'backfills retention mode into older baselines without counting it as new settings' { + $oldJson = Join-Path $Tmp 'first-run-old.json' + @{ CapturedUtc = '2026-01-01T00:00:00'; Host = 'check' + Channels = @($AllState.Channels | ForEach-Object { @{ Name = $_.Name; MaximumSizeInBytes = $_.MaximumSizeInBytes; IsEnabled = $_.IsEnabled } }) + Registry = $AllState.Registry; SmbAudit = $AllState.SmbAudit } | ConvertTo-Json -Depth 5 | Set-Content -Path $oldJson -Encoding UTF8 + Add-NewItemsToFirstRun -Path $oldJson | Should -Be 0 + $filled = Get-Content $oldJson -Raw | ConvertFrom-Json + @($filled.Channels | Where-Object { $_.PSObject.Properties.Name -notcontains 'LogMode' }) | Should -BeNullOrEmpty + @($AllState.Channels).Count | Should -BeGreaterThan 0 + } + + It 'only ever makes retention circular, and restores Retain only on rollback' { + $src = Get-Content (Join-Path $KitRoot 'Enable-LoggingBaseline.ps1') -Raw + ([regex]::Matches($src, "'/rt:false'")).Count | Should -Be 1 + ([regex]::Matches($src, "'/rt:true'")).Count | Should -Be 1 + $src | Should -Match '\$restoreRetain\) \{ \$wevArgs \+= ''/rt:true''' + } It 'swaps the file in with a .bak kept and no .tmp left' { "$FirstJson.bak" | Should -Exist "$FirstJson.tmp" | Should -Not -Exist