Skip to content

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

Windows: rollback restores credential files with their SYSTEM/Administrators DACL

Claude36d91623914c
diff --git a/cli/beacon/internal/endpoint/lifecycle/lifecycle.go b/cli/beacon/internal/endpoint/lifecycle/lifecycle.go
index 967ce9be..37dabb5f 100644
--- a/cli/beacon/internal/endpoint/lifecycle/lifecycle.go
+++ b/cli/beacon/internal/endpoint/lifecycle/lifecycle.go
@@ -451,6 +451,9 @@ type fileSnapshot struct {
Existed bool
Data []byte
Mode os.FileMode
+ // Secret is set for a file that carried sysacl.SecretFileDACL (on Windows, a system file holding
+ // a credential), so restoring it does not hand it the tree's DACL that every user can read.
+ Secret bool
}
// serviceController is the part of service.Manager that rollback uses.
@@ -1301,6 +1304,7 @@ func snapshotFile(path string) fileSnapshot {
if info, statErr := os.Stat(path); statErr == nil {
snapshot.Mode = info.Mode().Perm()
}
+ snapshot.Secret = sysacl.IsSecretFile(path)
}
return snapshot
}
@@ -1310,6 +1314,10 @@ func restoreFile(path string, snapshot fileSnapshot) {
_ = os.Remove(path)
return
}
+ if snapshot.Secret {
+ _ = sysacl.WriteSecretFile(path, snapshot.Data)
+ return
+ }
mode := snapshot.Mode
if mode == 0 {
mode = 0600
diff --git a/cli/beacon/internal/endpoint/sysacl/secret_other.go b/cli/beacon/internal/endpoint/sysacl/secret_other.go
index c9b03a27..4ade2183 100644
--- a/cli/beacon/internal/endpoint/sysacl/secret_other.go
+++ b/cli/beacon/internal/endpoint/sysacl/secret_other.go
@@ -8,3 +8,7 @@ import "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/atomicfile"
func WriteSecretFile(path string, data []byte) error {
return atomicfile.Write(path, data, 0600)
}
+
+// IsSecretFile is false off Windows: POSIX keeps the guarantee in the mode, which a snapshot
+// records and a restore puts back itself.
+func IsSecretFile(string) bool { return false }
diff --git a/cli/beacon/internal/endpoint/sysacl/secret_windows.go b/cli/beacon/internal/endpoint/sysacl/secret_windows.go
index 80265cbf..134fa0ed 100644
--- a/cli/beacon/internal/endpoint/sysacl/secret_windows.go
+++ b/cli/beacon/internal/endpoint/sysacl/secret_windows.go
@@ -4,6 +4,7 @@ package sysacl
import (
"fmt"
+ "reflect"
"os"
"path/filepath"
"runtime"
@@ -58,3 +59,10 @@ func WriteSecretFile(path string, data []byte) error {
}
return nil
}
+
+// IsSecretFile reports whether path carries SecretFileDACL, so a rollback that puts a snapshot back
+// can restore it the same way rather than with the tree's DACL.
+func IsSecretFile(path string) bool {
+ obj, err := ReadObject(path)
+ return err == nil && obj.Protected && reflect.DeepEqual(obj.DACL, SecretFileDACL())
+}
diff --git a/cli/beacon/internal/endpoint/sysacl/secret_windows_test.go b/cli/beacon/internal/endpoint/sysacl/secret_windows_test.go
index 1913797e..d7925e5d 100644
--- a/cli/beacon/internal/endpoint/sysacl/secret_windows_test.go
+++ b/cli/beacon/internal/endpoint/sysacl/secret_windows_test.go
@@ -29,6 +29,9 @@ func TestWriteSecretFileIsSystemAndAdministratorsOnly(t *testing.T) {
if obj.Owner != sidAdministrators {
t.Fatalf("secret file owned by %s, want Administrators", obj.Owner)
}
+ if !IsSecretFile(path) {
+ t.Fatal("IsSecretFile = false for a file WriteSecretFile wrote")
+ }
if got, err := os.ReadFile(path); err != nil || string(got) != body {
t.Fatalf("content = %q, %v", got, err)
}
@@ -40,6 +43,15 @@ func TestWriteSecretFileIsSystemAndAdministratorsOnly(t *testing.T) {
if obj := mustRead(t, path); !reflect.DeepEqual(obj.DACL, SecretFileDACL()) {
t.Fatalf("SecureSystemTree reset the secret file to %+v", obj.DACL)
}
+ // A file the tree's DACL covers is not a secret one, so a rollback restores it as it was.
+ plain := filepath.Join(root, "plain.json")
+ if err := os.WriteFile(plain, []byte("{}"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ if IsSecretFile(plain) {
+ t.Fatal("IsSecretFile = true for a file with the tree's DACL")
+ }
+ os.Remove(plain)
entries, _ := os.ReadDir(root)
if len(entries) != 1 {
t.Fatalf("temp files left behind: %v", entries)