Files
netbird/client/internal/ipcauth/consoleuser.go
T
Theodor Midtlien 90052cbefb [client] Profile ownership console user tofu (#7529)
* Add consoleuser and stamp default profile on known username in migration

* Refactor consoleuser to verify Id, fix seats on linux and default stamp

* Add default profile claim

* Add disable auto-claim of default profile and always fail close

* Add disable auto-claim flag to migration

* Adding timeout to console user on Linux and close library load on darwin

* Fixed failed close test

* Close both Dlopen for darwin

* Replace RegisterFunc with purego.Dlsym to avoid possible panic

* Fix freebsd tty enumeration

* Fix active profile migration logic and add test

* Log defaultClaimDisabled error once

* Guard against panicking console user lookup.

* Fix merge conflict

* Fix broken tests
2026-09-17 11:20:13 +02:00

44 lines
1.1 KiB
Go

package ipcauth
import (
"sync"
log "github.com/sirupsen/logrus"
)
// logConsolePanic keeps the notice to once per process.
var logConsolePanic sync.Once
// IsConsoleUser reports whether a caller is sitting at one of this machine's
// consoles right now.
//
// It is false on a headless machine, which has no seat to sit at, on a
// platform that exposes no console-user lookup at all, and whenever the lookup
// fails. Callers must read that as "cannot confirm" rather than as proof of
// absence. It gates handing out ownership, so a lookup that cannot answer
// withholds a claim, and never grants one.
func IsConsoleUser(id Identity) bool {
if !id.Known() {
return false
}
return guardConsoleLookup(id, isConsoleUser)
}
// guardConsoleLookup runs a platform lookup and turns a panic out of it into
// "cannot confirm".
func guardConsoleLookup(id Identity, lookup func(Identity) bool) (atConsole bool) {
defer func() {
r := recover()
if r == nil {
return
}
atConsole = false
logConsolePanic.Do(func() {
log.Errorf("console user lookup panicked, no caller will be treated as being at the console: %v", r)
})
}()
return lookup(id)
}