feat: add registry resource type for Windows#1053
Open
Blankf wants to merge 1 commit intogoss-org:masterfrom
Open
feat: add registry resource type for Windows#1053Blankf wants to merge 1 commit intogoss-org:masterfrom
Blankf wants to merge 1 commit intogoss-org:masterfrom
Conversation
Add a new registry resource type that validates Windows registry keys
natively using the golang.org/x/sys/windows/registry API. This replaces
the need to shell out to PowerShell for registry checks, providing
significant performance improvements (0.02s vs 44s for 250 checks).
Gossfile syntax:
registry:
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName:
exists: true
value: "Windows Server 2025 Datacenter"
type: REG_SZ
For value names containing backslashes (e.g. HardenedPaths UNC entries),
use "::" as an explicit separator:
registry:
HKLM\...\HardenedPaths::\\*\NETLOGON:
exists: true
Supported hives: HKLM, HKCU, HKCR, HKU, HKCC.
Supported types: REG_SZ, REG_EXPAND_SZ, REG_DWORD, REG_QWORD,
REG_BINARY, REG_MULTI_SZ.
On non-Windows platforms, the resource returns an error indicating
it is only supported on Windows, following the NullPackage pattern.
7ac5f7b to
eb7a099
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
registryresource type that validates Windows registry keys natively using thegolang.org/x/sys/windows/registryAPI. This replaces the need to shell out to PowerShell for registry checks.Closes #616
Motivation
The ansible-lockdown Windows CIS audit repos (Windows 2016/2019/2025) currently rely entirely on the
commandresource shelling out to PowerShell for ~300+ registry checks per benchmark. This is slow (~180ms per check due to PowerShell process spawn) and verbose.With the native
registryresource, the same checks run in milliseconds via direct Windows API calls.Benchmark results (250 identical checks):
registryresourcecommand+ PowerShellGossfile syntax
For value names containing backslashes (e.g. HardenedPaths UNC entries), use
::as an explicit separator:Details
QUERY_VALUEaccess (read-only, least privilege)NullPackagepatternFiles changed
New files:
system/registry.go-- Registry interface + key path parsersystem/registry_test.go-- 17 unit tests for the parsersystem/registry_notwindows.go-- Non-Windows stubsystem/registry_windows.go-- Windows implementationresource/registry.go-- Resource type definitionintegration-tests/goss/windows/tests/registry.goss.yaml-- Integration testsdocs/windows-parity-progress.md-- Progress trackerModified files:
system/system.go-- AddedNewRegistryfactoryresource/resource_list_genny.go+resource/resource_list.go-- Added RegistryMapgoss_config.go-- Wired into configadd.go-- Added to AddResource switchcmd/goss/goss.go-- Added CLI subcommanddocs/schema.yaml-- Added schema definitiondocs/platforms.md-- Updated platform matrixTest plan
go vet ./...passesgo test ./...passes (17 new parser tests + all existing)GOOS=windows GOARCH=amd64 go buildcross-compiles successfullygosec ./system/ ./resource/-- zero findings in new codecommandresource still works