Disable ownership on mobile

This commit is contained in:
Theodor S. Midtlien
2026-09-22 15:29:39 +02:00
parent a785814a3f
commit 9d40a09459
9 changed files with 70 additions and 10 deletions
@@ -1,3 +1,5 @@
//go:build !ios && !android
package profilemanager
import (
@@ -0,0 +1,23 @@
//go:build ios || android
package profilemanager
import (
"os/user"
"strconv"
"github.com/netbirdio/netbird/client/internal/ipcauth"
)
// MigrateLegacyProfiles is a no-op on mobile
func (s *ServiceManager) MigrateLegacyProfiles() error {
return nil
}
// PrincipalForUser turns a resolved account into an owner principal.
func PrincipalForUser(u *user.User) (string, bool) {
if uid, err := strconv.ParseUint(u.Uid, 10, 32); err == nil {
return ipcauth.UIDPrincipal(uint32(uid)), true
}
return "", false
}
@@ -1,3 +1,5 @@
//go:build !ios && !android
package profilemanager
import (
@@ -44,6 +44,9 @@ func (p *Profile) AccessibleBy(id ipcauth.Identity) bool {
if !id.Known() {
return false
}
if ipcauth.ProfileOwnershipDisabled() {
return true
}
if ipcauth.IsPrivilegedCaller(id) {
return true
}
@@ -7,8 +7,19 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/netbirdio/netbird/client/internal/ipcauth"
)
func TestAccessibleByReachesUnownedProfileWhenOwnershipDisabled(t *testing.T) {
t.Setenv(ipcauth.EnvDisableProfileOwnership, "true")
unowned := Profile{}
caller := ipcauth.KnownForTest(ipcauth.Identity{UID: 4242})
assert.True(t, unowned.AccessibleBy(caller), "an unowned profile is reachable with ownership off")
}
func withTempConfigDir(t *testing.T, testFunc func(configDir string)) {
t.Helper()
tempDir := t.TempDir()