The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
localingest: on Windows, spool under the token's profile, not USERPROFILE
Claude306722771ebf
diff --git a/packaging/windows/smoke-restricted-log.ps1 b/packaging/windows/smoke-restricted-log.ps1index 4f0c7ad3..609f45d9 100644--- a/packaging/windows/smoke-restricted-log.ps1+++ b/packaging/windows/smoke-restricted-log.ps1@@ -94,7 +94,6 @@ function Invoke-Hook {"set `"BEACON_ENDPOINT_LOG=$log`"","set `"BEACON_ENDPOINT_CONFIG=$config`"",'set "USER=Administrator"',- "echo %USERPROFILE%> `"$work\$Session.home`"","`"$hooks`" --platform claude session-start < `"$payload`" > `"$work\$Session.out`" 2> `"$work\$Session.err`"")if ($code -ne 0) {@@ -150,9 +149,10 @@ try {$sessionB = 'smoke-b-' + [Guid]::NewGuid().ToString('N')Invoke-Hook $sessionBif ((Get-LogEvents $sessionB).Count -gt 0) { throw "an event reached the restricted log with the collector stopped" }- # The profile the hook ran under, as it saw it: Windows names a profile directory after the- # account only when that name is free.- $profileDir = (Get-Content -LiteralPath "$work\$sessionB.home" -ErrorAction SilentlyContinue | Select-Object -First 1)+ # The account's own profile, looked up by its SID: Windows names a profile directory after the+ # account only when that name is free, and the hook inherits this script's USERPROFILE (which+ # is why the spool is placed by the token's profile, not by that variable).+ $profileDir = (Get-CimInstance Win32_UserProfile | Where-Object { $_.SID -eq $sid } | Select-Object -First 1).LocalPathif (-not $profileDir) { $profileDir = Join-Path $env:SystemDrive "Users\$account" }$spool = Join-Path $profileDir.Trim() '.beacon\endpoint\spool'if (-not (Get-ChildItem -LiteralPath $spool -Recurse -File -ErrorAction SilentlyContinue | Select-String -SimpleMatch $sessionB -Quiet)) {diff --git a/pkg/asymptoteobserve/localingest/deliver.go b/pkg/asymptoteobserve/localingest/deliver.goindex 690fc453..06aeb2c5 100644--- a/pkg/asymptoteobserve/localingest/deliver.go+++ b/pkg/asymptoteobserve/localingest/deliver.go@@ -19,7 +19,7 @@ const spoolDirInHome = ".beacon/endpoint/spool"// DefaultSpoolDir is the current account's spool directory, or "" when it has no home.func DefaultSpoolDir() string {- home, err := os.UserHomeDir()+ home, err := accountHome()if err != nil || home == "" {return ""}diff --git a/pkg/asymptoteobserve/localingest/deliver_windows_test.go b/pkg/asymptoteobserve/localingest/deliver_windows_test.goindex b887be50..11c22821 100644--- a/pkg/asymptoteobserve/localingest/deliver_windows_test.go+++ b/pkg/asymptoteobserve/localingest/deliver_windows_test.go@@ -159,3 +159,17 @@ func TestWindowsPrivilegeDecidesTheRoute(t *testing.T) {t.Fatalf("Applies = %v while processPrivileged = %v", (Deliverer{}).Applies(systemLog), processPrivileged())}}++// The spool is under the profile of the account the process runs as, whatever USERPROFILE says: a+// process started under other credentials can inherit its parent's environment, and a spool in+// that profile is one this account cannot write.+func TestTheSpoolIsInTheTokensProfileNotUSERPROFILE(t *testing.T) {+ profile, err := windows.GetCurrentProcessToken().GetUserProfileDirectory()+ if err != nil || profile == "" {+ t.Skipf("this process has no profile loaded: %v", err)+ }+ t.Setenv("USERPROFILE", t.TempDir())+ if got, want := DefaultSpoolDir(), filepath.Join(profile, spoolDirInHome); !strings.EqualFold(got, want) {+ t.Fatalf("DefaultSpoolDir = %q, want %q under the token's profile", got, want)+ }+}diff --git a/pkg/asymptoteobserve/localingest/privilege_unix.go b/pkg/asymptoteobserve/localingest/privilege_unix.goindex 999bc9ca..94c4ad84 100644--- a/pkg/asymptoteobserve/localingest/privilege_unix.go+++ b/pkg/asymptoteobserve/localingest/privilege_unix.go@@ -6,3 +6,6 @@ import "os"// processPrivileged reports whether this process is root.func processPrivileged() bool { return os.Geteuid() == 0 }++// accountHome is the home directory the spool lives under.+func accountHome() (string, error) { return os.UserHomeDir() }diff --git a/pkg/asymptoteobserve/localingest/privilege_windows.go b/pkg/asymptoteobserve/localingest/privilege_windows.goindex f9384b23..031ba429 100644--- a/pkg/asymptoteobserve/localingest/privilege_windows.go+++ b/pkg/asymptoteobserve/localingest/privilege_windows.go@@ -2,7 +2,11 @@package localingest-import "golang.org/x/sys/windows"+import (+ "os"++ "golang.org/x/sys/windows"+)// processPrivileged reports whether this process may write the restricted log itself: it runs as// SYSTEM, or its token has Administrators enabled. Those are the accounts the log's ACL gives@@ -24,3 +28,14 @@ func processPrivileged() bool {member, err := windows.Token(0).IsMember(admins)return err == nil && member}++// accountHome is the profile directory of the account this process runs as, read from its token+// rather than USERPROFILE: a process started under other credentials can inherit its parent's+// environment (Start-Process -Credential does), which would point the spool at a profile this+// account cannot write. USERPROFILE is the fallback when the token has no profile loaded.+func accountHome() (string, error) {+ if dir, err := windows.GetCurrentProcessToken().GetUserProfileDirectory(); err == nil && dir != "" {+ return dir, nil+ }+ return os.UserHomeDir()+}diff --git a/pkg/asymptoteobserve/localingest/transport_other.go b/pkg/asymptoteobserve/localingest/transport_other.goindex 2373cae9..11e79cb4 100644--- a/pkg/asymptoteobserve/localingest/transport_other.go+++ b/pkg/asymptoteobserve/localingest/transport_other.go@@ -5,6 +5,7 @@ package localingestimport ("errors""net"+ "os""time")@@ -36,3 +37,6 @@ func temporaryAcceptError(error) bool { return false }// processPrivileged is never true here, where there is no ingest channel to bypass.func processPrivileged() bool { return false }++// accountHome is the home directory the spool lives under.+func accountHome() (string, error) { return os.UserHomeDir() }