-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deny default write permissions from windows root directory (#1962)
- Loading branch information
1 parent
caa9ede
commit 7d72304
Showing
2 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package main | ||
|
||
import ( | ||
"io" | ||
"log/slog" | ||
"testing" | ||
|
||
"github.com/kolide/launcher/pkg/threadsafebuffer" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_checkRootDirACLs(t *testing.T) { | ||
t.Parallel() | ||
|
||
rootDir := t.TempDir() | ||
var logBytes threadsafebuffer.ThreadSafeBuffer | ||
|
||
slogger := slog.New(slog.NewTextHandler(&logBytes, &slog.HandlerOptions{ | ||
Level: slog.LevelDebug, | ||
})) | ||
|
||
// run the check once, expecting that we will correctly work all the way through | ||
// and log that we've updated the ACLs for our new directory | ||
checkRootDirACLs(slogger, rootDir) | ||
require.Contains(t, logBytes.String(), "updated ACLs for root directory") | ||
|
||
// now clear the log, and rerun. if the previous run did what it was supposed to, | ||
// and our check-before-write logic works correctly, we should detect the ACL we | ||
// just added and exit early | ||
io.Copy(io.Discard, &logBytes) | ||
checkRootDirACLs(slogger, rootDir) | ||
require.NotContains(t, logBytes.String(), "updated ACLs for root directory") | ||
require.Contains(t, logBytes.String(), "root directory already had proper DACL permissions set, skipping") | ||
} |