Skip to content

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

windows: keep the backfill's copies of a user's session stores private (#1175)

Shukan Shah95d7adf5171b
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 537641e7..22eb0be3 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -868,9 +868,10 @@ jobs:
}
# Each MSI step has its own bound, inside the job's. A wedged msiexec then fails its step instead
- # of holding the job until GitHub cancels it, and a cancelled job keeps no log at all -- which is
- # how intermittent upgrade and uninstall hangs went undiagnosed. With the step bound, the
- # diagnostics and the package logs below still run and upload.
+ # of holding the job until GitHub cancels it, and a cancelled job keeps no log at all. With the
+ # step bound, the diagnostics and the package logs below still run and upload. None of that
+ # helps when the runner itself goes away mid-step, which still happens now and then: nothing
+ # after that point runs, and re-running the job is the workaround.
#
# Each step bound is longer than the package scripts' own limits for the actions it runs
# (packaging/windows/install-endpoint.ps1 and uninstall-endpoint.ps1), so a hung beacon.exe call
diff --git a/cli/beacon/cmd/endpoint_backfill.go b/cli/beacon/cmd/endpoint_backfill.go
index 732a61c3..432aa048 100644
--- a/cli/beacon/cmd/endpoint_backfill.go
+++ b/cli/beacon/cmd/endpoint_backfill.go
@@ -20,6 +20,7 @@ import (
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/dshsession"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/asymptote"
endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/sysacl"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/writer"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/factorysession"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/fxsession"
@@ -178,6 +179,10 @@ var endpointBackfillScratchDir = func() string {
return filepath.Join(endpointconfig.BaseDir(false), "state", "backfill-snapshots")
}
+// secureBackfillScratchDir makes the scratch directory readable by SYSTEM and Administrators alone
+// before a system backfill copies anything into it. A seam for tests.
+var secureBackfillScratchDir = sysacl.SecureSecretDir
+
// endpointBackfillNow is time.Now, a seam for tests.
var endpointBackfillNow = time.Now
@@ -498,7 +503,15 @@ func runEndpointBackfillUnlocked(logPath string, userMode bool, sweep endpointSw
if err != nil {
return endpointBackfillResult{Skipped: fmt.Sprintf("could not read the owner of the console user's home: %v", err)}
}
- confined, err := sessionfs.Confine(info.HomeDir, uid, sessionfs.Options{ScratchDir: endpointBackfillScratchDir()})
+ // The snapshots are copies of that user's session stores. On Windows their directory would
+ // inherit the machine-wide tree's grant of read to every user, which 0700 does nothing about, so
+ // it is made SYSTEM and Administrators only first, and nothing is copied when that fails.
+ // Elsewhere root ownership and 0700 already keep it private.
+ scratch := endpointBackfillScratchDir()
+ if err := secureBackfillScratchDir(scratch); err != nil {
+ return endpointBackfillResult{Skipped: fmt.Sprintf("could not make the snapshot directory %s private: %v", scratch, err)}
+ }
+ confined, err := sessionfs.Confine(info.HomeDir, uid, sessionfs.Options{ScratchDir: scratch})
if err != nil {
return endpointBackfillResult{Skipped: err.Error()}
}
diff --git a/cli/beacon/cmd/endpoint_backfill_test.go b/cli/beacon/cmd/endpoint_backfill_test.go
index 4675973a..e6ea9068 100644
--- a/cli/beacon/cmd/endpoint_backfill_test.go
+++ b/cli/beacon/cmd/endpoint_backfill_test.go
@@ -34,6 +34,11 @@ func stubBackfill(t *testing.T, maxBytes, shareBytes int64, runners ...endpointB
t.Cleanup(func() { endpointBackfillScratchDir = oldScratch })
scratch := filepath.Join(t.TempDir(), "backfill-snapshots")
endpointBackfillScratchDir = func() string { return scratch }
+ // Securing the directory on Windows sets its owner, which needs an elevated token; the tests
+ // that check it put the real one back.
+ oldSecure := secureBackfillScratchDir
+ t.Cleanup(func() { secureBackfillScratchDir = oldSecure })
+ secureBackfillScratchDir = func(string) error { return nil }
}
func writingRunner(name string, events int, since *time.Time) endpointBackfillRunner {
@@ -203,6 +208,49 @@ func TestSystemEndpointBackfillReadsTheConsoleUsersStores(t *testing.T) {
}
}
+// A system backfill makes its snapshot directory private before it reads anything, and reads
+// nothing when it cannot: the copies it would make there are the console user's session stores.
+func TestSystemEndpointBackfillSecuresTheSnapshotDirectoryFirst(t *testing.T) {
+ ran := false
+ stubBackfill(t, 1<<20, 1<<20, endpointBackfillRunner{Name: "Codex", Sync: "beacon endpoint codex sync", Run: func(endpointBackfillRun) (int, error) {
+ ran = true
+ return 0, nil
+ }})
+ stubConsoleUser(t, consoleUserInfo{Username: "alice", HomeDir: t.TempDir()}, true, nil)
+ scratch := endpointBackfillScratchDir()
+
+ var secured []string
+ secureBackfillScratchDir = func(dir string) error {
+ if ran {
+ t.Error("the snapshot directory was secured after a runtime was read")
+ }
+ secured = append(secured, dir)
+ return nil
+ }
+ runEndpointBackfill(filepath.Join(t.TempDir(), "runtime.jsonl"), false)
+ if !ran || len(secured) != 1 || secured[0] != scratch {
+ t.Fatalf("secured %v (runtime read: %t), want %s once, before the runtime is read", secured, ran, scratch)
+ }
+
+ ran = false
+ secureBackfillScratchDir = func(string) error { return errors.New("access is denied") }
+ result := runEndpointBackfill(filepath.Join(t.TempDir(), "runtime.jsonl"), false)
+ if ran {
+ t.Fatal("a system backfill read session stores although its snapshot directory could not be made private")
+ }
+ if !strings.Contains(result.Skipped, scratch) || !strings.Contains(result.Skipped, "access is denied") {
+ t.Fatalf("Skipped = %q, want it to name %s and the error", result.Skipped, scratch)
+ }
+
+ // A user backfill reads the user's own stores and makes no copies in the system tree.
+ secured = nil
+ secureBackfillScratchDir = func(dir string) error { secured = append(secured, dir); return nil }
+ runEndpointBackfill(filepath.Join(t.TempDir(), "runtime.jsonl"), true)
+ if len(secured) != 0 {
+ t.Fatalf("a user backfill secured %v", secured)
+ }
+}
+
func TestConnectShipsTheBackfill(t *testing.T) {
originalLoad, originalConnect := connectAccountLoad, connectManagedEndpoint
originalConnectOpts, originalEndpointOpts := connectOpts, endpointOpts
diff --git a/cli/beacon/cmd/endpoint_backfill_windows_test.go b/cli/beacon/cmd/endpoint_backfill_windows_test.go
new file mode 100644
index 00000000..0f6e7cda
--- /dev/null
+++ b/cli/beacon/cmd/endpoint_backfill_windows_test.go
@@ -0,0 +1,74 @@
+//go:build windows
+
+package cmd
+
+import (
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/sysacl"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/sessionfs"
+ "golang.org/x/sys/windows"
+)
+
+// A system backfill's copy of the console user's SQLite store is readable by SYSTEM and
+// Administrators alone. Without that, the copy would inherit whatever its directory passes on: in
+// %ProgramData%\Beacon, read for every user.
+func TestSystemEndpointBackfillSnapshotsAreSystemAndAdministratorsOnly(t *testing.T) {
+ token, err := windows.OpenCurrentProcessToken()
+ if err != nil {
+ t.Skipf("open the process token: %v", err)
+ }
+ elevated := token.IsElevated()
+ token.Close()
+ if !elevated {
+ t.Skip("setting the snapshot directory's owner needs an elevated shell")
+ }
+
+ home := t.TempDir()
+ store := filepath.Join(home, ".hermes", "state.db")
+ if err := os.MkdirAll(filepath.Dir(store), 0o700); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(store, []byte("sqlite"), 0o600); err != nil {
+ t.Fatal(err)
+ }
+
+ var snapshot string
+ var others []string
+ stubBackfill(t, 1<<20, 1<<20, endpointBackfillRunner{Name: "Hermes Agent", Sync: "beacon endpoint hermes sync", Run: func(endpointBackfillRun) (int, error) {
+ var err error
+ if snapshot, err = sessionfs.SQLitePath(store); err != nil {
+ return 0, err
+ }
+ // Read while the copy exists: the backfill removes it once the runtime is done.
+ for _, path := range []string{snapshot, filepath.Dir(snapshot)} {
+ obj, err := sysacl.ReadObject(path)
+ if err != nil {
+ return 0, err
+ }
+ for _, ace := range obj.DACL {
+ // Type 0 is an allow entry. S-1-5-18 is SYSTEM, S-1-5-32-544 Administrators.
+ if ace.Type == 0 && ace.Mask != 0 && ace.SID != "S-1-5-18" && ace.SID != "S-1-5-32-544" {
+ others = append(others, path+": "+ace.SID)
+ }
+ }
+ }
+ return 0, nil
+ }})
+ secureBackfillScratchDir = sysacl.SecureSecretDir
+ stubConsoleUser(t, consoleUserInfo{Username: "alice", HomeDir: home}, true, nil)
+
+ result := runEndpointBackfill(filepath.Join(t.TempDir(), "runtime.jsonl"), false)
+ if snapshot == "" {
+ t.Fatalf("no snapshot was made: %+v", result)
+ }
+ if !strings.HasPrefix(snapshot, endpointBackfillScratchDir()+string(filepath.Separator)) {
+ t.Fatalf("snapshot %s is not under the scratch directory %s", snapshot, endpointBackfillScratchDir())
+ }
+ if len(others) > 0 {
+ t.Fatalf("the snapshot is readable by accounts other than SYSTEM and Administrators: %v", others)
+ }
+}
diff --git a/cli/beacon/internal/endpoint/sysacl/secret.go b/cli/beacon/internal/endpoint/sysacl/secret.go
index 770179ed..9b33d4b7 100644
--- a/cli/beacon/internal/endpoint/sysacl/secret.go
+++ b/cli/beacon/internal/endpoint/sysacl/secret.go
@@ -7,3 +7,15 @@ package sysacl
func SecretFileDACL() []ACE {
return RestrictedLockDACL()
}
+
+// SecretDirDACL is the protected DACL on a machine-wide directory whose contents only SYSTEM and
+// Administrators may read, such as the system backfill's copies of the console user's SQLite
+// session stores: SecretFileDACL's two entries, inherited by every file and directory created in
+// it.
+func SecretDirDACL() []ACE {
+ dacl := SecretFileDACL()
+ for i := range dacl {
+ dacl[i].Flags |= aceObjectInherit | aceContainerInherit
+ }
+ return dacl
+}
diff --git a/cli/beacon/internal/endpoint/sysacl/secret_other.go b/cli/beacon/internal/endpoint/sysacl/secret_other.go
index 4ade2183..e3ea6b70 100644
--- a/cli/beacon/internal/endpoint/sysacl/secret_other.go
+++ b/cli/beacon/internal/endpoint/sysacl/secret_other.go
@@ -12,3 +12,6 @@ func WriteSecretFile(path string, data []byte) error {
// 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 }
+
+// SecureSecretDir is a no-op off Windows, where a root-owned 0700 directory is already private.
+func SecureSecretDir(string) error { return nil }
diff --git a/cli/beacon/internal/endpoint/sysacl/secret_windows.go b/cli/beacon/internal/endpoint/sysacl/secret_windows.go
index a7c8acf0..a8f9a56f 100644
--- a/cli/beacon/internal/endpoint/sysacl/secret_windows.go
+++ b/cli/beacon/internal/endpoint/sysacl/secret_windows.go
@@ -66,3 +66,23 @@ func IsSecretFile(path string) bool {
obj, err := ReadObject(path)
return err == nil && obj.Protected && reflect.DeepEqual(obj.DACL, SecretFileDACL())
}
+
+// SecureSecretDir gives dir Administrators ownership and the protected SecretDirDACL, and resets
+// everything already below it to what it inherits from that, so nothing in it stays readable by
+// other accounts and everything written there later inherits the same two entries. dir is created
+// if missing and replaced if it is a link; links below it are removed. A directory that is already
+// private passes SecureSystemTree's checks, so a later pass over the tree leaves it alone.
+func SecureSecretDir(dir string) error {
+ return withPrivileges(func() error {
+ h, err := ensureRealDir(dir)
+ if err != nil {
+ return err
+ }
+ err = setSecurity(h, true, SecretDirDACL())
+ windows.CloseHandle(h)
+ if err != nil {
+ return fmt.Errorf("secure %s: %w", dir, err)
+ }
+ return resetRestricted(dir, SecretDirDACL(), "")
+ })
+}
diff --git a/cli/beacon/internal/endpoint/sysacl/secret_windows_test.go b/cli/beacon/internal/endpoint/sysacl/secret_windows_test.go
index d7925e5d..04fce8dc 100644
--- a/cli/beacon/internal/endpoint/sysacl/secret_windows_test.go
+++ b/cli/beacon/internal/endpoint/sysacl/secret_windows_test.go
@@ -57,3 +57,73 @@ func TestWriteSecretFileIsSystemAndAdministratorsOnly(t *testing.T) {
t.Fatalf("temp files left behind: %v", entries)
}
}
+
+// SecureSecretDir closes a directory that inherited the tree's grants, resets what is already in
+// it, and passes the private entries to what is created there later. A later pass over the tree
+// leaves it private.
+func TestSecureSecretDirResetsAndPassesOnPrivacy(t *testing.T) {
+ requireElevated(t)
+ root := filepath.Join(t.TempDir(), "Beacon")
+ if err := SecureSystemTree(root); err != nil {
+ t.Fatal(err)
+ }
+ dir := filepath.Join(root, "Endpoint", "state", "backfill-snapshots")
+ stale := filepath.Join(dir, "beacon-backfill-sqlite-1", "opencode.db")
+ if err := os.MkdirAll(filepath.Dir(stale), 0o700); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(stale, []byte("sqlite"), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ if len(grantsOthers(mustRead(t, stale).DACL)) == 0 {
+ t.Fatal("setup: the stale snapshot does not carry the tree's Users grant")
+ }
+
+ if err := SecureSecretDir(dir); err != nil {
+ t.Fatalf("SecureSecretDir: %v", err)
+ }
+ obj := mustRead(t, dir)
+ if obj.Owner != sidAdministrators || !obj.Protected || !reflect.DeepEqual(obj.DACL, SecretDirDACL()) {
+ t.Fatalf("secret directory reads back owner %s protected %v DACL %+v", obj.Owner, obj.Protected, obj.DACL)
+ }
+ for _, path := range []string{filepath.Dir(stale), stale} {
+ if others := grantsOthers(mustRead(t, path).DACL); len(others) > 0 {
+ t.Errorf("%s kept a grant after SecureSecretDir: %+v", path, others)
+ }
+ }
+ fresh := filepath.Join(dir, "beacon-backfill-sqlite-2", "state.db")
+ if err := os.MkdirAll(filepath.Dir(fresh), 0o700); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(fresh, []byte("x"), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ if others := grantsOthers(mustRead(t, fresh).DACL); len(others) > 0 {
+ t.Fatalf("a file created in the secret directory inherits %+v", others)
+ }
+
+ // Running it again changes nothing, and a pass over the tree does not widen it back.
+ if err := SecureSecretDir(dir); err != nil {
+ t.Fatalf("SecureSecretDir again: %v", err)
+ }
+ if err := SecureSystemTree(root); err != nil {
+ t.Fatal(err)
+ }
+ if obj := mustRead(t, dir); !obj.Protected || !reflect.DeepEqual(obj.DACL, SecretDirDACL()) {
+ t.Fatalf("SecureSystemTree changed the secret directory to %+v (protected %v)", obj.DACL, obj.Protected)
+ }
+ if others := grantsOthers(mustRead(t, fresh).DACL); len(others) > 0 {
+ t.Fatalf("SecureSystemTree widened a file in the secret directory: %+v", others)
+ }
+}
+
+// grantsOthers lists the allow entries in dacl for anyone but SYSTEM and Administrators.
+func grantsOthers(dacl []ACE) []ACE {
+ var out []ACE
+ for _, ace := range dacl {
+ if ace.Type != aceTypeDenied && ace.SID != sidSystem && ace.SID != sidAdministrators && ace.Mask != 0 {
+ out = append(out, ace)
+ }
+ }
+ return out
+}
diff --git a/docs/changelog/cli.mdx b/docs/changelog/cli.mdx
index d23f7f46..f107a1df 100644
--- a/docs/changelog/cli.mdx
+++ b/docs/changelog/cli.mdx
@@ -12,6 +12,7 @@ Stay up to date with the latest changes to the Agent Beacon CLI.
## Unreleased
- **Scheduled session sync** · `beacon endpoint install|repair --session-sync` turns on a job that runs every 15 minutes and reads new records from the agent runtimes' local session stores into the runtime log. It runs the same bounded, confined sweep install already runs once, so session-store data keeps reaching the log, and any forwarder reading it, after install. Off by default; repair and upgrades keep the setting, and `--no-session-sync` removes the job. See [Scheduled session sync](/cli/endpoint-install#scheduled-session-sync).
+- **Windows session backfill keeps its copies of your sessions from other users** · To read the SQLite session stores of Cursor, OpenCode, Devin CLI and Hermes Agent, a system install's session backfill copies them into `%ProgramData%\Beacon\Endpoint\state\backfill-snapshots`. On Windows that directory let every local account read the copies until they were deleted, and indefinitely when a run was stopped partway. It is now readable by SYSTEM and Administrators only, and the backfill copies nothing when it cannot make it so.
- **Windows system installs keep destination credentials from other users** · On Windows the 0600 mode Beacon asked for has no effect, and `%ProgramData%\Beacon` lets every user read the files below it, so any local account could read a Splunk or Falcon HEC token in `config.json` and `otelcol.yaml`, and the OTLP forward's headers. Those files are now created with access for SYSTEM and Administrators only, at creation, so there is no moment they are readable. A `config.json` with no credential in it stays readable, as before, so other accounts still find the system log through it.
- **Forward OTLP to a second backend** · Macs that already sent Claude Code or Codex OpenTelemetry to another backend lost that export when Beacon pointed the runtimes at its collector. `beacon endpoint install|repair --otlp-forward-endpoint <endpoint>` (with `--otlp-forward-protocol grpc|http/protobuf` and repeatable `--otlp-forward-header name=value`) now has the collector send that OTLP on to the endpoint as well, through pipelines of its own. The forward carries only Claude Code and Codex by default (`--otlp-forward-harness` changes the list), so browser-extension chats and other runtimes stay local. Secrets are redacted, raw API bodies are dropped, and the queue is bounded, so a down backend never holds up Beacon's own capture. Header values are kept in a root-only `otlp-forward-headers.json` beside `config.json`. Repair and package upgrades keep it; `--no-otlp-forward` removes it. See [Kandji, GCS and an existing OTLP backend](/guides/kandji-otlp-forward-mdm).
- **Inherited per-signal OTLP settings no longer divert Claude telemetry** · An `OTEL_EXPORTER_OTLP_{LOGS,METRICS,TRACES}_ENDPOINT`, protocol or headers setting in the environment or Claude's settings sent Claude's telemetry past Beacon's collector, in `beacon ci` and with `beacon endpoint`, which still reported telemetry as enabled. Beacon now overrides them, and `beacon endpoint status` flags one that points elsewhere.
diff --git a/docs/platforms/windows.mdx b/docs/platforms/windows.mdx
index 9a151090..082dac6c 100644
--- a/docs/platforms/windows.mdx
+++ b/docs/platforms/windows.mdx
@@ -150,6 +150,8 @@ Because users cannot create files in the log directory, the install creates `run
`%ProgramData%\Beacon` is reset even when it already exists. `%ProgramData%` lets any user create a subdirectory, so one found there before the package was installed may belong to someone else: the install takes ownership, replaces its ACL, removes any junction, symbolic link or hard link inside it (Beacon creates none), and resets anything below it that grants an ordinary user write, delete or ownership rights. Anything already locked down further than this is left as it is.
+A few things below `%ProgramData%\Beacon` are kept from ordinary users entirely, with access for SYSTEM and Administrators only: `config.json` and `otelcol.yaml` when they hold a Splunk or Falcon HEC token, the OTLP forward's headers, and `Endpoint\state\backfill-snapshots`, where the session backfill copies the signed-in user's SQLite session stores to read them and deletes each copy once read.
+
`doctor --system` checks both halves: that interactive users can append, and that nothing grants them more. An endpoint installed by an older version carries a broader grant (Modify for `INTERACTIVE` on the log directory) and is reported as `acl_too_broad`. Upgrading the package fixes it, as does running this from an elevated shell:
```powershell title="Reset the log directory ACL"
diff --git a/packaging/windows/package-common.ps1 b/packaging/windows/package-common.ps1
index d854924d..1f4a83ca 100644
--- a/packaging/windows/package-common.ps1
+++ b/packaging/windows/package-common.ps1
@@ -3,10 +3,8 @@
#
# An MSI custom action has no console and no time limit of its own. A beacon.exe call that never
# returns therefore holds the whole installation open: msiexec waits on the action, a fleet tool
-# (Intune, Workspace ONE, SCCM) waits on msiexec, and nothing records which step it was. CI saw
-# exactly that, intermittently, in both an upgrade and an uninstall, and each time the job was
-# cancelled at its time limit with its log discarded. So every call made here is bounded, and every
-# call leaves a record.
+# (Intune, Workspace ONE, SCCM) waits on msiexec, and nothing records which step it was. So every
+# call made here is bounded, and every call leaves a record.
#
# The record is a file of its own in the temporary directory of the account running the script --
# SYSTEM, for the MSI -- because nothing else survives: Windows Installer keeps no output from an