Skip to content

zero doctor saves a Windows capability SID for every new directory, and its tests write the real sandbox home #1233

Open

Description

@Vasanthdev2004

Summary

On Windows, zero doctor saves a new entry in windows-cap-sids.json for the directory it runs in, although it is only validating the sandbox setup marker. The doctor tests in internal/cli run it from a fresh temp directory with the sandbox home resolved from the real environment, so every run of the suite appends to the developer's real %USERPROFILE%\.config\zero\windows-cap-sids.json.

Reproduction

main at 8288ae81, Windows 11, restricted-token backend with setup already done.

  1. Count the keys under workspaceByRoot in %USERPROFILE%\.config\zero\windows-cap-sids.json.
  2. go test ./internal/cli -run 'TestRunDoctorFormatsRedactedProviderDiagnostics$' -count=1
  3. Count again.

Here it went from 4010 to 4011 and the file grew by 96 bytes. The new key is the test's temp directory.

That file on my machine now holds 4,011 workspace roots and is 710 KB. About 3,350 of them are temp directories from six doctor tests, 550 to 570 each: TestRunDoctorConnectivityProbesProvider, TestRunDoctorConnectivityReportsProviderHealthFailure, TestRunDoctorConnectivityDoesNotMaskConfigHealthFailure, TestRunDoctorFormatsRedactedProviderDiagnostics, TestRunDoctorJSONReturnsFailureForMissingProvider and TestRunDoctorReportsConfigValidationForMalformedFile.

Cause

  • windowsSandboxSetupCheck in internal/doctor/hardening.go resolves the sandbox home with sandbox.ResolveWindowsSandboxHome(nil), which reads the process environment, and then calls sandbox.ValidateWindowsSandboxSetupMarker.
  • Validation builds the expected marker with BuildWindowsSandboxSetupMarker. That derives the capability SIDs for the workspace through WindowsWorkspaceCapabilitySID, which generates a SID for any root it has not seen and writes the whole file back.
  • internal/doctor/hardening_test.go sets ZERO_WINDOWS_SANDBOX_HOME to a temp directory for its own tests. The internal/cli doctor tests use t.TempDir() as the working directory and do not, so each run is a root the real file has never seen.

Why it matters

  • Tests must not write the developer's real config directory. Test suite is not hermetic: config, cache and home dirs leak into tests #1103 closed that class in general; this path is still open on Windows.
  • Outside tests, a diagnostic command changes persistent state: running zero doctor once in a directory leaves a capability entry for it. Nothing removes entries, and the file is loaded on every sandboxed launch.

Suggested direction

  • Validation should look a root up, not create it. A root with no entry cannot match the recorded ACL plan anyway, so "setup is missing or out of date" is already the right answer for it.
  • Redirect the sandbox home in the internal/cli doctor tests, or pass the environment into windowsSandboxSetupCheck so the test's own environment decides. A test that fails when the real sandbox home is touched would keep it closed.
  • Pruning entries whose root no longer exists is a separate question and could wait.

#808 and #901 both rework this part of the sandbox, so the fix is easiest after they land. I can take it then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions