mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-15 19:29:08 +02:00
A service reads LocalMachine\MY, where AD and Intune enrol device certificates. CurrentUser\MY lives in the signed-in user's registry hive with keys protected against their profile, and a service that opens it does not fail: "current user" resolves to HKU\S-1-5-18, so it silently reads the service account's own empty store. The service therefore reads the machine store itself and launches "netbird posture cert-proof" with the session token for the rest, mirroring the macOS console user helper. Windows lets a privileged service assume a user identity, so the token goes straight into the child process and no external tooling is involved. CREATE_NO_WINDOW keeps a console window from flashing on the desktop every sync. In-process impersonation would also work but is per OS thread while goroutines migrate, so the child process avoids that class of bug. Session selection prefers the physical console and falls back to any active session, so remote desktop and VDI hosts are covered. WTSQueryUserToken needs SE_TCB_NAME, so a user-run client skips the helper and reads the machine store alone. SystemStore takes a store location, gaining NewUserStore alongside NewSystemStore and the per candidate logging macOS already had. The request building and proof merging move to helper_spawn.go, shared by both platforms, and helperStore picks what the helper reads per platform.
40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package certproof
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestConsoleUser_OnlyADesktopSessionCanBeValidated(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
user ConsoleUser
|
|
desktop bool
|
|
}{
|
|
{"logged in user", ConsoleUser{Name: "maycon", UID: 501, GID: 20}, true},
|
|
{"login window as root", ConsoleUser{Name: "root", UID: 0}, false},
|
|
{"login window by name", ConsoleUser{Name: "loginwindow", UID: 0}, false},
|
|
{"named user still at uid 0", ConsoleUser{Name: "admin", UID: 0}, false},
|
|
{"no console user", ConsoleUser{}, false},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assert.Equal(t, tt.desktop, tt.user.hasDesktop(), "only a real desktop session offers a login keychain")
|
|
})
|
|
}
|
|
}
|
|
|
|
// CurrentConsoleUser runs against the real SystemConfiguration framework. A machine with
|
|
// a desktop open must report a non-root user; a headless runner must report none.
|
|
func TestCurrentConsoleUser_AgreesWithItself(t *testing.T) {
|
|
user, ok := CurrentConsoleUser()
|
|
if !ok {
|
|
t.Log("no console user, running headless")
|
|
return
|
|
}
|
|
assert.NotEmpty(t, user.Name, "a console user must have a name")
|
|
assert.NotZero(t, user.UID, "a desktop session never belongs to uid 0")
|
|
assert.True(t, user.hasDesktop(), "a reported console user must be a desktop session")
|
|
}
|