Remove fixed-host and HTTPS-only deployment requirements so the dashboard works at the container IP on HTTP port 5187. Validate browser mutations against the actual request host and retain access keys and CSRF protection. Ignore legacy public-origin settings and make Proxmox setup hostname-free. Update D14 and regression coverage for version 1.2.3. Refs #25
This commit is contained in:
+1
-1
@@ -53,7 +53,7 @@ def main(argv=None):
|
||||
if args.dry_run:
|
||||
print("Plan: fetch public master, build and update inside this container; preserve keys, profiles and history.")
|
||||
if marker["role"] != "worker":
|
||||
print("Backend: HTTP :5187 behind your existing HTTPS proxy; disable only the old FinalToken proxy.")
|
||||
print("Dashboard: http://<container-ip>:5187; no hostname or proxy required. Disable only the old FinalToken proxy.")
|
||||
return 0
|
||||
with update_lock():
|
||||
if not shutil.which("git"):
|
||||
|
||||
+14
-3
@@ -1,6 +1,7 @@
|
||||
"""Private guest provisioner, invoked by host.py inside the selected LXC. Not a host entry point."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import ipaddress
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path, PurePosixPath
|
||||
@@ -178,7 +179,7 @@ def configure(meta, enrollment_key=None):
|
||||
"profiles": [{"id": p, "accountId": p} for p in providers]}]
|
||||
json_file(ETC / "server.json", {"accounts": accounts, "machines": machines}, once=True)
|
||||
atomic(ETC / "server.env", f"FINALTOKEN_SERVER_CONFIG={ETC}/server.json\nFINALTOKEN_SERVER_DATA={SERVER_HOME}/data\n"
|
||||
f"FINALTOKEN_DASHBOARD_KEY={keys['dashboard']}\nFINALTOKEN_PUBLIC_ORIGIN=https://{meta['domain']}\n"
|
||||
f"FINALTOKEN_DASHBOARD_KEY={keys['dashboard']}\n"
|
||||
f"ASPNETCORE_URLS=http://0.0.0.0:5187\nFINALTOKEN_MACHINE_{meta['machineId']}={keys['worker']}\n", once=True)
|
||||
atomic(ETC / "dashboard-key", keys["dashboard"] + "\n", once=True)
|
||||
atomic(ETC / "worker-key", keys["worker"] + "\n", once=True)
|
||||
@@ -315,12 +316,22 @@ def migrate_external_proxy(meta):
|
||||
return updated
|
||||
|
||||
|
||||
def dashboard_urls():
|
||||
try:
|
||||
result = run(["hostname", "-I"], capture=True, check=False)
|
||||
addresses = [ipaddress.ip_address(value) for value in result.stdout.split()] if result.returncode == 0 else []
|
||||
return [f"http://{'[' + str(ip) + ']' if ip.version == 6 else ip}:5187"
|
||||
for ip in addresses if not ip.is_loopback and not ip.is_link_local] or ["http://<container-ip>:5187"]
|
||||
except (OSError, ValueError):
|
||||
return ["http://<container-ip>:5187"]
|
||||
|
||||
|
||||
def healthy(services, meta):
|
||||
for _ in range(20):
|
||||
live = all(run(["systemctl", "is-active", "--quiet", s], check=False, capture=True).returncode == 0 for s in services)
|
||||
if live and "finaltoken-server.service" in services:
|
||||
try:
|
||||
request = urllib.request.Request("http://127.0.0.1:5187/", headers={"Host": meta["domain"]})
|
||||
request = urllib.request.Request("http://127.0.0.1:5187/")
|
||||
with urllib.request.urlopen(request, timeout=2) as response:
|
||||
live = response.status == 200
|
||||
except OSError:
|
||||
@@ -399,7 +410,7 @@ def provision(manifest, archive):
|
||||
json_file(marker, meta)
|
||||
install_updater()
|
||||
if meta["role"] != "worker":
|
||||
print("Dashboard: https://" + meta["domain"])
|
||||
print("Dashboard: " + ", ".join(dashboard_urls()))
|
||||
print("Dashboard key is root-readable at /etc/finaltoken/dashboard-key (not printed).")
|
||||
print("Official CLI login still requires your browser authorization. No provider credentials were copied.")
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@ def domain_name(value):
|
||||
|
||||
def server_url(value):
|
||||
url = urlsplit(value)
|
||||
if url.scheme != "https" or not url.hostname or url.username or url.password or url.path not in ("", "/") or url.query or url.fragment:
|
||||
raise ValueError("Remote server URL must be an HTTPS origin")
|
||||
if url.scheme not in ("http", "https") or not url.hostname or url.username is not None or url.password is not None or url.path not in ("", "/") or url.query or url.fragment:
|
||||
raise ValueError("Server URL must be an HTTP or HTTPS origin")
|
||||
_ = url.port
|
||||
return value.rstrip("/")
|
||||
|
||||
@@ -65,7 +65,7 @@ def parser():
|
||||
p.add_argument("--cores", type=int, default=2)
|
||||
p.add_argument("--disk", type=int, default=20, help="GiB")
|
||||
p.add_argument("--role", choices=("both", "server", "worker"), help="Install default: both")
|
||||
p.add_argument("--domain", help="Dashboard DNS name; required for server/both")
|
||||
p.add_argument("--domain", help="Legacy optional DNS hint; no longer used to restrict access")
|
||||
p.add_argument("--email", help="Expected provider email for both selected providers")
|
||||
p.add_argument("--claude-email")
|
||||
p.add_argument("--codex-email")
|
||||
@@ -104,9 +104,8 @@ def validate(args):
|
||||
if args.template and not TEMPLATE.fullmatch(args.template):
|
||||
raise ValueError("Template must be a Debian 13 standard amd64 template filename")
|
||||
if args.role != "worker":
|
||||
if not args.domain:
|
||||
raise ValueError("Server/both requires the public hostname configured on your existing HTTPS reverse proxy")
|
||||
args.domain = domain_name(args.domain)
|
||||
if args.domain:
|
||||
args.domain = domain_name(args.domain)
|
||||
else:
|
||||
if not args.server_url or not args.worker_key_file:
|
||||
raise ValueError("Worker-only install requires --server-url and --worker-key-file")
|
||||
@@ -221,7 +220,7 @@ def main(argv=None):
|
||||
print("Unprivileged Debian 13 amd64; build NativeAOT inside CT; preserve config, keys, history and CLI profiles.")
|
||||
if args.action == "install":
|
||||
print(f"Root storage={args.storage}; template storage={args.template_storage}; bridge={args.bridge}; IP={args.ip}")
|
||||
print(f"Dashboard={('https://' + args.domain) if args.domain else args.server_url}; backend=HTTP :5187 behind your existing reverse proxy")
|
||||
print("Server=" + args.server_url if role == "worker" else "Dashboard=http://<container-ip>:5187; no hostname or proxy required")
|
||||
return 0
|
||||
execute(args)
|
||||
return 0
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -3,6 +3,7 @@ import argparse
|
||||
import datetime as dt
|
||||
import getpass
|
||||
import http.cookiejar
|
||||
from http.cookies import SimpleCookie
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
@@ -15,6 +16,7 @@ import time
|
||||
import unittest
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
KEY = "synthetic-dashboard-key-for-local-tests-only-123456"
|
||||
@@ -32,7 +34,7 @@ def wait_for(check, timeout=30):
|
||||
|
||||
|
||||
class Fixture:
|
||||
def __init__(self, port=None):
|
||||
def __init__(self, port=None, public_origin=None, start_worker=True):
|
||||
self.temp = tempfile.TemporaryDirectory(prefix="finaltoken-web-test-")
|
||||
self.path = Path(self.temp.name)
|
||||
self.processes = []
|
||||
@@ -41,6 +43,7 @@ class Fixture:
|
||||
sock.bind(("127.0.0.1", 0))
|
||||
port = sock.getsockname()[1]
|
||||
self.url = f"http://127.0.0.1:{port}"
|
||||
self.ready_host = urlsplit(public_origin or self.url).netloc
|
||||
self.jar = http.cookiejar.CookieJar()
|
||||
self.browser = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(self.jar))
|
||||
self.csrf = None
|
||||
@@ -78,7 +81,7 @@ class Fixture:
|
||||
(sessions / "rollout-fixture.jsonl").write_text("\n".join(map(json.dumps, rows)) + "\n", encoding="utf-8")
|
||||
env = os.environ.copy()
|
||||
env.update(FINALTOKEN_SERVER_CONFIG=str(self.path / "server.json"), FINALTOKEN_SERVER_DATA=str(self.path / "server-data"),
|
||||
FINALTOKEN_DASHBOARD_KEY=KEY, FINALTOKEN_MACHINE_a=WORKER_KEY, FINALTOKEN_PUBLIC_ORIGIN=self.url, ASPNETCORE_URLS=self.url)
|
||||
FINALTOKEN_DASHBOARD_KEY=KEY, FINALTOKEN_MACHINE_a=WORKER_KEY, FINALTOKEN_PUBLIC_ORIGIN=public_origin or self.url, ASPNETCORE_URLS=self.url)
|
||||
self.spawn(["dotnet", str(self.path / "FinalToken.Web/FinalToken.Web.dll")], env, ROOT / "src/FinalToken.Web")
|
||||
wait_for(self.ready)
|
||||
worker_env = os.environ.copy()
|
||||
@@ -86,7 +89,8 @@ class Fixture:
|
||||
worker_env.pop("CLAUDE_CONFIG_DIR", None)
|
||||
worker_env.pop("CODEX_HOME", None)
|
||||
worker_env["FINALTOKEN_WORKER_KEY"] = WORKER_KEY
|
||||
self.spawn(["dotnet", str(self.path / "FinalToken.Worker/finaltoken-worker.dll"), str(self.path / "worker.json")], worker_env, ROOT)
|
||||
if start_worker:
|
||||
self.spawn(["dotnet", str(self.path / "FinalToken.Worker/finaltoken-worker.dll"), str(self.path / "worker.json")], worker_env, ROOT)
|
||||
|
||||
@staticmethod
|
||||
def json(path, value):
|
||||
@@ -99,7 +103,7 @@ class Fixture:
|
||||
|
||||
def ready(self):
|
||||
try:
|
||||
return urllib.request.urlopen(self.url, timeout=1).status == 200
|
||||
return urllib.request.urlopen(urllib.request.Request(self.url, headers={"Host": self.ready_host}), timeout=1).status == 200
|
||||
except (OSError, urllib.error.URLError):
|
||||
return False
|
||||
|
||||
@@ -147,6 +151,61 @@ class Fixture:
|
||||
self.temp.cleanup()
|
||||
|
||||
|
||||
class IPAccessIntegration(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.fixture = Fixture(public_origin="https://usage.example.com", start_worker=False)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.fixture.close()
|
||||
|
||||
def request(self, path, body=None, origin=None, cookie=None, csrf=None):
|
||||
f = self.fixture
|
||||
authority = "10.0.30.150:" + str(urlsplit(f.url).port)
|
||||
headers = {"Host": authority, "X-FinalToken": "1", "Content-Type": "application/json"}
|
||||
if origin:
|
||||
headers["Origin"] = origin
|
||||
if cookie:
|
||||
headers["Cookie"] = cookie
|
||||
if csrf:
|
||||
headers["X-CSRF"] = csrf
|
||||
request = urllib.request.Request(f.url + path, headers=headers,
|
||||
data=None if body is None else json.dumps(body).encode())
|
||||
return urllib.request.urlopen(request, timeout=10)
|
||||
|
||||
def test_ip_page_and_http_login_ignore_the_legacy_fixed_hostname(self):
|
||||
with self.request("/") as response:
|
||||
self.assertEqual(200, response.status)
|
||||
authority = "10.0.30.150:" + str(urlsplit(self.fixture.url).port)
|
||||
with self.request("/session", {"key": KEY}, origin="http://" + authority) as response:
|
||||
cookies = SimpleCookie(response.headers["Set-Cookie"])
|
||||
csrf = json.load(response)["csrf"]
|
||||
self.assertFalse(cookies["finaltoken"]["secure"])
|
||||
self.assertTrue(cookies["finaltoken"]["httponly"])
|
||||
self.assertEqual("strict", cookies["finaltoken"]["samesite"].lower())
|
||||
cookie = "finaltoken=" + cookies["finaltoken"].value
|
||||
with self.request("/api/dashboard", cookie=cookie) as response:
|
||||
self.assertEqual(200, response.status)
|
||||
with self.assertRaises(urllib.error.HTTPError) as error:
|
||||
self.request("/api/dashboard")
|
||||
self.assertEqual(401, error.exception.code)
|
||||
with self.assertRaises(urllib.error.HTTPError) as error:
|
||||
self.request("/api/logout", {}, origin="http://" + authority, cookie=cookie, csrf="wrong")
|
||||
self.assertEqual(403, error.exception.code)
|
||||
with self.assertRaises(urllib.error.HTTPError) as error:
|
||||
self.request("/api/logout", {}, origin="http://evil.test", cookie=cookie, csrf=csrf)
|
||||
self.assertEqual(403, error.exception.code)
|
||||
with self.request("/api/logout", {}, origin="http://" + authority, cookie=cookie, csrf=csrf) as response:
|
||||
self.assertEqual(204, response.status)
|
||||
|
||||
def test_https_browser_origin_retains_secure_cookie_behind_a_proxy(self):
|
||||
authority = "10.0.30.150:" + str(urlsplit(self.fixture.url).port)
|
||||
with self.request("/session", {"key": KEY}, origin="https://" + authority) as response:
|
||||
cookie = SimpleCookie(response.headers["Set-Cookie"])
|
||||
self.assertTrue(cookie["finaltoken"]["secure"])
|
||||
|
||||
|
||||
class WebIntegration(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
||||
Reference in New Issue
Block a user