openwisp / openwisp-controller

Network and WiFi controller: provisioning, configuration management and updates, (pull via openwisp-config or push via SSH), x509 PKI management and more. Mainly OpenWRT, but designed to work also on other systems.
https://openwisp.io/docs/dev/controller/
Other
559 stars 182 forks source link

[bug] Deleting VPN template does not delete VpnClient objects #831

Open pandafy opened 9 months ago

pandafy commented 9 months ago

How to replicate

  1. Open Django shell (in command line) and check the number of VpnClient objects using this query VpnClient.objects.count()
  2. Create a VPN server object with OpenVPN backend
  3. Create a VPN template for this VPN server
  4. Add the VPN template to a device
  5. Go to the VPN template page and delete the Template
  6. Open Django shell (in command line) and check the number of VpnClient objects using this query VpnClient.objects.count()

Expected outcome The number of VpnClients is different in Step 1 and Step 6 should be same.

Actual outcome

The number of VpnClients is different in Step 1 and Step 6 (increased by one). It is because the deletion of VPN template didn't trigger deletion of related VpnClient objects (there is no direct relation).

pandafy commented 9 months ago

I found that it is possible to have two different VPN templates for the same VPN server object. But, it is not possible to apply both the templates on the same device, as the JSONSchema generates the following error

There is a conflict with the specified templates. Invalid configuration triggered by "#/files", validator says:

Screenshot from 2024-02-09 17-53-02

I think we should discourage using different templates for the same VPN server object on the same device using validation (we can create a separate issue for this).

pandafy commented 9 months ago

We should double check the working of the following code. I think, it is not getting triggered when the template object is deleted.

https://github.com/openwisp/openwisp-controller/blob/226442c47be5031e64033ae44c8b00aaf2623c68/openwisp_controller/config/base/config.py#L229-L275