Skip to content

The agent that grows with you

fix(dashboard): name the exact gate trigger in fail-closed refusals

Tekniumb03b8ac51d54
diff --git a/hermes_cli/web_server.py b/hermes_cli/web_server.py
index cdbf43e5c0c..c9b661653d2 100644
--- a/hermes_cli/web_server.py
+++ b/hermes_cli/web_server.py
@@ -19312,8 +19312,42 @@ def start_server(
except Exception:
pass
+ # Name the exact reason the gate engaged. When the bind itself is
+ # loopback the ONLY trigger is dashboard.public_url — an operator
+ # (or a stale config.yaml entry) declared external exposure. Say
+ # so explicitly, print the offending URL, and give the two exits:
+ # configure auth, or remove public_url to restore local-only mode.
+ if host in _LOOPBACK_HOST_VALUES:
+ _public_url_for_msg = ""
+ try:
+ from hermes_cli.dashboard_auth.prefix import (
+ resolve_public_url as _rpu,
+ )
+
+ _public_url_for_msg = _rpu()
+ except Exception:
+ pass
+ _gate_reason = (
+ f"dashboard.public_url is set to "
+ f"{_public_url_for_msg or '<a non-loopback URL>'} — an "
+ f"operator-declared external URL engages the auth gate "
+ f"even on a loopback bind"
+ )
+ _local_only_hint = (
+ "If this dashboard should be LOCAL-ONLY (no reverse "
+ "proxy), remove dashboard.public_url from config.yaml "
+ "(and unset HERMES_DASHBOARD_PUBLIC_URL) to restore the "
+ "unauthenticated loopback mode.\n"
+ )
+ else:
+ _gate_reason = (
+ f"the auth gate engages on non-loopback binds ({host})"
+ )
+ _local_only_hint = ""
+
_fix_hint = (
- "Configure an auth provider before exposing the dashboard:\n"
+ _local_only_hint
+ + "Configure an auth provider before exposing the dashboard:\n"
" • Password: set dashboard.basic_auth.username + "
"password_hash in config.yaml\n"
" (hash with: python -c \"from "
@@ -19354,18 +19388,16 @@ def start_server(
pass
if skip_reasons:
raise SystemExit(
- f"Refusing to bind dashboard to {host} — the auth gate "
- f"engages on non-loopback binds, but no auth providers "
- f"are registered.\n\n"
+ f"Refusing to bind dashboard to {host} — {_gate_reason}, "
+ f"but no auth providers are registered.\n\n"
f"Bundled providers reported these issues:\n"
+ "\n".join(skip_reasons)
+ "\n\n"
+ _fix_hint
)
raise SystemExit(
- f"Refusing to bind dashboard to {host} — the auth gate is "
- f"required by the bind or configured public URL, but no auth "
- f"providers are registered.\n\n" + _fix_hint
+ f"Refusing to bind dashboard to {host} — {_gate_reason}, "
+ f"but no auth providers are registered.\n\n" + _fix_hint
)
_log.info(
"Dashboard binding to %s with auth gate enabled. Providers: %s",
diff --git a/tests/hermes_cli/test_dashboard_auth_gate.py b/tests/hermes_cli/test_dashboard_auth_gate.py
index c084ebbeb87..18eef3d39c2 100644
--- a/tests/hermes_cli/test_dashboard_auth_gate.py
+++ b/tests/hermes_cli/test_dashboard_auth_gate.py
@@ -315,3 +315,72 @@ def test_start_server_loopback_public_url_without_provider_fails_closed(monkeypa
assert web_server.app.state.auth_required is True
+def test_loopback_public_url_fail_closed_message_is_actionable(monkeypatch):
+ """The refusal must name public_url, print its value, and give both exits.
+
+ Upgrade compatibility: an operator with a stale dashboard.public_url and
+ no auth provider must not face a mystery-locked dashboard — the error
+ text IS the mitigation.
+ """
+ from hermes_cli.dashboard_auth import clear_providers
+
+ monkeypatch.setenv(
+ "HERMES_DASHBOARD_PUBLIC_URL",
+ "https://dashboard.example.test:9443",
+ )
+ clear_providers()
+ _stub_uvicorn_run(monkeypatch)
+ _restore_app_state_after_test(
+ monkeypatch,
+ "auth_required",
+ "bound_host",
+ "bound_port",
+ "trusted_public_hosts",
+ )
+
+ with pytest.raises(SystemExit) as exc:
+ web_server.start_server(
+ host="127.0.0.1", port=9119,
+ open_browser=False, allow_public=False,
+ )
+ msg = str(exc.value)
+ # Names the trigger and its value.
+ assert "dashboard.public_url" in msg
+ assert "https://dashboard.example.test:9443" in msg
+ # Exit 1: configure auth.
+ assert "basic_auth" in msg
+ assert "hermes dashboard register" in msg
+ # Exit 2: remove public_url to restore local-only mode.
+ assert "remove dashboard.public_url" in msg
+ assert "LOCAL-ONLY" in msg
+
+
[email protected]("host,public_url,expected", [
+ # Loopback bind, no public URL → local token mode, no gate.
+ ("127.0.0.1", None, False),
+ ("localhost", None, False),
+ ("::1", None, False),
+ # Loopback bind + non-loopback public URL → gate engages.
+ ("127.0.0.1", "https://dash.example.test", True),
+ ("::1", "https://dash.example.test:8443", True),
+ # Loopback bind + loopback public URL → still local-only.
+ ("127.0.0.1", "http://localhost:9119", False),
+ ("127.0.0.1", "http://127.0.0.1:9119", False),
+ # Non-loopback bind → always gated, public URL irrelevant.
+ ("0.0.0.0", None, True),
+ ("192.168.1.5", None, True),
+ ("0.0.0.0", "http://localhost:9119", True),
+])
+def test_should_require_dashboard_auth_truth_table(
+ monkeypatch, host, public_url, expected
+):
+ from hermes_cli.web_server import should_require_dashboard_auth
+
+ if public_url is None:
+ monkeypatch.delenv("HERMES_DASHBOARD_PUBLIC_URL", raising=False)
+ monkeypatch.setattr(
+ web_server, "_dashboard_public_hosts", lambda: frozenset()
+ )
+ else:
+ monkeypatch.setenv("HERMES_DASHBOARD_PUBLIC_URL", public_url)
+ assert should_require_dashboard_auth(host) is expected