netbird
netbird copied to clipboard
Add option to disable default all-to-all policy
Describe your changes
This PR introduces a new configuration option DisableDefaultPolicy that prevents the creation of the default all-to-all policy when new accounts are created. This is useful for automation scenarios where explicit policies are preferred.
Key Changes:
- Added DisableDefaultPolicy flag to the management server config
- Modified account creation logic to respect this flag
- Updated all test cases to explicitly pass the flag (defaulting to false to maintain backward compatibility)
- Propagated the flag through the account manager initialization chain
Testing:
- Verified default behavior remains unchanged when flag is false
- Confirmed no default policy is created when flag is true
- All existing tests pass with the new parameter
Issue ticket number and link
Closes #3932
Stack
Checklist
- [ ] Is it a bug fix
- [ ] Is a typo/documentation fix
- [x] Is a feature enhancement
- [x] It is a refactor
- [ ] Created tests that fail without the change (if possible)
- [ ] Extended the README / documentation, if necessary
By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.
@aliamerj Thanks for your contribution! Could you please take a look at the failing tests?
@bcmmbaga my bad forgot to refactor one of the tests, Now i think all good
I don't know why i am getting the Linux / Management / Benchmark (API) Failing
i will work on the setup.env and tests next , Thank you for feedback
@bcmmbaga
I think I set up the setup.env correctly , did i miss anything ?
Quality Gate passed
Issues
0 New issues
1 Accepted issue
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code
@bcmmbaga, Do we need to have a third commit to add some tests ?
@mlsmaycon
Thanks for the review! I want to clarify how the implementation handles the "All" group and default policy:
In the AddAllGroup function:
func (a *Account) AddAllGroup(disableDefaultPolicy bool) error {
if len(a.Groups) == 0 {
// 1. ALWAYS create the "All" group
allGroup := &Group{...}
a.Groups = map[string]*Group{allGroup.ID: allGroup}
// 2. Only conditionally create the policy
if disableDefaultPolicy {
return nil // Skip policy creation
}
// 3. Create default policy (only when not disabled)
defaultPolicy := &Policy{...}
a.Policies = []*Policy{defaultPolicy}
}
return nil
}
The "All" group is always created regardless of the disableDefaultPolicy flag
Only the policy creation is conditional
In account creation paths:
// newAccountWithId ALWAYS calls AddAllGroup
func newAccountWithId(..., disableDefaultPolicy bool) *Account {
acc := &Account{...}
acc.AddAllGroup(disableDefaultPolicy) // Always called
return acc
}
// GetOrCreateAccountByPrivateDomain ALWAYS calls AddAllGroup
newAccount.AddAllGroup(am.DisableDefaultPolicy)
This ensures:
- The "All" group is always present (required for system functionality)
- The default policy is only created when not disabled
- Complete separation between group and policy creation
So I didn't get it , what should i change ?