[change] VpnClient objects should block modifications
To be done after #1486 is merged.
Describe the bug Currently, VpnClient objects allow direct modification of their fields. This is problematic because it can lead to inconsistent state and data integrity issues. The expected behavior is that VpnClient objects should be immutable after creation, and any configuration changes should require re-creating the object instead of modifying existing fields.
Expected behavior VpnClient objects should not allow direct field modifications. Instead, users should be required to delete the existing VpnClient object and create a new one (by re-applying template) with the desired configuration. This ensures data consistency and makes the object lifecycle management explicit and predictable.
We shall add model validation to disallow any changes to the VpnClient fields post creation.
System Informatioon:
- OS: [e.g. Ubuntu 24.04 LTS]
- Python Version: [e.g. Python 3.11.2]
- Django Version: [e.g. Django 4.2.5]
- Browser and Browser Version (if applicable): [e.g. Chromium v126.0.6478.126]
Root Cause
VpnClient is mutable by default because it is a standard Django model without any model-level immutability checks. As a result, existing instances can be modified, even though the intended lifecycle is create/delete only.
Proposed Fix
Enforce immutability in AbstractVpnClient by validating updates in both clean() and save(). Allow only the ip field to be updated since it is legitimately modified by the subnet provisioning flow. This preserves the intended behavior, prevents accidental updates, and fixes unnecessary re-provisioning on re-save. @pandafy @mwarning
@sameerrandive-dev your poposal looks good.
This issue has been automatically assigned to @sameerrandive-dev who opened PR #1431 to address it. 🎯
Linking these issues for easier management: https://github.com/openwisp/openwisp-controller/issues/1397
This issue has been automatically assigned to @sameerrandive-dev who opened PR #1431 to address it. 🎯
Can i take up this issue @pandafy @nemesifier ?
I'd like to work on this — happy to add model validation to block field modifications on VpnClient after creation. Could someone confirm this is still unassigned before I start?
Hi @pandafy, I would like to work on this. I plan to override the clean() method in AbstractVpnClient to raise a ValidationError if self._state.adding is False, and I'll add the corresponding unit tests in test_vpn.py. Let me know if that sounds like the right approach!
Hi @goyaladitay11 👋,
Thank you for your interest in contributing to OpenWISP! 🎉
According to our contributing guidelines, you don't need to wait to be assigned to start working on an issue. We encourage you to:
- Fork the repository and start working on your solution
- Open a Pull Request (PR) as soon as possible - even as a draft if it's still in progress
- Link your PR to this issue by including
Fixes #1428in the PR description
Note: We suggest Fixes because this appears to be a bug. You can also use:
Closes #1428for features/changesFixes #1428for bugsRelated to #1428for PRs that contribute but don't completely solve the issue
Once you open a PR that references this issue, you will be automatically assigned to it.
This approach helps us:
- See your progress and provide early feedback
- Avoid multiple contributors working on the same issue unknowingly
- Keep the contribution process moving smoothly
We look forward to your contribution! If you have any questions, feel free to ask in the PR or check our documentation.
Happy coding! 🚀
Hi @dharmendra26-wiz 👋,
Thank you for opening PR #1500 to address this issue!
GitHub did not allow the bot to assign this issue to you automatically, because you are not yet an organization member and have not previously commented on this issue.
To get assigned, please comment @openwisp-companion assign on this issue. Your comment satisfies GitHub's requirement and the bot will then assign the issue to you.
@openwisp-companion assign
This issue has been assigned to @dharmendra26-wiz who opened PR #1500 to address it. 🎯