Skip to content

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

writer: going back to shared on Windows restores every file the restriction reset

Claude6cc272a2e549
diff --git a/cli/beacon/internal/endpoint/sysacl/restricted_windows.go b/cli/beacon/internal/endpoint/sysacl/restricted_windows.go
index e48b8260..81483a27 100644
--- a/cli/beacon/internal/endpoint/sysacl/restricted_windows.go
+++ b/cli/beacon/internal/endpoint/sysacl/restricted_windows.go
@@ -47,6 +47,32 @@ func SecureRestrictedLogDir(dir, base, readersSID string) error {
})
}
+// ResetLogDirToShared gives everything below the log directory what it inherits from the shared
+// LogDirDACL, which SecureLogDir sets on the directory itself. SecureLogDir resets only the log
+// family and leaves other files as it finds them, so after the restricted mode, which reset every
+// entry, this is what puts inventory_state.jsonl, system.jsonl and anything else in the directory
+// back to the shared grants. Run it only on a directory that was restricted: on a shared one it
+// would reset files an operator may have set up on purpose.
+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 {
+ return false
+ }
+ for _, ace := range obj.DACL {
+ if ace.SID == sidInteractive {
+ return false
+ }
+ }
+ return true
+}
+
// resetRestricted gives everything below dir, which carries dacl, what it would inherit. base names
// the log family in the top directory and is empty below it.
func resetRestricted(dir string, dacl []ACE, base string) error {
diff --git a/cli/beacon/internal/endpoint/sysacl/sysacl_other.go b/cli/beacon/internal/endpoint/sysacl/sysacl_other.go
index 03a83a06..e709caa1 100644
--- a/cli/beacon/internal/endpoint/sysacl/sysacl_other.go
+++ b/cli/beacon/internal/endpoint/sysacl/sysacl_other.go
@@ -18,3 +18,9 @@ func SecureRestrictedLogDir(dir, base, readersSID string) error { return nil }
func SecureRestrictedLock(path string) error { return nil }
func InspectRestrictedLogDir(dir, base, readersSID string) ([]string, error) { return nil, nil }
+
+// ResetLogDirToShared is a no-op off Windows.
+func ResetLogDirToShared(string) error { return nil }
+
+// LooksRestricted is false off Windows.
+func LooksRestricted(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 7bfe0812..30aa93e0 100644
--- a/cli/beacon/internal/endpoint/writer/logaccess_windows.go
+++ b/cli/beacon/internal/endpoint/writer/logaccess_windows.go
@@ -301,8 +301,21 @@ func copyInto(dst *os.File, path string) error {
// EnsureSystemLogWritable gives the directory and the log family the shared ACL again, the lock's
// narrower one included.
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))
if err := asymptoteobserve.SetRuntimeLogAccess(path, asymptoteobserve.LogAccessShared); err != nil {
return fmt.Errorf("remove the restricted mode marker: %w", err)
}
- return EnsureSystemLogWritable(path)
+ if err := EnsureSystemLogWritable(path); err != nil {
+ return err
+ }
+ if wasRestricted {
+ // EnsureSystemLogWritable resets only the log family; the restricted mode reset every file
+ // in the directory, and they go back too.
+ if err := sysacl.ResetLogDirToShared(filepath.Dir(path)); err != nil {
+ return fmt.Errorf("give the log directory back its shared grants: %w", err)
+ }
+ }
+ return nil
}
diff --git a/cli/beacon/internal/endpoint/writer/logaccess_windows_test.go b/cli/beacon/internal/endpoint/writer/logaccess_windows_test.go
index 8884e14f..ee095e31 100644
--- a/cli/beacon/internal/endpoint/writer/logaccess_windows_test.go
+++ b/cli/beacon/internal/endpoint/writer/logaccess_windows_test.go
@@ -197,6 +197,25 @@ func TestRestrictSystemLogReplacesTheOtherFilesBesideTheLog(t *testing.T) {
if fileIndex(t, linked) != linkedBefore {
t.Fatal("a hard-linked file outside the log family was copied")
}
+
+ // Back to shared, the files beside the log get the shared grants back with the log, not only
+ // the log family.
+ if err := ShareSystemLog(path); err != nil {
+ t.Fatalf("ShareSystemLog: %v", err)
+ }
+ obj, err := sysacl.ReadObject(inventory)
+ if err != nil {
+ t.Fatal(err)
+ }
+ interactive := false
+ for _, ace := range obj.DACL {
+ if ace.SID == "S-1-5-4" {
+ interactive = true
+ }
+ }
+ if !interactive {
+ t.Fatalf("inventory_state.jsonl kept the restricted ACL after the log was shared again: %+v", obj.DACL)
+ }
}
// Every file the restriction creates is owned by Administrators from the start, and the new lock