vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
| 1 | //go:build windows |
| 2 | |
| 3 | package audit |
| 4 | |
| 5 | // The unix tests assert the log's mode and uid; this one asserts the access list |
| 6 | // that replaces them, and runs on a real Windows machine rather than in CI: |
| 7 | // |
| 8 | // GOOS=windows go test ./internal/audit |
| 9 | |
| 10 | import ( |
| 11 | "os" |
| 12 | "path/filepath" |
| 13 | "runtime" |
| 14 | "testing" |
| 15 | |
| 16 | "golang.org/x/sys/windows" |
| 17 | |
| 18 | "rodent.software/vole/internal/secure" |
| 19 | ) |
| 20 | |
| 21 | // TestCheckProtectsALogOpenToEveryone is the Windows upgrade case: a log that an |
| 22 | // earlier install created somewhere readable is tightened by Check, and the check |
| 23 | // it performs afterwards is the same one every other secret gets. |
| 24 | func TestCheckProtectsALogOpenToEveryone(t *testing.T) { |
| 25 | path := filepath.Join(t.TempDir(), "audit.log") |
| 26 | if err := os.WriteFile(path, []byte("old line\n"), 0o600); err != nil { |
| 27 | t.Fatal(err) |
| 28 | } |
| 29 | world, err := windows.CreateWellKnownSid(windows.WinWorldSid) |
| 30 | if err != nil { |
| 31 | t.Fatal(err) |
| 32 | } |
| 33 | var pinner runtime.Pinner |
| 34 | pinner.Pin(world) |
| 35 | dacl, err := windows.ACLFromEntries([]windows.EXPLICIT_ACCESS{{ |
| 36 | AccessPermissions: 0x1f01ff, |
| 37 | AccessMode: windows.SET_ACCESS, |
| 38 | Trustee: windows.TRUSTEE{ |
| 39 | TrusteeForm: windows.TRUSTEE_IS_SID, |
| 40 | TrusteeType: windows.TRUSTEE_IS_USER, |
| 41 | TrusteeValue: windows.TrusteeValueFromSID(world), |
| 42 | }, |
| 43 | }}, nil) |
| 44 | pinner.Unpin() |
| 45 | if err != nil { |
| 46 | t.Fatal(err) |
| 47 | } |
| 48 | if err := windows.SetNamedSecurityInfo(path, windows.SE_FILE_OBJECT, |
| 49 | windows.DACL_SECURITY_INFORMATION|windows.PROTECTED_DACL_SECURITY_INFORMATION, |
| 50 | nil, nil, dacl, nil); err != nil { |
| 51 | t.Fatal(err) |
| 52 | } |
| 53 | if err := secure.VerifyACL(path); err == nil { |
| 54 | t.Fatal("the fixture grants Everyone access; the test proves nothing") |
| 55 | } |
| 56 | |
| 57 | if err := Check(path); err != nil { |
| 58 | t.Fatalf("Check on a log granting Everyone: %v", err) |
| 59 | } |
| 60 | if err := secure.VerifyACL(path); err != nil { |
| 61 | t.Fatalf("the log is not protected after Check: %v", err) |
| 62 | } |
| 63 | } |
| 64 |