瀏覽代碼

fix(ipam): Prevent reassignment of OOB IPs

Disable reassignment of IP addresses designated as primary or OOB for
parent objects. Adds validation to block changes when an IP is marked as
the OOB IP.

Fixes #21050
Martin Hauser 1 月之前
父節點
當前提交
f4892caa51
共有 2 個文件被更改,包括 9 次插入2 次删除
  1. 2 2
      netbox/ipam/forms/model_forms.py
  2. 7 0
      netbox/ipam/models/ip.py

+ 2 - 2
netbox/ipam/forms/model_forms.py

@@ -372,8 +372,8 @@ class IPAddressForm(TenancyForm, PrimaryModelForm):
                     'virtual_machine_id': instance.assigned_object.virtual_machine.pk,
                     'virtual_machine_id': instance.assigned_object.virtual_machine.pk,
                 })
                 })
 
 
-        # Disable object assignment fields if the IP address is designated as primary
-        if self.initial.get('primary_for_parent'):
+        # Disable object assignment fields if the IP address is designated as primary or OOB
+        if self.initial.get('primary_for_parent') or self.initial.get('oob_for_parent'):
             self.fields['interface'].disabled = True
             self.fields['interface'].disabled = True
             self.fields['vminterface'].disabled = True
             self.fields['vminterface'].disabled = True
             self.fields['fhrpgroup'].disabled = True
             self.fields['fhrpgroup'].disabled = True

+ 7 - 0
netbox/ipam/models/ip.py

@@ -940,6 +940,13 @@ class IPAddress(ContactsMixin, PrimaryModel):
                     _("Cannot reassign IP address while it is designated as the primary IP for the parent object")
                     _("Cannot reassign IP address while it is designated as the primary IP for the parent object")
                 )
                 )
 
 
+            # can't use is_oob_ip as self.assigned_object might be changed
+            if hasattr(original_parent, 'oob_ip') and original_parent.oob_ip_id == self.pk:
+                if parent != original_parent:
+                    raise ValidationError(
+                        _("Cannot reassign IP address while it is designated as the OOB IP for the parent object")
+                    )
+
         # Validate IP status selection
         # Validate IP status selection
         if self.status == IPAddressStatusChoices.STATUS_SLAAC and self.family != 6:
         if self.status == IPAddressStatusChoices.STATUS_SLAAC and self.family != 6:
             raise ValidationError({
             raise ValidationError({