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

Reuse and reallocate TCP/UDP port range #6974

Closed
3 tasks done
DavidePrincipi opened this issue Jul 22, 2024 · 6 comments
Closed
3 tasks done

Reuse and reallocate TCP/UDP port range #6974

DavidePrincipi opened this issue Jul 22, 2024 · 6 comments
Assignees
Labels
verified All test cases were verified successfully

Comments

@DavidePrincipi
Copy link
Member

DavidePrincipi commented Jul 22, 2024

The current implementation of TCP and UDP ports allocation has two limitations:

  1. Modules like NethVoice allocates a wide range of port numbers, leading to possible node port exhaustion. When an instance is removed, used ports must be reclaimed by the node agent.
  2. By time, the number of ports required by a module may change. For instance, Mattermost received an additional TCP port for the Calls plugin. As the ports are allocated by the add-module action, the only way to require more ports is with backup/restore or instance clone.

Proposed solution

  • Reclaim and reuse a port range after an instance is removed.
  • Implement a node action that a module can invoke to receive a new range of ports (both TCP and UDP).
  • Migrate existing range allocations from module/ID/environment keys to the new (trusted) allocation storage

Alternative solutions

This feature is required. Keeping things as they are makes difficult to install NethVoice and manage the update of applications that increase their port requirements.

See also

Discussion https://mattermost.nethesis.it/nethesis/pl/5s131bmj7jdwzj7gaogukb5z6a

@DavidePrincipi
Copy link
Member Author

DavidePrincipi commented Sep 23, 2024

Acceptance tests

  • Works on new installation
  • Upgrade an existing system. Existing TCP and UDP ports allocation are migrated to /var/lib/nethserver/node/ports.sqlite DB for each cluster node.
  • Redis keys *_ports_sequence are removed.
  • Modules with role portsadm can run allocate-ports and deallocate-ports actions on the local node agent.
  • Port ranges are allocated without conflicts.
  • Port ranges are deallocated and can be reallocated later.
  • Port allocation and deallocation is workable with clone-module
  • Port allocation and deallocation is workable with import-module (migration) NethServer/ns8-core@9afcb17

Useful commands

Dump the ports.sqlite DB with

podman run -i --rm --volume /var/lib/nethserver/node/state/ports.sqlite:/srv/ports.sqlite:z alpine ash -c 'apk add sqlite ; sqlite3 /srv/ports.sqlite' <<<"SELECT *, 'tcp' FROM TCP_PORTS UNION SELECT *, 'udp' FROM UDP_PORTS;"

DavidePrincipi added a commit to NethServer/ns8-core that referenced this issue Oct 7, 2024
@DavidePrincipi
Copy link
Member Author

DavidePrincipi commented Oct 7, 2024

Testing in core 3.1.0-dev.1

DavidePrincipi added a commit to NethServer/ns8-core that referenced this issue Oct 8, 2024
- As only one role can be granted to a module on the local node, define
additional roles, given by the union of existing roles fwadm and tunadm.

- The deallocate-ports action step is unnecessary since the
allocate-ports/deallocate-ports node actions do not manage "_rsync"
allocations. These can only be handled by the cluster agent.

Refs NethServer/dev#6974
@DavidePrincipi
Copy link
Member Author

Testing with core 3.1.0-dev.2

Test case

@gsanchietti gsanchietti self-assigned this Oct 8, 2024
@gsanchietti
Copy link
Member

Current implementation has one main problem: it always reallocates the entire range
Reconfiguring modules that utilize numerous ports can be challenging. Additionally, these ports might be publicly accessible and used by external clients. Changing them could lead to issues, as clients would be unaware of the new connection points (e.g., VPN endpoint of NethSecurity Controller). This issue can also arise in modules that do not publicly expose ports but use them for internal communication with other modules (e.g., NethVoice with NethVoice Proxy).

@gsanchietti
Copy link
Member

Testing with core 3.1.0-dev.3

@gsanchietti gsanchietti added the testing Packages are available from testing repositories label Oct 11, 2024
@DavidePrincipi DavidePrincipi added verified All test cases were verified successfully and removed testing Packages are available from testing repositories labels Oct 14, 2024
@DavidePrincipi
Copy link
Member Author

@github-project-automation github-project-automation bot moved this from In progress to Done in NethServer Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
verified All test cases were verified successfully
Projects
Status: Done
Development

No branches or pull requests

3 participants