Torrents over a fail-closed VPN (#1026)

Torrents reach the Internet only through a fail-closed VPN (WireGuard or
OpenVPN, any provider), so peers never see a WROLPi's own address.

- A network namespace (Pi/Debian) or the vpn container (Docker) with an
  nftables kill switch; NAT-PMP or fixed port forwarding.
- qBittorrent inside it, sandboxed; torrents kept in config/torrents/.
- Torrent download form, Torrents page, Share as torrent, nav warning, and
  VPN settings in both Controller UIs.
- Help docs: Torrents, and The VPN for Torrents.

QA'd on a Raspberry Pi with a real provider over WireGuard and OpenVPN.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
lrnselfreliance 2026-11-28 14:25:24 -07:00 • committed by Roland
parent 633b125dc6
commit 2c3300b8b0
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
80 changed files with 7516 additions and 45 deletions

View file

@ -295,3 +295,94 @@ class TestGetContainerLogs:
assert result["logs"] == "log line 1\nlog line 2"
assert result["service"] == "api"
assert result["lines"] == 50
def _container(service, ports=None, status="running"):
container = mock.Mock()
container.name = f"{CONTAINER_PREFIX}-{service}-1"
container.status = status
container.attrs = {"NetworkSettings": {"Ports": ports or {}}}
return container
WEB_PORTS = {"443/tcp": [{"HostPort": "8443"}], "8084/tcp": [{"HostPort": "8084"}],
"8085/tcp": [{"HostPort": "8085"}], "8086/tcp": [{"HostPort": "8086"}],
"8091/tcp": [{"HostPort": "8091"}]}
def _list(*containers):
client = mock.Mock()
client.containers.list.return_value = list(containers)
client.containers.get.side_effect = lambda name: {c.name: c for c in containers}[name]
with mock.patch("controller.lib.docker_services.can_manage_containers", return_value=True), \
mock.patch("controller.lib.docker_services._get_client", return_value=client):
return {s["name"]: s for s in get_all_containers_status()}, client
class TestDockerServiceDescriptions:
"""Each container says what it is; one served by the web container (Caddy) links to Caddy's port for it."""
def test_every_compose_service_is_described(self):
import yaml
from pathlib import Path
from controller.lib.docker_services import DOCKER_SERVICES
compose = yaml.safe_load((Path(__file__).parents[2] / "docker-compose.yml").read_text())
for name in compose["services"]:
assert DOCKER_SERVICES.get(name, {}).get("description"), name
def test_vpn_is_torrents_and_links_to_the_webui(self):
services, _ = _list(_container("vpn"), _container("web", WEB_PORTS))
vpn = services["vpn"]
assert "torrents" in vpn["description"].lower()
assert vpn["port"] == 8091 and vpn["use_https"] is True and vpn["viewable"] is True
def test_served_through_web_uses_webs_host_port(self):
# WEB_HTTPS_PORT may be changed; the link follows Caddy's published port.
ports = dict(WEB_PORTS, **{"443/tcp": [{"HostPort": "9443"}]})
services, _ = _list(_container("help"), _container("zim"), _container("app"), _container("web", ports))
assert (services["help"]["port"], services["help"]["use_https"]) == (8086, True)
assert services["zim"]["port"] == 8085
assert services["app"]["port"] == 9443
assert services["web"]["port"] == 9443 and services["web"]["use_https"] is True
def test_tiles_are_plain_http_with_no_page(self):
services, _ = _list(_container("tiles"), _container("web", dict(WEB_PORTS, **{"8088/tcp": [{"HostPort": "8088"}]})))
assert (services["tiles"]["port"], services["tiles"]["use_https"], services["tiles"]["viewable"]) == \
(8088, False, False)
def test_without_web_there_is_no_link(self):
services, _ = _list(_container("vpn"))
assert services["vpn"]["port"] is None
assert services["vpn"]["description"]
def test_archive_has_no_page(self):
services, _ = _list(_container("archive", {"8080/tcp": [{"HostPort": "8083"}]}))
assert services["archive"]["viewable"] is False
assert services["archive"]["description"]
def test_unknown_container_has_no_description(self):
services, _ = _list(_container("custom", {"80/tcp": [{"HostPort": "9000"}]}))
assert services["custom"]["description"] == ""
assert services["custom"]["port"] == 9000
def test_single_container_status_is_described(self):
vpn, web = _container("vpn"), _container("web", WEB_PORTS)
client = mock.Mock()
client.containers.get.side_effect = lambda name: {vpn.name: vpn, web.name: web}[name]
with mock.patch("controller.lib.docker_services.can_manage_containers", return_value=True), \
mock.patch("controller.lib.docker_services._get_client", return_value=client):
status = get_container_status("vpn")
assert "torrents" in status["description"].lower()
assert status["port"] == 8091
class TestSimpleUiDescriptions:
"""The Controller's own page shows each service's description, as the React page does."""
def test_rows_show_descriptions(self):
from pathlib import Path
page = (Path(__file__).parents[1] / "templates/index.html").read_text()
macro = page[page.index("{% macro service_row"):page.index("{% endmacro %}")]
assert "service.description" in macro
script = page[page.index("function serviceRowHtml"):]
assert "service.description" in script[:script.index("return row")]