Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Added auth and ip assignment for ZeroTier member #799

Merged
merged 108 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
a16f810
[ci] Added gsoc23 to CI build branches
Aryamanz29 Jun 20, 2023
0f7d641
[feature] Added support for ZeroTier VPN backend #604
Aryamanz29 Jun 20, 2023
51f4715
[req-changes] Added first review changes
Aryamanz29 Jun 26, 2023
82059b9
[requested-changes] Added second review changes
Aryamanz29 Jul 2, 2023
f8c88ec
[req-changes] Added API call to add controller to the network
Aryamanz29 Jul 14, 2023
9ecf341
[req-changes] Added retry mechanism to ZeroTier API tasks
Aryamanz29 Jul 15, 2023
868deb2
[requested-changes] Added new notification type for API task
Aryamanz29 Jul 16, 2023
7e6066a
[change] Updated zerotier auto_client method
Aryamanz29 Jul 23, 2023
1dcc1a9
[requested-changes] Third round of review feedback incorporated
Aryamanz29 Jul 23, 2023
02d298e
[fix] Fixed zerotier migration conflicts
Aryamanz29 Jul 23, 2023
272fe1a
[tests] Added zerotier vpn backend tests
Aryamanz29 Jul 24, 2023
c88c545
[docs] Added how to setup zerotier tunnels
Aryamanz29 Jul 25, 2023
74c5f43
[fix] Fixed zerotier server deletion 404
Aryamanz29 Jul 25, 2023
4f99038
[req-change] Avoid sending recovery notifications after retrying API …
Aryamanz29 Jul 26, 2023
fd93b51
[tests] Improved zerotier vpn deletion tests
Aryamanz29 Jul 26, 2023
555ac55
[tests] Added zerotier api tasks notifications tests
Aryamanz29 Jul 26, 2023
737e05e
[changes] Controller node should leave network after deletion of zt v…
Aryamanz29 Jul 30, 2023
016248f
[deps] Updated netjsonconfig branch to gsoc23
Aryamanz29 Jul 30, 2023
2efd130
[req-changes] Fixed host validation errors and improved tests
Aryamanz29 Aug 1, 2023
9776c3f
[req-changes] Improved zerotier tutorial docs
Aryamanz29 Aug 1, 2023
aaa8ee5
[ci] Added gsoc23 to CI build branches
Aryamanz29 Jun 20, 2023
30942ea
Merge branch 'gsoc23' into issue-604/add-zerotier-vpn-backend
Aryamanz29 Aug 1, 2023
3257d41
[docs] Added OPENWISP_CONTROLLER_API_TASK_RETRY_OPTIONS
Aryamanz29 Aug 1, 2023
d6ac216
[feature] Added auth and ip assignment for ZeroTier members
Aryamanz29 Jul 28, 2023
38e8efa
[changes] Added cache key for ZeroTier identity secret generation
Aryamanz29 Jul 29, 2023
283a029
[changes] Improved zerotier identity in system context variable UI
Aryamanz29 Jul 29, 2023
8b94371
[req-changes] Improved zt vpn client logic
Aryamanz29 Jul 31, 2023
23a8304
[change] Removed vpn server pk from zt vpn client system variables keys
Aryamanz29 Jul 31, 2023
497541f
[deps] Changed netjsonconfig branch
Aryamanz29 Jul 31, 2023
26f0cdb
[changes] Fixed merge conflicts and improved zt vpn client query for …
Aryamanz29 Aug 1, 2023
3787f10
[changes] Dont send notification for leave member operation when Vpn …
Aryamanz29 Aug 2, 2023
f8273c7
[tests] Fixed existing zerotier vpn backend tests
Aryamanz29 Aug 2, 2023
ec34c36
[tests] Added zt generate identity tests
Aryamanz29 Aug 2, 2023
b3353ad
[ci] Added gsoc23 to CI build branches
Aryamanz29 Jun 20, 2023
002b7aa
[feature] Added support for ZeroTier VPN backend #604
Aryamanz29 Jun 20, 2023
38bd1f2
[req-changes] Added first review changes
Aryamanz29 Jun 26, 2023
18b249e
[requested-changes] Added second review changes
Aryamanz29 Jul 2, 2023
867fa27
[req-changes] Added API call to add controller to the network
Aryamanz29 Jul 14, 2023
95835cc
[req-changes] Added retry mechanism to ZeroTier API tasks
Aryamanz29 Jul 15, 2023
fd2df93
[requested-changes] Added new notification type for API task
Aryamanz29 Jul 16, 2023
6b04c13
[change] Updated zerotier auto_client method
Aryamanz29 Jul 23, 2023
b88c742
[requested-changes] Third round of review feedback incorporated
Aryamanz29 Jul 23, 2023
bb74bb1
[fix] Fixed zerotier migration conflicts
Aryamanz29 Jul 23, 2023
1935b7d
[tests] Added zerotier vpn backend tests
Aryamanz29 Jul 24, 2023
1acd2fb
[docs] Added how to setup zerotier tunnels
Aryamanz29 Jul 25, 2023
5d9dc03
[fix] Fixed zerotier server deletion 404
Aryamanz29 Jul 25, 2023
283dba8
[req-change] Avoid sending recovery notifications after retrying API …
Aryamanz29 Jul 26, 2023
f119e8b
[tests] Improved zerotier vpn deletion tests
Aryamanz29 Jul 26, 2023
9062253
[tests] Added zerotier api tasks notifications tests
Aryamanz29 Jul 26, 2023
a2d3aba
[changes] Controller node should leave network after deletion of zt v…
Aryamanz29 Jul 30, 2023
7aaa908
[deps] Updated netjsonconfig branch to gsoc23
Aryamanz29 Jul 30, 2023
8d7c653
[req-changes] Fixed host validation errors and improved tests
Aryamanz29 Aug 1, 2023
30a8240
[req-changes] Improved zerotier tutorial docs
Aryamanz29 Aug 1, 2023
0339fc4
[docs] Added OPENWISP_CONTROLLER_API_TASK_RETRY_OPTIONS
Aryamanz29 Aug 1, 2023
c8a18e3
[fix] Fixed migration merge conflicts
Aryamanz29 Aug 3, 2023
7c72d31
Merge branch 'issue-604/add-zerotier-vpn-backend' into issue-606/zero…
Aryamanz29 Aug 3, 2023
f9c44df
[fix] Fixed migration merge conflicts
Aryamanz29 Aug 3, 2023
31e363e
[req-changes] Worked on first review changes
Aryamanz29 Aug 4, 2023
6c9add4
[tests] Added zerotier vpn clients tests
Aryamanz29 Aug 4, 2023
42415f0
[docs] Added a note about zerotier-idtool in zt vpn client section
Aryamanz29 Aug 4, 2023
86f5273
[changes] Minor improvements in tests and zt idtool link
Aryamanz29 Aug 4, 2023
f39c996
[deps] Switched back to gsoc23
Aryamanz29 Aug 9, 2023
13a7965
[ci] Added gsoc23 to CI build branches
Aryamanz29 Jun 20, 2023
a2d0d66
[feature] Added support for ZeroTier VPN backend #604
Aryamanz29 Jun 20, 2023
676f438
[req-changes] Added first review changes
Aryamanz29 Jun 26, 2023
0412570
[requested-changes] Added second review changes
Aryamanz29 Jul 2, 2023
20822f7
[req-changes] Added API call to add controller to the network
Aryamanz29 Jul 14, 2023
e08ff13
[req-changes] Added retry mechanism to ZeroTier API tasks
Aryamanz29 Jul 15, 2023
2f39c1b
[requested-changes] Added new notification type for API task
Aryamanz29 Jul 16, 2023
19e9105
[change] Updated zerotier auto_client method
Aryamanz29 Jul 23, 2023
e9f8f1d
[requested-changes] Third round of review feedback incorporated
Aryamanz29 Jul 23, 2023
758767f
[fix] Fixed zerotier migration conflicts
Aryamanz29 Jul 23, 2023
27bc331
[tests] Added zerotier vpn backend tests
Aryamanz29 Jul 24, 2023
09131b6
[docs] Added how to setup zerotier tunnels
Aryamanz29 Jul 25, 2023
3dd2d7f
[fix] Fixed zerotier server deletion 404
Aryamanz29 Jul 25, 2023
b7f3144
[req-change] Avoid sending recovery notifications after retrying API …
Aryamanz29 Jul 26, 2023
7e9a163
[tests] Improved zerotier vpn deletion tests
Aryamanz29 Jul 26, 2023
66a1afe
[tests] Added zerotier api tasks notifications tests
Aryamanz29 Jul 26, 2023
e93fe01
[changes] Controller node should leave network after deletion of zt v…
Aryamanz29 Jul 30, 2023
da63f7b
[deps] Updated netjsonconfig branch to gsoc23
Aryamanz29 Jul 30, 2023
cc232e8
[req-changes] Fixed host validation errors and improved tests
Aryamanz29 Aug 1, 2023
2ddc642
[req-changes] Improved zerotier tutorial docs
Aryamanz29 Aug 1, 2023
6f43c34
[docs] Added OPENWISP_CONTROLLER_API_TASK_RETRY_OPTIONS
Aryamanz29 Aug 1, 2023
c92b73e
[fix] Fixed migration merge conflicts
Aryamanz29 Aug 3, 2023
07b48f7
[req-changes] Moved zerotier tasks and changed 'exc' to 'e' for consi…
Aryamanz29 Aug 11, 2023
81278e5
Merge branch 'issue-604/add-zerotier-vpn-backend' into issue-606/zero…
Aryamanz29 Aug 13, 2023
ffd4eb1
[req-changes] Moved zerotier tasks and changed 'exc' to 'e' for consi…
Aryamanz29 Aug 11, 2023
06bdb42
Merge branch 'issue-604/add-zerotier-vpn-backend' into issue-606/zero…
Aryamanz29 Aug 17, 2023
3b9e0f7
[req-changes] Moved zerotier tasks and changed 'exc' to 'e' for consi…
Aryamanz29 Aug 11, 2023
9f3079b
Merge branch 'issue-604/add-zerotier-vpn-backend' into issue-606/zero…
Aryamanz29 Aug 17, 2023
8dd834e
[feature] Added support for ZeroTier
Aryamanz29 Aug 17, 2023
9655309
Merge branch 'gsoc23' into issue-606/zerotier-member-auth-ip-assign
Aryamanz29 Aug 17, 2023
be46520
[qa] Fixed css lint errors
Aryamanz29 Aug 17, 2023
58cc7a0
[tests] Fixed zt_auto_client tests
Aryamanz29 Aug 17, 2023
e003289
[req-change] Shortened css comment
Aryamanz29 Aug 17, 2023
c1426cd
[req-changes] Improved zerotier tests assertions
Aryamanz29 Aug 21, 2023
0500e7b
[feature] Added support for ZeroTier
Aryamanz29 Aug 17, 2023
5dca274
[ci] Added gsoc23 to CI build branches
Aryamanz29 Jun 20, 2023
7e9b69e
Merge branch 'gsoc23' into issue-606/zerotier-member-auth-ip-assign
Aryamanz29 Aug 21, 2023
d997bea
[feature] Added support for ZeroTier
Aryamanz29 Aug 17, 2023
dd0bfd3
Merge branch 'gsoc23' into issue-606/zerotier-member-auth-ip-assign
Aryamanz29 Aug 21, 2023
5291846
[feature] Added support for custom ZeroTier interface name #801
Aryamanz29 Aug 22, 2023
f0bd639
[req-changes] Changed zt_identity_secret to "secret"
Aryamanz29 Aug 23, 2023
dc0fa4d
[req-change] Changed "nwid_ifname" to "networks"
Aryamanz29 Aug 29, 2023
348dd58
[req-change] Changed "member_id" to "zerotier_member_id"
Aryamanz29 Aug 29, 2023
9f77a4e
Merge branch 'gsoc23' into issue-606/zerotier-member-auth-ip-assign
Aryamanz29 Aug 31, 2023
9219c7d
[req-changes] Improved zerotier secret logic query
Aryamanz29 Sep 4, 2023
a5b41ed
[chores] Switched netjsonconfig to gsoc23 branch
nemesifier Sep 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 20 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1347,15 +1347,20 @@ from the `official website <https://www.zerotier.com/download/>`_.
be applied to. For this example, we will leave it to ``OpenWRT``.
4. Select the correct VPN server from the dropdown for the **VPN** field. Here
it is ``ZeroTier``.
5. Make sure to check the **Automatic tunnel provisioning** option.
This will enable OpenWISP to automatically provision an IP address
for each ZeroTier VPN client.
5. Ensure that the **Automatic tunnel provisioning** option is checked.
This will enable OpenWISP to automatically provision an IP address and
ZeroTier identity secrets (used for assigning member IDs) for each ZeroTier VPN client.
6. After clicking on **Save and continue editing** button, you will see details
of *ZeroTier* VPN server in **System Defined Variables**. The template
configuration will be automatically generated which you can tweak
accordingly. We will use the automatically generated VPN client configuration
for this example.

**Note:** OpenWISP uses `zerotier-idtool
<https://github.com/zerotier/ZeroTierOne/blob/dev/doc/zerotier-idtool.1.md>`_
to manage **ZeroTier identity secrets**. Please make sure that you have
`ZeroTier package installed <https://www.zerotier.com/download/>`_ on the server.

.. image:: https://raw.githubusercontent.com/openwisp/openwisp-controller/docs/docs/zerotier-tutorial/template.png
:alt: ZeroTier VPN client template example

Expand All @@ -1367,12 +1372,19 @@ OpenWISP. Register or create a device before proceeding.

1. Open the **Configuration** tab of the concerned device.
2. Select the *ZeroTier Client* template.
3. Upon clicking on **Save and continue editing** button, you will see some
entries in **System Defined Variables**. It will contain internal IP address
for the ZeroTier client on the device along with details of VPN server.
3. Upon clicking the **Save and Continue Editing** button, you will see entries
in the **System Defined Variables** section. These entries will include **zerotier_member_id**, **identity_secret**,
and the internal **IP address** of the ZeroTier client (network member) on the device, along with details of the VPN server.

.. image:: https://raw.githubusercontent.com/openwisp/openwisp-controller/docs/docs/zerotier-tutorial/device-configuration-1.png
:alt: ZeroTier VPN device configuration example 1

4. Once the configuration is successfully applied to the device, you will notice a new ZeroTier interface
that is up and running. This interface will have the name ``owzt89f498`` (where ``owzt`` is followed
by the last six hexadecimal characters of the ZeroTier **network ID**).

.. image:: https://raw.githubusercontent.com/openwisp/openwisp-controller/docs/docs/zerotier-tutorial/device-configuration.png
:alt: ZeroTier VPN device configuration example
.. image:: https://raw.githubusercontent.com/openwisp/openwisp-controller/docs/docs/zerotier-tutorial/device-configuration-2.png
:alt: ZeroTier VPN device configuration example 2

**Voila!** You have successfully configured OpenWISP
to manage ZeroTier tunnels for your devices.
Expand Down
118 changes: 95 additions & 23 deletions openwisp_controller/config/api/zerotier_service.py
Aryamanz29 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -51,36 +51,24 @@ def _get_repsonse(self, repsonse):
return repsonse

def _add_routes_and_ip_assignment(self, config):
"""
Adds ZeroTier network routes
and IP assignmentpools through OpenWISP subnet

Params:
config (dict): ZeroTier network config dict
"""
config['routes'] = [{'target': str(self.subnet), 'via': ''}]
ip_end = str(self.subnet.broadcast_address)
ip_start = str(next(self.subnet.hosts()))
config['ipAssignmentPools'] = [{"ipRangeEnd": ip_end, "ipRangeStart": ip_start}]
return config

def join_network(self, network_id):
url = f'{self.url}/network/{network_id}'
response = requests.post(
url, json={}, headers=self.headers, timeout=REQUEST_TIMEOUT
)
return response

def leave_network(self, network_id):
url = f'{self.url}/network/{network_id}'
response = requests.delete(url, headers=self.headers, timeout=REQUEST_TIMEOUT)
return response

def update_network_member(self, node_id, network_id, member_ip):
url = f'{self.url}/controller/network/{network_id}/member/{node_id}'
# Authorize and assign ip to the network member
response = requests.post(
url,
json={'authorized': True, 'ipAssignments': [str(member_ip)]},
headers=self.headers,
timeout=5,
)
return response

def get_node_status(self):
"""
Fetches the status of the running ZeroTier controller
This method is used for host validation during VPN creation
"""
url = f'{self.url}/status'
try:
response = requests.get(url, headers=self.headers, timeout=REQUEST_TIMEOUT)
Expand All @@ -94,7 +82,41 @@ def get_node_status(self):
}
)

def join_network(self, network_id):
"""
Adds ZeroTier Controller to the specified network

Params:
network_id (str): ID of the network to join
"""
url = f'{self.url}/network/{network_id}'
response = requests.post(
url, json={}, headers=self.headers, timeout=REQUEST_TIMEOUT
)
return response

def leave_network(self, network_id):
"""
Removes ZeroTier Controller from the specified network

Params:
network_id (str): ID of the network to leave
"""
url = f'{self.url}/network/{network_id}'
response = requests.delete(url, headers=self.headers, timeout=REQUEST_TIMEOUT)
return response

def create_network(self, node_id, config):
"""
Creates a new network in the ZeroTier Controller

Params:
node_id (str): ID of the controller node
config (dict): Configuration of the new network

Returns:
network_config(dict): Filtered response from the ZeroTier Controller API
"""
url = f"{self.url}{self._get_endpoint('network', 'create', node_id)}"
config = self._add_routes_and_ip_assignment(config)
try:
Expand All @@ -110,6 +132,13 @@ def create_network(self, node_id, config):
)

def update_network(self, config, network_id):
"""
Update configuration of an existing ZeroTier Controller network

Params:
config (dict): New configuration data for the network
network_id (str): ID of the network to update
"""
url = f"{self.url}{self._get_endpoint('network', 'update', network_id)}"
config = self._add_routes_and_ip_assignment(config)
response = requests.post(
Expand All @@ -118,6 +147,49 @@ def update_network(self, config, network_id):
return response, self._get_repsonse(response.json())

def delete_network(self, network_id):
"""
Deletes ZeroTier Controller network

Params:
network_id (str): ID of the ZeroTier network to be deleted
"""
url = f"{self.url}{self._get_endpoint('network', 'delete', network_id)}"
response = requests.delete(url, headers=self.headers, timeout=REQUEST_TIMEOUT)
return response

def update_network_member(self, node_id, network_id, member_ip):
"""
Update ZeroTier Network Member Configuration

This method is currently used to authorize, enable the bridge
and assign an IP address to a network member

Params:
node_id (str): Node ID of the network member
network_id (str): Network ID to which the member belongs
member_ip (str): IP address to be assigned to the network member
"""
url = f'{self.url}/controller/network/{network_id}/member/{node_id}'
response = requests.post(
url,
json={
'authorized': True,
'activeBridge': True,
'ipAssignments': [str(member_ip)],
},
headers=self.headers,
timeout=5,
)
return response

def remove_network_member(self, node_id, network_id):
"""
Remove a member from ZeroTier network

Params:
node_id (str): ID of the network member
network_id (str): ID of the ZeroTier network
"""
url = f'{self.url}/controller/network/{network_id}/member/{node_id}'
response = requests.delete(url, headers=self.headers, timeout=5)
return response
9 changes: 8 additions & 1 deletion openwisp_controller/config/base/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ def manage_vpn_clients(cls, action, instance, pk_set, **kwargs):
).exists():
continue
client = vpn_client_model(
config=instance, vpn=template.vpn, auto_cert=template.auto_cert
config=instance,
vpn=template.vpn,
auto_cert=template.auto_cert,
)
client.full_clean()
client.save()
Expand Down Expand Up @@ -601,6 +603,11 @@ def get_vpn_context(self):
context[
vpn_context_keys['vni']
] = f'{vpnclient.vni or vpnclient.vpn._vxlan_vni}'
if vpnclient.secret:
context[
vpn_context_keys['zerotier_member_id']
] = vpnclient.zerotier_member_id
context[vpn_context_keys['secret']] = vpnclient.secret
return context

def get_context(self, system=False):
Expand Down