Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

sysacl: recognise a restricted log directory by its exact ACL

Claudee5a4d8fa0eda
diff --git a/cli/beacon/internal/endpoint/sysacl/restricted_windows.go b/cli/beacon/internal/endpoint/sysacl/restricted_windows.go
index 81483a27..0d3ed291 100644
--- a/cli/beacon/internal/endpoint/sysacl/restricted_windows.go
+++ b/cli/beacon/internal/endpoint/sysacl/restricted_windows.go
@@ -57,20 +57,20 @@ func ResetLogDirToShared(dir string) error {
return withPrivileges(func() error { return resetRestricted(dir, LogDirDACL(), "") })
}
-// LooksRestricted reports whether the log directory carries the restricted mode's ACL rather than
-// the shared one: no entry for interactive users, which the shared ACL always has. It reads only
-// the directory, so it answers for a restriction cut short before its marker was written.
-func LooksRestricted(dir string) bool {
- obj, isLink, err := readObject(dir)
- if err != nil || isLink {
+// LooksRestricted reports whether the log directory carries exactly the restricted mode's ACL for
+// readersSID: protected, and granting nothing RestrictedProblems would object to. It reads only the
+// directory, so it answers for a restriction cut short before its marker was written, and a
+// directory Beacon never secured (still inheriting from %ProgramData%, or made by hand) is not
+// mistaken for one.
+func LooksRestricted(dir, readersSID string) bool {
+ if readersSID == "" {
return false
}
- for _, ace := range obj.DACL {
- if ace.SID == sidInteractive {
- return false
- }
+ obj, isLink, err := readObject(dir)
+ if err != nil || isLink || !obj.Protected || len(obj.DACL) == 0 {
+ return false
}
- return true
+ return len(RestrictedProblems(obj, readersSID, false)) == 0
}
// resetRestricted gives everything below dir, which carries dacl, what it would inherit. base names
diff --git a/cli/beacon/internal/endpoint/sysacl/sysacl_other.go b/cli/beacon/internal/endpoint/sysacl/sysacl_other.go
index e709caa1..c1990d4e 100644
--- a/cli/beacon/internal/endpoint/sysacl/sysacl_other.go
+++ b/cli/beacon/internal/endpoint/sysacl/sysacl_other.go
@@ -23,4 +23,4 @@ func InspectRestrictedLogDir(dir, base, readersSID string) ([]string, error) { r
func ResetLogDirToShared(string) error { return nil }
// LooksRestricted is false off Windows.
-func LooksRestricted(string) bool { return false }
+func LooksRestricted(string, string) bool { return false }
diff --git a/cli/beacon/internal/endpoint/writer/logaccess_windows.go b/cli/beacon/internal/endpoint/writer/logaccess_windows.go
index 30aa93e0..fe265f6c 100644
--- a/cli/beacon/internal/endpoint/writer/logaccess_windows.go
+++ b/cli/beacon/internal/endpoint/writer/logaccess_windows.go
@@ -303,7 +303,13 @@ func copyInto(dst *os.File, path string) error {
func ShareSystemLog(path string) error {
// Read before the marker goes: whether the directory was restricted, by the marker or, for a
// restriction cut short before writing it, by the directory's own ACL.
- wasRestricted := asymptoteobserve.RuntimeLogAccessRestricted(path) || sysacl.LooksRestricted(filepath.Dir(path))
+ wasRestricted := asymptoteobserve.RuntimeLogAccessRestricted(path)
+ if !wasRestricted {
+ // No readers group, no restriction: the mode cannot be applied without one.
+ if readers, err := logReadersSID(); err == nil {
+ wasRestricted = sysacl.LooksRestricted(filepath.Dir(path), readers)
+ }
+ }
if err := asymptoteobserve.SetRuntimeLogAccess(path, asymptoteobserve.LogAccessShared); err != nil {
return fmt.Errorf("remove the restricted mode marker: %w", err)
}
diff --git a/cli/beacon/internal/endpoint/writer/logaccess_windows_test.go b/cli/beacon/internal/endpoint/writer/logaccess_windows_test.go
index ee095e31..1afee88a 100644
--- a/cli/beacon/internal/endpoint/writer/logaccess_windows_test.go
+++ b/cli/beacon/internal/endpoint/writer/logaccess_windows_test.go
@@ -5,6 +5,7 @@ package writer
import (
"os"
"path/filepath"
+ "reflect"
"strings"
"testing"
"time"
@@ -259,3 +260,38 @@ func fileIndex(t *testing.T, path string) uint64 {
}
return uint64(info.FileIndexHigh)<<32 | uint64(info.FileIndexLow)
}
+
+// A shared install on a log directory Beacon never secured -- one still inheriting from its
+// parent, or made by hand -- is not taken for a restricted one, so nothing else in it is reset.
+func TestShareSystemLogLeavesAnUnsecuredDirectoryAlone(t *testing.T) {
+ requireSystemACLRights(t)
+ testenv.SetHome(t, t.TempDir())
+ prev := logReadersSID
+ logReadersSID = func() (string, error) { return backupOperators, nil }
+ t.Cleanup(func() { logReadersSID = prev })
+ path := filepath.Join(t.TempDir(), "logs", "runtime.jsonl")
+ operator := filepath.Join(filepath.Dir(path), "operator.txt")
+ if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(operator, []byte("mine\n"), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ if sysacl.LooksRestricted(filepath.Dir(path), backupOperators) {
+ t.Fatal("a directory that inherits from its parent reads as restricted")
+ }
+ before, err := sysacl.ReadObject(operator)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := ShareSystemLog(path); err != nil {
+ t.Fatalf("ShareSystemLog: %v", err)
+ }
+ after, err := sysacl.ReadObject(operator)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !reflect.DeepEqual(before.DACL, after.DACL) {
+ t.Fatalf("a shared install reset a file it never restricted: %+v -> %+v", before.DACL, after.DACL)
+ }
+}