web: allow direct IP dashboard and worker access (#26)

Support direct HTTP IP access on port 5187 without hostname registration or a required proxy. Preserve dashboard/machine authentication and CSRF checks. Update Proxmox setup, D14, tests and documentation for 1.2.3.

Closes #25
This commit was merged in pull request #26.
This commit is contained in:
2026-11-15 16:42:12 +01:00
parent f45e065994
commit 284e692993
19 changed files with 218 additions and 69 deletions
+30 -5
View File
@@ -33,6 +33,14 @@ def install_args(*extra):
class HostTests(unittest.TestCase):
def test_server_install_requires_no_hostname(self):
args = host.parser().parse_args(["install", "--role", "server", "--ctid", "201", "--storage", "local-lvm"])
host.validate(args)
self.assertIsNone(args.domain)
def test_worker_can_use_a_direct_http_ip_address(self):
self.assertEqual("http://10.0.30.150:5187", host.server_url("http://10.0.30.150:5187/"))
def test_server_only_requires_no_provider_login_or_email(self):
args = host.parser().parse_args(["install", "--role", "server", "--ctid", "201",
"--storage", "local-lvm", "--domain", "usage.example.test"])
@@ -61,14 +69,14 @@ class HostTests(unittest.TestCase):
with self.subTest(flags=flags), self.assertRaises(ValueError):
install_args(*flags)
def test_worker_only_requires_https_and_enrollment_file(self):
def test_worker_only_requires_http_origin_and_enrollment_file(self):
with tempfile.TemporaryDirectory() as tmp:
key = Path(tmp) / "enrollment"
key.write_text("a" * 64)
args = install_args("--role", "worker", "--server-url", "https://usage.example.test", "--worker-key-file", str(key))
self.assertEqual("worker", args.role)
with self.assertRaises(ValueError):
install_args("--role", "worker", "--server-url", "http://usage.example.test", "--worker-key-file", str(key))
install_args("--role", "worker", "--server-url", "ftp://usage.example.test", "--worker-key-file", str(key))
key.write_text("short")
with self.assertRaises(ValueError):
install_args("--role", "worker", "--server-url", "https://usage.example.test", "--worker-key-file", str(key))
@@ -178,6 +186,22 @@ class HostTests(unittest.TestCase):
class GuestTests(unittest.TestCase):
def test_dashboard_urls_use_container_ips_and_bracket_ipv6(self):
with patch.object(guest, "run", return_value=subprocess.CompletedProcess([], 0, "10.0.30.150 2001:db8::5 fe80::1 127.0.0.1")):
self.assertEqual(["http://10.0.30.150:5187", "http://[2001:db8::5]:5187"], guest.dashboard_urls())
def test_missing_address_command_does_not_fail_an_update(self):
with patch.object(guest, "run", side_effect=FileNotFoundError):
self.assertEqual(["http://<container-ip>:5187"], guest.dashboard_urls())
def test_health_check_uses_no_configured_hostname(self):
with patch.object(guest, "run", return_value=subprocess.CompletedProcess([], 0)), patch.object(guest.time, "sleep"), \
patch.object(guest.urllib.request, "urlopen") as opener:
opener.return_value.__enter__.return_value.status = 200
self.assertTrue(guest.healthy(["finaltoken-server.service"], {"role": "server"}))
self.assertEqual("http://127.0.0.1:5187/", opener.call_args.args[0].full_url)
self.assertFalse(opener.call_args.args[0].has_header("Host"))
def test_server_packages_do_not_install_a_reverse_proxy(self):
with patch.object(guest, "run") as runner, patch.object(Path, "exists", return_value=True):
guest.packages("server", [])
@@ -194,10 +218,10 @@ class GuestTests(unittest.TestCase):
stack.enter_context(patch.object(guest.pwd, "getpwnam", return_value=types.SimpleNamespace(pw_gid=1000)))
stack.enter_context(patch.object(guest.os, "chown", create=True))
guest.configure({"role": "server", "providers": [], "emails": {}, "ctid": 201,
"machineId": "lxc_201", "timezone": "UTC", "domain": "usage.example.test", "tls": "acme"})
"machineId": "lxc_201", "timezone": "UTC"})
environment = (guest.ETC / "server.env").read_text()
self.assertTrue("ASPNETCORE_URLS=http://0.0.0.0:5187" in environment)
self.assertIn("FINALTOKEN_PUBLIC_ORIGIN=https://usage.example.test", environment)
self.assertNotIn("FINALTOKEN_PUBLIC_ORIGIN", environment)
self.assertFalse((guest.ETC / "Caddyfile").exists())
self.assertFalse((guest.SYSTEMD / "finaltoken-proxy.service").exists())
self.assertEqual(["finaltoken-server"], [call.args[0] for call in users.call_args_list])
@@ -405,7 +429,8 @@ class GuestTests(unittest.TestCase):
patch.object(Path, "read_text", read), patch.object(guest, "packages") as packages, \
patch.object(guest, "configure") as configure, patch.object(guest, "official_clis") as clis, \
patch.object(guest, "build", return_value=root / "release-v2") as build, \
patch.object(guest, "install_updater"), patch.object(guest, "activate") as activate, contextlib.redirect_stdout(io.StringIO()):
patch.object(guest, "install_updater"), patch.object(guest, "dashboard_urls", return_value=["http://10.0.30.150:5187"]), \
patch.object(guest, "activate") as activate, contextlib.redirect_stdout(io.StringIO()):
guest.provision(manifest, archive)
packages.assert_called_once_with("server", [])
configure.assert_not_called()