Skip to content

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

localingest: on Windows, only SYSTEM and enabled Administrators bypass the pipe

Claudec9cc55a77f68
diff --git a/pkg/asymptoteobserve/localingest/deliver_windows_test.go b/pkg/asymptoteobserve/localingest/deliver_windows_test.go
index 3b90e3e0..b887be50 100644
--- a/pkg/asymptoteobserve/localingest/deliver_windows_test.go
+++ b/pkg/asymptoteobserve/localingest/deliver_windows_test.go
@@ -134,17 +134,26 @@ func TestARealAccessDeniedIsAPermissionRefusal(t *testing.T) {
}
}
-// SYSTEM and elevated administrators write the restricted log directly; everyone else goes through
-// the pipe.
+// SYSTEM and administrators with Administrators enabled write the restricted log directly;
+// everyone else, elevated for another group or not elevated at all, goes through the pipe.
func TestWindowsPrivilegeDecidesTheRoute(t *testing.T) {
token, err := windows.OpenCurrentProcessToken()
if err != nil {
t.Fatal(err)
}
- elevated := token.IsElevated()
- token.Close()
- if elevated && !processPrivileged() {
- t.Fatal("an elevated process is not treated as privileged")
+ defer token.Close()
+ groups, err := token.GetTokenGroups()
+ if err != nil {
+ t.Fatal(err)
+ }
+ adminEnabled := false
+ for _, g := range groups.AllGroups() {
+ if g.Sid.IsWellKnown(windows.WinBuiltinAdministratorsSid) && g.Attributes&windows.SE_GROUP_ENABLED != 0 {
+ adminEnabled = true
+ }
+ }
+ if processPrivileged() != adminEnabled {
+ t.Fatalf("processPrivileged = %v, but Administrators enabled in this token = %v", processPrivileged(), adminEnabled)
}
if (Deliverer{}).Applies(systemLog) == processPrivileged() {
t.Fatalf("Applies = %v while processPrivileged = %v", (Deliverer{}).Applies(systemLog), processPrivileged())
diff --git a/pkg/asymptoteobserve/localingest/privilege_windows.go b/pkg/asymptoteobserve/localingest/privilege_windows.go
index ccbc2a7d..f9384b23 100644
--- a/pkg/asymptoteobserve/localingest/privilege_windows.go
+++ b/pkg/asymptoteobserve/localingest/privilege_windows.go
@@ -4,14 +4,23 @@ package localingest
import "golang.org/x/sys/windows"
-// processPrivileged reports whether this process runs as SYSTEM or with an elevated token: either
-// may write the restricted log, whose ACL gives SYSTEM and Administrators full control, and neither
-// may be stamped as anyone else.
+// 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
+// write, and neither may be stamped as anyone else. Elevation alone is not enough: a token elevated
+// for another group (Backup Operators run as administrator, say) is still refused by the ACL, so it
+// must go through the pipe and the spool like any other account.
func processPrivileged() bool {
token := windows.GetCurrentProcessToken()
- if token.IsElevated() {
+ if user, err := token.GetTokenUser(); err == nil && user.User.Sid.IsWellKnown(windows.WinLocalSystemSid) {
return true
}
- user, err := token.GetTokenUser()
- return err == nil && user.User.Sid.IsWellKnown(windows.WinLocalSystemSid)
+ admins, err := windows.CreateWellKnownSid(windows.WinBuiltinAdministratorsSid)
+ if err != nil {
+ return false
+ }
+ // A zero token asks CheckTokenMembership about this thread's token, or a copy of the process's,
+ // counting only enabled groups: an administrator's filtered token holds Administrators for deny
+ // only, so a shell that is not elevated is not privileged.
+ member, err := windows.Token(0).IsMember(admins)
+ return err == nil && member
}