[PR #6771] [management] Add setting to let regular users view their groups' peers #29877

Open
opened 2026-08-05 08:09:15 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/6771
Author: @zerotohero
Created: 7/14/2026
Status: 🔄 Open

Base: mainHead: feat/regular-users-group-peers-view


📝 Commits (1)

  • b073462 [management] Add setting to let regular users view their groups' peers

📊 Changes

10 files changed (+722 additions, -227 deletions)

View changed files

📝 management/server/http/handlers/accounts/accounts_handler.go (+26 -22)
📝 management/server/http/handlers/accounts/accounts_handler_test.go (+216 -147)
📝 management/server/http/handlers/peers/peers_handler.go (+24 -1)
📝 management/server/http/handlers/peers/peers_handler_test.go (+87 -6)
📝 management/server/peer.go (+46 -1)
📝 management/server/peer_test.go (+267 -11)
📝 management/server/store/sql_store.go (+36 -32)
📝 management/server/types/settings.go (+13 -7)
📝 shared/management/http/api/openapi.yml (+4 -0)
📝 shared/management/http/api/types.gen.go (+3 -0)

📄 Description

Summary

Since v0.70, regular (non-admin) users can only see peers they personally registered. PR #6006 dropped the policy-aware expansion from the peer-read path, and no open-source setting restores visibility of peers reachable via a user's groups short of granting full admin (which also grants config write). This implements the fix proposed in discussion #6680; the regression was reported in discussion #6599.

Adds an opt-in, default-off account setting RegularUsersGroupPeersViewEnabled. When enabled, a regular user additionally sees peers that belong to groups they are a member of (user.AutoGroups), in addition to peers they registered themselves. Behavior is unchanged when the setting is off.

RegularUsersViewBlocked keeps precedence: when it is on, the user still sees no peers, regardless of the new setting.

Changes

  • Setting (management/server/types/settings.go): new RegularUsersGroupPeersViewEnabled bool field + Copy().
  • Persistence (management/server/store/sql_store.go): new settings_regular_users_group_peers_view_enabled column in the raw pgx getAccount SELECT + scan; the sqlite path is handled by GORM auto-migrate.
  • API (shared/management/http/api/openapi.yml + regenerated types.gen.go): optional regular_users_group_peers_view_enabled on AccountSettings, wired both directions in the accounts handler.
  • Peer list (GetPeers): on the restricted path, union the user's own peers with GetPeersByGroupIDs(user.AutoGroups), deduped by peer ID.
  • Peer detail (GetPeer): allow access when the target peer shares at least one group with the user.
  • Accessible peers (GetAccessiblePeers): the same shared-group gate.

No store interface changes — GetPeersByGroupIDs and GetPeerGroupIDs already existed.

Testing

  • GetPeers: off => own only; on => own ∪ group peers, deduped (a peer both owned and in-group appears exactly once); a peer in a disjoint group is excluded; RegularUsersViewBlocked on => empty; admin / peers:read unaffected; nil AutoGroups does not panic.
  • GetPeer: owner / admin allowed; shared-group allowed; disjoint-group denied; blocked-precedence denied.
  • GetAccessiblePeers: disjoint-group excluded (proves real group intersection, not "peer is in some group"), shared-group included, off unchanged.
  • Accounts handler: regular_users_group_peers_view_enabled round-trips true/false; omitted defaults to false.
  • Mutation-tested: independently breaking the dedup, the RegularUsersViewBlocked precedence, the GetPeer intersection gate, or the default-off each fails at least one test.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/6771 **Author:** [@zerotohero](https://github.com/zerotohero) **Created:** 7/14/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/regular-users-group-peers-view` --- ### 📝 Commits (1) - [`b073462`](https://github.com/netbirdio/netbird/commit/b0734625bee1a489e6b2863c67f59a1fd94fecc0) [management] Add setting to let regular users view their groups' peers ### 📊 Changes **10 files changed** (+722 additions, -227 deletions) <details> <summary>View changed files</summary> 📝 `management/server/http/handlers/accounts/accounts_handler.go` (+26 -22) 📝 `management/server/http/handlers/accounts/accounts_handler_test.go` (+216 -147) 📝 `management/server/http/handlers/peers/peers_handler.go` (+24 -1) 📝 `management/server/http/handlers/peers/peers_handler_test.go` (+87 -6) 📝 `management/server/peer.go` (+46 -1) 📝 `management/server/peer_test.go` (+267 -11) 📝 `management/server/store/sql_store.go` (+36 -32) 📝 `management/server/types/settings.go` (+13 -7) 📝 `shared/management/http/api/openapi.yml` (+4 -0) 📝 `shared/management/http/api/types.gen.go` (+3 -0) </details> ### 📄 Description ## Summary Since v0.70, regular (non-admin) users can only see peers they personally registered. [PR #6006](https://github.com/netbirdio/netbird/pull/6006) dropped the policy-aware expansion from the peer-read path, and no open-source setting restores visibility of peers reachable via a user's groups short of granting full `admin` (which also grants config write). This implements the fix proposed in [discussion #6680](https://github.com/netbirdio/netbird/discussions/6680); the regression was reported in [discussion #6599](https://github.com/netbirdio/netbird/discussions/6599). Adds an **opt-in, default-off** account setting `RegularUsersGroupPeersViewEnabled`. When enabled, a regular user additionally sees peers that belong to groups they are a member of (`user.AutoGroups`), in addition to peers they registered themselves. Behavior is unchanged when the setting is off. `RegularUsersViewBlocked` keeps precedence: when it is on, the user still sees no peers, regardless of the new setting. ## Changes - **Setting** (`management/server/types/settings.go`): new `RegularUsersGroupPeersViewEnabled bool` field + `Copy()`. - **Persistence** (`management/server/store/sql_store.go`): new `settings_regular_users_group_peers_view_enabled` column in the raw pgx `getAccount` SELECT + scan; the sqlite path is handled by GORM auto-migrate. - **API** (`shared/management/http/api/openapi.yml` + regenerated `types.gen.go`): optional `regular_users_group_peers_view_enabled` on `AccountSettings`, wired both directions in the accounts handler. - **Peer list** (`GetPeers`): on the restricted path, union the user's own peers with `GetPeersByGroupIDs(user.AutoGroups)`, deduped by peer ID. - **Peer detail** (`GetPeer`): allow access when the target peer shares at least one group with the user. - **Accessible peers** (`GetAccessiblePeers`): the same shared-group gate. No store interface changes — `GetPeersByGroupIDs` and `GetPeerGroupIDs` already existed. ## Testing - `GetPeers`: off => own only; on => own ∪ group peers, deduped (a peer both owned and in-group appears exactly once); a peer in a disjoint group is excluded; `RegularUsersViewBlocked` on => empty; admin / `peers:read` unaffected; nil `AutoGroups` does not panic. - `GetPeer`: owner / admin allowed; shared-group allowed; disjoint-group denied; blocked-precedence denied. - `GetAccessiblePeers`: disjoint-group excluded (proves real group intersection, not "peer is in some group"), shared-group included, off unchanged. - Accounts handler: `regular_users_group_peers_view_enabled` round-trips true/false; omitted defaults to false. - Mutation-tested: independently breaking the dedup, the `RegularUsersViewBlocked` precedence, the `GetPeer` intersection gate, or the default-off each fails at least one test. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 08:09:15 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#29877