mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-25 08:09:07 +02:00
[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
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user