Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ jobs:
- name: Verify the dashboard requires a login
shell: bash
run: |
test "$(docker compose exec -T dashboard printenv AGENTLOOP_DASHBOARD_REQUIRE_KEY)" = true
status="$(curl --silent --output /dev/null --write-out '%{http_code}' --cacert caddy-root.crt https://dashboard.localhost/)"
test "$status" = 401
status="$(curl --silent --output /dev/null --write-out '%{http_code}' --cacert caddy-root.crt \
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ trace, study, receipt, API and database schema versions.

### Added

- Shared dashboards can sign users in by project. With
`AGENTLOOP_DASHBOARD_REQUIRE_KEY=true`, the dashboard asks for a project API
key, verifies it like the HTTP API, and shows only that project; the project
field, API-key creation and the host-file patch plan are unavailable, and
repeated failed sign-ins wait a minute. The cloud deployment stack enables it.
- Cloud deployment. Releases publish a container image to
`ghcr.io/dipeshbabu/agentloop` (version and `latest` tags), built from the
validated tag and checked to report the release version as a non-root user.
Expand Down
71 changes: 71 additions & 0 deletions dashboard/access.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""Project-scoped sign-in for a shared, hosted dashboard.

With ``AGENTLOOP_DASHBOARD_REQUIRE_KEY`` enabled, the dashboard asks for a
project API key, verifies it against the store exactly as the HTTP API does,
and shows only that key's project. Pages that act outside one project are
hidden. Without the setting, the dashboard keeps its local, single-user
behaviour with a free-text project field.
"""

from __future__ import annotations

import os
import time

# Creating keys is an administrator task, and the patch plan reads files on the
# dashboard host; neither belongs to one project's users.
PROJECT_HIDDEN_PAGES = frozenset({"API Keys", "Patch Plan"})
MAX_FAILURES = 5
LOCKOUT_SECONDS = 60.0


def require_project_key() -> bool:
"""Return whether the dashboard must sign users in with a project API key."""
return os.getenv("AGENTLOOP_DASHBOARD_REQUIRE_KEY", "").strip().lower() in {
"1",
"true",
"yes",
"on",
}


def visible_pages(pages: list[str], *, project_mode: bool) -> list[str]:
"""Pages a signed-in project user may open."""
if not project_mode:
return list(pages)
return [page for page in pages if page not in PROJECT_HIDDEN_PAGES]


def lockout_remaining(state, now: float | None = None) -> float:
"""Seconds left before another sign-in attempt is allowed."""
now = time.monotonic() if now is None else now
return max(0.0, float(state.get("signin_locked_until", 0.0)) - now)


def sign_in(store, api_key: str, state, now: float | None = None) -> str | None:
"""Verify a project API key and record the signed-in project in ``state``.

Returns the project ID on success. Failed attempts are counted per session,
and after ``MAX_FAILURES`` further attempts wait ``LOCKOUT_SECONDS``.
"""
now = time.monotonic() if now is None else now
if lockout_remaining(state, now) > 0:
return None
key = api_key.strip() if isinstance(api_key, str) else ""
record = store.verify_api_key(key) if key else None
if record is None:
failures = int(state.get("signin_failures", 0)) + 1
state["signin_failures"] = failures
if failures >= MAX_FAILURES:
state["signin_failures"] = 0
state["signin_locked_until"] = now + LOCKOUT_SECONDS
return None
state["signin_failures"] = 0
state["signed_in_project"] = str(record["project_id"])
state["signed_in_key_prefix"] = str(record.get("prefix") or "")
return state["signed_in_project"]


def sign_out(state) -> None:
for name in ("signed_in_project", "signed_in_key_prefix"):
state.pop(name, None)
77 changes: 59 additions & 18 deletions dashboard/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,17 @@
from agentloop.value import build_value_report

try:
from dashboard.access import (
lockout_remaining,
require_project_key,
sign_in,
sign_out,
visible_pages,
)
from dashboard.trace_upload import TraceUploadError, parse_uploaded_trace
from dashboard.value_view import assumption_inputs, percentage, render_value_report
except ModuleNotFoundError:
from access import lockout_remaining, require_project_key, sign_in, sign_out, visible_pages
from trace_upload import TraceUploadError, parse_uploaded_trace
from value_view import assumption_inputs, percentage, render_value_report

Expand Down Expand Up @@ -114,29 +122,62 @@ def render_gate_table(results: list[dict]) -> None:
st.sidebar.title("AgentLoop")
st.sidebar.caption("Execution profiling and evidence")

project_id = st.sidebar.text_input("Project", value=st.session_state.get("project_id", "default"))
st.session_state["project_id"] = project_id
store = load_store()
project_mode = require_project_key()

if project_mode:
# A shared dashboard shows exactly one project: the one the API key belongs to.
if "signed_in_project" not in st.session_state:
st.title("AgentLoop Dashboard")
st.subheader("Sign in to your project")
st.caption(
"Enter a project API key. The dashboard shows only the traces and findings "
"of the project that key belongs to."
)
with st.form("project_sign_in"):
entered_key = st.text_input("Project API key", type="password")
submitted = st.form_submit_button("Sign in")
if submitted:
if sign_in(store, entered_key, st.session_state) is not None:
st.rerun()
remaining = lockout_remaining(st.session_state)
if remaining > 0:
st.error(f"Too many failed attempts. Try again in {int(remaining) + 1} seconds.")
else:
st.error("That API key is not valid for any project.")
st.stop()
project_id = st.session_state["signed_in_project"]
st.sidebar.markdown(f"**Project:** `{project_id}`")
if st.sidebar.button("Sign out"):
sign_out(st.session_state)
st.rerun()
else:
project_id = st.sidebar.text_input(
"Project", value=st.session_state.get("project_id", "default")
)
st.session_state["project_id"] = project_id

page = st.sidebar.radio(
"Navigate",
[
"Overview",
"Traces",
"Optimization Queue",
"Optimization",
"Diagnosis",
"Patch Plan",
"Replay Proof",
"Quality Gates",
"Value & Pricing",
"API Keys",
"Ingest",
"Setup",
],
visible_pages(
[
"Overview",
"Traces",
"Optimization Queue",
"Optimization",
"Diagnosis",
"Patch Plan",
"Replay Proof",
"Quality Gates",
"Value & Pricing",
"API Keys",
"Ingest",
"Setup",
],
project_mode=project_mode,
),
)

store = load_store()

st.title("AgentLoop Dashboard")
st.caption("Cost, latency, and execution-graph optimization for production AI agents")

Expand Down
2 changes: 2 additions & 0 deletions deploy/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ services:
PGUSER: ${POSTGRES_USER:-agentloop}
AGENTLOOP_POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
AGENTLOOP_API_URL: http://api:8000
# Each user signs in with a project API key and sees only that project.
AGENTLOOP_DASHBOARD_REQUIRE_KEY: "true"
depends_on:
api:
condition: service_healthy
Expand Down
25 changes: 15 additions & 10 deletions docs/CLOUD_DEPLOY.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ The `deploy/` directory contains the stack:
[Caddy](https://caddyserver.com/), which obtains and renews HTTPS
certificates automatically;
- `deploy/Caddyfile` serves the API on one hostname and the dashboard on
another, with a login in front of the dashboard;
another, with a login in front of the dashboard. Inside, the dashboard also
asks for a project API key and shows only that project;
- `deploy/.env.example` lists every setting.

Only ports 80 and 443 are published. The API, dashboard and database are
Expand Down Expand Up @@ -80,8 +81,9 @@ docker compose -f deploy/docker-compose.yml ps
curl https://agentloop-api.example.com/v1/readyz
```

Open the dashboard hostname in a browser and sign in with the user and password
you chose.
Open the dashboard hostname in a browser and enter the user and password you
chose. The dashboard then asks for a project API key (created in the next
step) and shows only that key's project.

### Create a project key and upload traces

Expand All @@ -105,7 +107,8 @@ client.upload_trace(trace)

or from the TypeScript SDK with
`new AgentLoopClient({ baseUrl: "https://agentloop-api.example.com", apiKey: "..." })`.
In the dashboard, set the sidebar's Project field to the same project ID.
Sign in to the dashboard with the same key to see that project's traces. Each
team can only see its own project; there is no project switcher.

### Upgrade and back up

Expand All @@ -132,8 +135,8 @@ checks that:

- the API is ready over HTTPS and stores and returns a trace with a project key;
- plain HTTP redirects to HTTPS, and uploads over the size limit are refused;
- the dashboard returns 401 without the login or with a wrong password, and
loads with the right one;
- the dashboard returns 401 without the login or with a wrong password, loads
with the right one, and runs with project sign-in enabled;
- the API, dashboard and database ports are not published on the host.

## Option 2: managed container platforms
Expand Down Expand Up @@ -175,9 +178,10 @@ These deployments are not exercised in CI. The same image and settings apply:

3. Optionally run the dashboard as a second service from the same image with
the command `streamlit run dashboard/app.py --server.address=0.0.0.0
--server.port=8501 --server.headless=true`, the same database settings, and
`AGENTLOOP_API_URL` set to the API's URL. The dashboard has no login of its
own: put it behind the platform's identity layer, such as Identity-Aware
--server.port=8501 --server.headless=true`, the same database settings,
`AGENTLOOP_API_URL` set to the API's URL, and
`AGENTLOOP_DASHBOARD_REQUIRE_KEY=true` so users sign in with a project key.
Also put it behind the platform's identity layer, such as Identity-Aware
Proxy on Google Cloud or built-in authentication on Azure Container Apps, or
keep it on a private network. Do not expose it publicly without one.

Expand All @@ -195,7 +199,8 @@ behind an authenticating ingress.

- Require API keys (`AGENTLOOP_REQUIRE_API_KEY=true`) and keep the admin key
out of clients; give each team or pipeline its own project key.
- Serve only HTTPS, and never expose the dashboard without a login.
- Serve only HTTPS, never expose the dashboard without a login, and keep
project sign-in enabled so teams only see their own traces.
- Keep Postgres off the public internet and back it up.
- Traces can contain prompts, tool inputs and outputs. Decide what you capture
and how long you keep it before sending production data; see
Expand Down
24 changes: 19 additions & 5 deletions docs/DASHBOARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,27 @@ uv run agentloop upload --path runs/research_agent_baseline.json \

Select project `acme` in a dashboard connected to the same store.

## Project sign-in for shared dashboards

Set `AGENTLOOP_DASHBOARD_REQUIRE_KEY=true` when several teams share one
dashboard (AgentLoop 0.2.7 and newer). The dashboard then asks for a project API
key, checks it the same way the HTTP API does, and shows only the traces,
findings and reports of the project that key belongs to. The free-text Project
field is replaced by the signed-in project and a Sign out button. The `API Keys`
page (creating keys is an administrator task) and the `Patch Plan` page (it
reads files on the dashboard host) are hidden. After five failed sign-ins in a
browser session, further attempts wait one minute.

Create project keys with the API's admin key or `agentloop create-api-key`.
Without the setting, the dashboard keeps its local, single-user behaviour.

## Security boundaries

The dashboard does not provide built-in user authentication. Keep it bound to a
trusted interface for local use. For shared or internet-facing deployments, put
it behind an authenticated reverse proxy and follow
[PRODUCTION.md](PRODUCTION.md), including TLS, explicit CORS, API-key auth,
retention, backups, and database access controls.
Keep a local dashboard bound to a trusted interface. For shared or
internet-facing deployments, enable project sign-in, put the dashboard behind an
authenticated reverse proxy, and follow [PRODUCTION.md](PRODUCTION.md), including
TLS, explicit CORS, API-key auth, retention, backups, and database access
controls. The [cloud deployment stack](CLOUD_DEPLOY.md) does all of this.

Quality fixture validation runs only when the Quality Gates form is submitted.
Empty suites, missing scorer requirements, and malformed JSON are shown beside
Expand Down
8 changes: 5 additions & 3 deletions docs/PRODUCTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,11 @@ configured. From 0.2.7 it also publishes the container image to
`.env` value alone does not update an existing database role. Use an authenticated
Postgres password-change procedure before replacing the secret, and keep the old value only
until the recreated clients connect successfully.
- The Streamlit dashboard does not provide end-user authentication. Treat it as
an operator console: keep it on a private network or place it behind an
authenticated reverse proxy. Do not expose it directly to the internet.
- The Streamlit dashboard has no user accounts. For a shared dashboard, set
`AGENTLOOP_DASHBOARD_REQUIRE_KEY=true` so each user signs in with a project API
key and sees only that project, and still keep it on a private network or
behind an authenticated reverse proxy. Do not expose it directly to the
internet.
- Terminate TLS at a trusted proxy or load balancer and forward only the API and
authenticated dashboard routes that users need.
- Apply request-body limits, rate limits, timeouts, and access logging at the
Expand Down
Loading
Loading