[PR #6559] [management] validate network resource existence when creating or updating groups #26149

Open
opened 2026-08-05 07:06:57 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/6559
Author: @matteoepitech
Created: 6/27/2026
Status: 🔄 Open

Base: mainHead: fix/3495-validate-group-resources


📝 Commits (1)

  • abd3e16 [management] validate network resource existence when creating/updating groups

📊 Changes

3 files changed (+67 additions, -1 deletions)

View changed files

📝 management/server/group.go (+1 -1)
management/server/group_resource_validation.go (+21 -0)
📝 management/server/group_test.go (+45 -0)

📄 Description

Describe your changes

The groups endpoint accepted any resource ID without checking that the referenced
network resource actually exists. Sending a POST or PUT to /api/groups with a
non-existent resource ID returned a 200 and created the group, but the resource
never showed up in the dashboard and was awkward to remove afterwards.

validateNewGroup now looks up every referenced resource with GetNetworkResourceByID,
so create, update and bulk group operations reject unknown resource IDs with a
NotFound error. Clearing a group's resources with an empty list still works, which
preserves the recovery path described in the issue.

Note on the error type: I reused the store's existing NewNetworkResourceNotFoundError
(NotFound, which maps to a 4xx) for consistency with the rest of the codebase. Happy
to switch it to InvalidArgument if a 400 is preferred.

Closes #3495

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (TestDefaultAccountManager_CreateGroupWithResources)
  • This change does not modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature, OR I have discussed it with the NetBird team beforehand. The assigned maintainer requested this exact validation in issue #3495.

Documentation

  • Documentation is not needed for this change. It only rejects resource IDs that were previously accepted by mistake; there is no new user-facing behavior to document.

Summary by CodeRabbit

  • Bug Fixes
    • Group creation and updates now validate that every referenced network resource exists.
    • Requests with missing or invalid resource IDs are rejected with a not-found error.
  • Tests
    • Added a unit test that verifies group creation fails when resources reference a non-existent ID and succeeds when referencing an existing network resource.

🔄 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/6559 **Author:** [@matteoepitech](https://github.com/matteoepitech) **Created:** 6/27/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/3495-validate-group-resources` --- ### 📝 Commits (1) - [`abd3e16`](https://github.com/netbirdio/netbird/commit/abd3e167a444f585c7d3f0fdb5d45a9b5b32422a) [management] validate network resource existence when creating/updating groups ### 📊 Changes **3 files changed** (+67 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `management/server/group.go` (+1 -1) ➕ `management/server/group_resource_validation.go` (+21 -0) 📝 `management/server/group_test.go` (+45 -0) </details> ### 📄 Description ## Describe your changes The groups endpoint accepted any resource ID without checking that the referenced network resource actually exists. Sending a POST or PUT to /api/groups with a non-existent resource ID returned a 200 and created the group, but the resource never showed up in the dashboard and was awkward to remove afterwards. validateNewGroup now looks up every referenced resource with GetNetworkResourceByID, so create, update and bulk group operations reject unknown resource IDs with a NotFound error. Clearing a group's resources with an empty list still works, which preserves the recovery path described in the issue. Note on the error type: I reused the store's existing NewNetworkResourceNotFoundError (NotFound, which maps to a 4xx) for consistency with the rest of the codebase. Happy to switch it to InvalidArgument if a 400 is preferred. ## Issue ticket number and link Closes #3495 ### Checklist - [x] Is it a bug fix - [ ] Is a typo/documentation fix - [ ] Is a feature enhancement - [ ] It is a refactor - [x] Created tests that fail without the change (TestDefaultAccountManager_CreateGroupWithResources) - [x] This change does not modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature, OR I have discussed it with the NetBird team beforehand. The assigned maintainer requested this exact validation in issue #3495. ## Documentation - [x] Documentation is not needed for this change. It only rejects resource IDs that were previously accepted by mistake; there is no new user-facing behavior to document. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Group creation and updates now validate that every referenced network resource exists. * Requests with missing or invalid resource IDs are rejected with a not-found error. * **Tests** * Added a unit test that verifies group creation fails when resources reference a non-existent ID and succeeds when referencing an existing network resource. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <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 07:06:57 -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#26149