Repository: netbox-community/netbox

Issue:
Enable `ENFORCE_GLOBAL_UNIQUE` by default
### NetBox version

v3.6.6

### Feature type

Change to existing functionality

### Proposed functionality

Change the default value of the [`ENFORCE_GLOBAL_UNIQUE`](https://docs.netbox.dev/en/stable/configuration/miscellaneous/#enforce_global_unique) configuration parameter from false to true. This will enforce unique IP addressing within the global (non-VRF) table by default.

This change would affect only deployments without any configuration already defined.

Please use a :+1: or :-1: response below to indicate your support for/opposition to this proposed change.

### Use case

Enforcing unique IP space by default is more restrictive and thus safer than the current default. Obviously, the parameter can still be toggled as needed.

This change would also be consistent with the `enforce_unique` field on the VRF model, which defaults to True.

### Database changes

_No response_

### External dependencies

_No response_


Discussion:

Resolving patch:
diff --git a/netbox/netbox/config/parameters.py b/netbox/netbox/config/parameters.py
--- a/netbox/netbox/config/parameters.py
+++ b/netbox/netbox/config/parameters.py
@@ -66,7 +66,7 @@ def __init__(self, name, label, default, description='', field=None, field_kwarg
     ConfigParam(
         name='ENFORCE_GLOBAL_UNIQUE',
         label=_('Globally unique IP space'),
-        default=False,
+        default=True,
         description=_("Enforce unique IP addressing within the global table"),
         field=forms.BooleanField
     ),


Test patch:
diff --git a/netbox/ipam/tests/test_models.py b/netbox/ipam/tests/test_models.py
--- a/netbox/ipam/tests/test_models.py
+++ b/netbox/ipam/tests/test_models.py
@@ -232,7 +232,6 @@ def test_duplicate_global(self):
         duplicate_prefix = Prefix(prefix=IPNetwork('192.0.2.0/24'))
         self.assertIsNone(duplicate_prefix.clean())
 
-    @override_settings(ENFORCE_GLOBAL_UNIQUE=True)
     def test_duplicate_global_unique(self):
         Prefix.objects.create(prefix=IPNetwork('192.0.2.0/24'))
         duplicate_prefix = Prefix(prefix=IPNetwork('192.0.2.0/24'))
@@ -471,7 +470,6 @@ def test_duplicate_global(self):
         duplicate_ip = IPAddress(address=IPNetwork('192.0.2.1/24'))
         self.assertIsNone(duplicate_ip.clean())
 
-    @override_settings(ENFORCE_GLOBAL_UNIQUE=True)
     def test_duplicate_global_unique(self):
         IPAddress.objects.create(address=IPNetwork('192.0.2.1/24'))
         duplicate_ip = IPAddress(address=IPNetwork('192.0.2.1/24'))
@@ -489,19 +487,16 @@ def test_duplicate_vrf_unique(self):
         duplicate_ip = IPAddress(vrf=vrf, address=IPNetwork('192.0.2.1/24'))
         self.assertRaises(ValidationError, duplicate_ip.clean)
 
-    @override_settings(ENFORCE_GLOBAL_UNIQUE=True)
     def test_duplicate_nonunique_nonrole_role(self):
         IPAddress.objects.create(address=IPNetwork('192.0.2.1/24'))
         duplicate_ip = IPAddress(address=IPNetwork('192.0.2.1/24'), role=IPAddressRoleChoices.ROLE_VIP)
         self.assertRaises(ValidationError, duplicate_ip.clean)
 
-    @override_settings(ENFORCE_GLOBAL_UNIQUE=True)
     def test_duplicate_nonunique_role_nonrole(self):
         IPAddress.objects.create(address=IPNetwork('192.0.2.1/24'), role=IPAddressRoleChoices.ROLE_VIP)
         duplicate_ip = IPAddress(address=IPNetwork('192.0.2.1/24'))
         self.assertRaises(ValidationError, duplicate_ip.clean)
 
-    @override_settings(ENFORCE_GLOBAL_UNIQUE=True)
     def test_duplicate_nonunique_role(self):
         IPAddress.objects.create(address=IPNetwork('192.0.2.1/24'), role=IPAddressRoleChoices.ROLE_VIP)
         IPAddress.objects.create(address=IPNetwork('192.0.2.1/24'), role=IPAddressRoleChoices.ROLE_VIP)