The webview gateway¶
Three processes sit behind the browser cockpit.
| process | listens on | reached by | decides |
|---|---|---|---|
agentctl top --gateway — cockpit + WS router |
127.0.0.1:8731 and 0.0.0.0:8735 |
the login proxy on loopback; agents on 8735, from any host | which agent a request is scoped to |
agentctl-webview-login.service — login proxy |
:8736, all interfaces |
browsers, through the HTTPS proxy in front | who the person is; sets X-User-Email |
an HTTPS proxy — the Caddy apply manages, or your own |
80 and 443 | the internet | TLS, and whether :8736 is publicly reachable |
webview-gateway install installs the first; webview-login install installs the proxy in
front. The third is a choice: let agentctl install and converge Caddy on this host, or run
your own proxy and meet the requirements below. It is not
optional either way — the session cookie is Secure. See TLS and Caddy,
Quick start, The cockpit and
Channels.
Identity and scope¶
The cockpit performs no authentication. It lowercases X-User-Email and looks it up in the
user_email → agent ledger. No signature, cookie or peer address is checked.
X-User-Email |
result |
|---|---|
| absent or empty | scope "" — denied everything. A login proxy in front is therefore mandatory |
| present, in the ledger | scoped to that agent |
| present, not in the ledger | scope "" — denied everything |
The login proxy overwrites X-User-Email rather than appending to it, so a value a
browser supplies is discarded.
Any local uid on the gateway host can curl http://127.0.0.1:8731/ with an X-User-Email
it does not own and be believed — the listener checks no peer address and the header carries
no signature, so what such a caller reaches is bounded only by which address it asserts. The
control is a host firewall rule on 8731, or a gateway host that runs nothing else. agentctl
asserts neither.
Binds and peer checks¶
| listener | bind | peer or origin check |
|---|---|---|
cockpit :8731 |
127.0.0.1, forced in code |
none — handlers ignore r.RemoteAddr |
dial-in :8735 |
0.0.0.0 |
none — WebSocket accepted with InsecureSkipVerify |
stream-stats, /_internal/oauth-callback |
0.0.0.0 |
loopback peers only |
/internal/relay-trace |
0.0.0.0 |
loopback peers and an operator credential; disabled by default |
login proxy :8736 |
all interfaces | none — it is the authenticator |
The cockpit bind cannot be widened: --web accepts an address but only its port is kept, and
the rendered unit passes no --web at all. The nftables guard covers the per-agent port bands
only, so 8731 and 8736 carry no rule — see
Ports and the port guard § Host port map.
Verify each host with ss -ltnp | grep -E '873[1-6]'.
Cockpit login: webview-login¶
WEBVIEW_AUTH_DRIVER selects the driver. This flow is not PKCE and is not tied to one identity
provider.
| key | driver | value |
|---|---|---|
WEBVIEW_AUTH_DRIVER |
both | basic or oidc (the default when unset; entra and google are accepted spellings of oidc) |
WEBVIEW_BASIC_USERS |
basic | user:password,user:password, one list per host |
WEBVIEW_OIDC_ISSUER |
oidc | issuer URL |
WEBVIEW_OIDC_CLIENT_ID |
oidc | required |
WEBVIEW_OIDC_CLIENT_SECRET |
oidc | required for most issuers |
WEBVIEW_URL |
oidc | redirect URI is ${WEBVIEW_URL}/auth/callback |
WEBVIEW_HMAC_KEY |
both | signs session, csrf and oidc-state |
WEBVIEW_SESSION_TTL |
both | any Go duration; 30 days by default |
WEBVIEW_DISABLE_PASSKEY |
both | 1/true/yes/on switches passkey (WebAuthn) sign-in off for the whole host and forces every visitor through WEBVIEW_AUTH_DRIVER. Unset, empty, or 0/false/off/no leaves it on, which is the default everywhere. Existing passkeys stay listable and revocable — see below |
WEBVIEW_TRUSTED_PROXIES |
basic | comma-separated IPs/CIDRs allowed to set X-Forwarded-For/X-Real-IP for rate limiting; default is loopback-only. Read from the process environment only — apply does not render it, so secret set has no effect on it; supply it through a systemd drop-in |
The OIDC principal is the email claim, then preferred_username, then upn. Entra and Google
are configuration, not code.
A driver that cannot be built refuses to start rather than serving a weaker login: an oidc
driver missing WEBVIEW_OIDC_ISSUER or WEBVIEW_OIDC_CLIENT_ID, a basic driver with no
entries, and a basic entry with an empty password all fail at startup — so a trailing colon
in WEBVIEW_BASIC_USERS cannot open the host.
Both drivers end at a wv_session cookie holding
b64(purpose|expiry|principal).b64(HMAC-SHA256) in URL-safe unpadded base64,
HttpOnly + Secure + SameSite=Lax.
Verification compares the purpose in constant time and refuses an empty principal. Rotating
WEBVIEW_HMAC_KEY invalidates every live session on the host.
basic driver behaviour¶
| case | behaviour |
|---|---|
| browser login | themed HTML form at /auth/login |
| script login | WWW-Authenticate: Basic, chosen when Accept lacks text/html |
| entry with an empty password | refused at startup |
| form rate limit | 8 failed attempts/min per client, one bucket shared with the Authorization: Basic path |
| client identity | the TCP peer, unless that peer is listed in WEBVIEW_TRUSTED_PROXIES — only then are X-Forwarded-For/X-Real-IP believed |
preemptive Authorization: Basic |
shares the same bucket as the form; not exempt |
Behind a remote (non-loopback) proxy with WEBVIEW_TRUSTED_PROXIES unset, every client
behind that proxy shares one rate-limit bucket.
Logout and unauthenticated paths¶
| path | behaviour |
|---|---|
/auth/logout |
clears the cookie; registered once for all drivers |
| OIDC logout | ends this application's session only; an IdP with an SSO session re-issues |
/manifest.webmanifest, /sw.js, /icons/, /fonts/ |
bypass auth; proxied with X-User-Email deleted |
Agent login to its model provider¶
The auth card a fresh webview agent shows on its first turn is a different, PKCE flow.
webview-login is not involved.
| piece | role |
|---|---|
agentctl-webview-dial@<agent>.service |
always-on tier; delivers the authorization URL while the agent is logged out |
agentctl login claude <agent> |
takes the pasted code#state and exchanges it as the agent's uid |
agentd SO_PEERCRED |
the dial unit runs as User=%i, so it can only log in itself |
agentctl auth-broker (:8734, optional) |
public /oauth/callback; verifies its own HMAC state and relays the code |
The broker removes the paste step, holds no durable secret and never stores a code.
Dial-in: how an agent registers¶
Agents connect outward to :8735 and stay connected, so a cross-host agent needs no inbound path and no shared filesystem. The cockpit injects turns and runs ops over that live session.
What the agent dials follows the ledger's host.webview_gateway marker:
| condition | URL |
|---|---|
gateway is this host, or no host.webview_gateway marker |
ws://127.0.0.1:8735 |
| gateway is another host | ws://<gateway-host>:8735 |
It reaches the agent as CHANNEL_WEBVIEW_GATEWAY_URL in agent.env / pi-agent.env, next to
CHANNEL_USER_EMAIL.
The transport proves nothing about the caller. Authorization is on the register frame: the
frame's user_email is lowercased and trimmed, and the connection is closed unless the
rendered ledger maps that address to exactly the agent the frame names.
user_email is an identifier, not a secret. Anyone who reaches :8735 and knows an agent's
login identity can register as that agent and receive its inbound frames. The network is the
primary control; the ledger check is a second gate. Keep :8735 off any public interface.
Other endpoints share the listener, since it is the one address every fleet host already
reaches: attachment pull, /browser/ and /terminal/ tunnel redemption, the host-shell
tunnel (two paths, out and back), the host dial-in, host jobs, agent administration,
stream-stats and the OAuth callback.
The gateway's rosters are rendered into its env file from agents.yaml at apply time, not
read live: WEBVIEW_LEDGER plus three rosters — admins, supervisors and the host-key
registry. All three are emitted even when empty, so an absent line means an agentctl too old
to render it rather than an empty roster.
Reverse-proxy requirements¶
Whatever terminates TLS in front of :8736 has to do three things.
| requirement | reason | symptom if ignored |
|---|---|---|
| Serve HTTP/2 | a tab holds up to 5 SSE streams: /events, /watch, /logs, /api/transcript, /api/fsevents |
HTTP/1.1 caps 6 connections per origin, so a second tab queues everything |
| Exclude those 5 paths from compression | the proxy decides before the upstream produces a content type | gzip buffers; the stream stalls or never flushes |
Forward X-Request-Id |
ties browser, proxy journal and access log to one request | no correlation across the three logs |
apply installs Caddy on a gateway host and renders all three, injecting
header_up X-Request-Id {http.request.uuid} — including the certificate, which Caddy obtains
and renews itself unless one is in the secret store. That is the default path and
TLS and Caddy covers it end to end.
Running your own proxy instead is equally supported; the three rows above are then yours to satisfy. Reproduce the compression exclusion:
@compressible {
not path /events /watch /logs /api/transcript /api/fsevents
}
encode @compressible zstd gzip
The cockpit sets X-Accel-Buffering: no on stream responses, which nginx honours — a hint to one
proxy, not a substitute for configuring your own.
Cookies and headers that must pass through unmodified¶
webview-login sets and reads five cookies, all HttpOnly + Secure + SameSite=Lax. The proxy
must forward the browser's Cookie: request header and the backend's Set-Cookie: response header
untouched — not stripped, not rewritten, and not filtered by an allowlist that omits any of them.
| cookie | set by | lifetime | carries |
|---|---|---|---|
wv_session |
both drivers, at the end of login | WEBVIEW_SESSION_TTL, 30 days by default |
the session; every authenticated request presents it |
wv_oidc_state |
oidc driver, at redirect |
10 minutes | the state for the /auth/callback leg only |
wv_login_csrf |
basic driver, with the login form |
15 minutes; path /auth/login |
the CSRF token the form POST is checked against |
wv_refresh_ref |
inline refresh | 90 days | an opaque lookup id — never the refresh token itself |
wv_wa_device |
passkey register and login | 2 years | the marker saying this browser already enrolled a passkey |
X-WebAuthn-State has to survive in both directions too: the passkey flow returns it on the
challenge response and reads it back off the next request. A proxy that drops unknown response
headers breaks passkey login at the second step while the first step appears to succeed.
Turning passkeys off¶
agentctl secret set WEBVIEW_DISABLE_PASSKEY true, then apply, switches passkey sign-in off for
the host and leaves WEBVIEW_AUTH_DRIVER carrying every sign-in.
What it blocks: /auth/webauthn/register/{start,finish} and /auth/webauthn/login/{start,finish}
answer 403 with a body naming the flag, the login page stops rendering its "Sign in with a
passkey" button, and the cockpit stops offering to enrol one.
What it does not block: /auth/webauthn/list and /auth/webauthn/revoke keep working, so a
passkey registered before the switch is still visible and still removable from the cockpit's
passkeys panel. Stored credentials are not deleted — clearing the flag restores them.
A proxy that authenticates on its own¶
Where the layer in front runs its own SSO — its own identity provider, its own session cookie — and proxies requests that are already authenticated, agentctl's login, session cookie and refresh machinery are not in the authorization path for ongoing API calls at all. Two consequences:
- That layer must set
X-User-Emailon every proxied request. It is trusted unconditionally — see Identity and scope. A request that arrives without it is denied everything, whatever the upstream session says. - That layer's own session timeout governs how long a user stays logged in, not
WEBVIEW_SESSION_TTL. When users re-authenticate more often than expected in this shape, check the SSO layer's session duration —agentctlcan neither see it nor control it.
You are in this shape if a request carrying only the upstream layer's session cookie, with no
wv_session at all, reaches webview-login and succeeds.
What apply reconciles¶
Both units reconcile on every apply and fleet sync where installed, re-rendering unit body
and env file and restarting only on a change.
| case | behaviour |
|---|---|
--force |
both restart regardless |
| deb upgrade | both force-bounce — the unit body is unchanged, the binary behind it is not |
| gateway restarted | apply then restarts every local agent that has a user_email |
WEBVIEW_HMAC_KEY reads back empty |
nothing is written and the old env file is left in place |
The login proxy restarts in-band. The gateway's own restart is deferred, armed as a timer
once apply has replied: the apply job reports its result over the host-dial connection the
gateway itself terminates, so bouncing it in-band would cut the reply. apply re-renders the
unit and env file in-band and the bounce follows a moment later.
An empty WEBVIEW_HMAC_KEY read means the sops store is unreadable on this host.
The gateway also carries cross-host traffic: host jobs and agent
administration route through it over each
target's own dial-in connection. What a host needs for that is
agentctl-host-dial.service, which holds the host's own connection to the gateway using the
host's age key. It is a per-host unit, not a per-agent one, so every host gets exactly one —
including a host with no agent living on it.
Diagnosing a cockpit that connects but never streams¶
Each step distinguishes failures the previous one cannot.
- Both units up, and the ledger holds your login identity?
agentctl webview-gateway status # unit, user_email→agent ledger
systemctl status agentctl-webview-login.service
The printed ledger is rebuilt from agents.yaml, not read from the running process. A
disagreement with observed behaviour means a stale env — run apply.
- Does the identity reach the cockpit?
curl -sI http://127.0.0.1:8731/ -H 'X-User-Email: person@example.com'
Run this on the gateway host. A 200 here with a browser failure puts the fault in the proxies, not the cockpit. Omitting the header returns 403 with the unprovisioned-principal page — the same refusal an address missing from the ledger gets — so send the header or the result says nothing.
- Is the agent registered?
systemctl status agentctl-webview-dial@<agent>.service
journalctl -u agentctl-webview-gateway.service | grep -E 'register accepted|rejected register'
The two log lines put the words in opposite orders, which is why the pattern spells both.
An agent card showing offline is usually the dial tier. rejected register for agent "…"
(user_email "…" not authorized) means the frame's identity is absent from the rendered
ledger.
- Do streams open and immediately close?
agentctl host stream-stats
Live per-route connect/disconnect counters from the running process. High disconnects on
/events while the cockpit renders means compression or an HTTP/1.1 ceiling.
- Is a 403 a scope mismatch or a stale admin roster?
agentctl terminal status <agent>
agentctl browser status <agent>
Both walk the gate sequence of /terminal/enter and /browser/enter and report each step.
The route itself returns a byte-identical 403 for either cause, so the step-by-step report
is the only thing that separates them. A roster check reporting UNKNOWN cannot read the
running process's memory — take that literally.
For a request that fails end to end, compare one X-Request-Id across the browser network tab,
the login proxy journal and Caddy's access log. The login proxy generates that ID when the header
arrives empty and echoes it on the response. Do not copy credentials or request bodies into a
report.
Relay timing and optional correlation¶
On an upgraded gateway, agentctl host stream-stats --json includes relay_dispatch: bounded, in-memory counters and
non-cumulative latency buckets for gateway socket admission/write, cockpit operation outcomes,
and optional timings reported by newer targets. Older gateways omit it rather than reporting zero.
It resets when the gateway restarts. The
socket-write phase does not prove target receipt. Target samples arrive only with a completed
exit frame; an older target, a canceled operation or a broken connection may have no sample.
Agentd admission measures its foreground queue wait; execution covers the direct owned command
and nested work until its stream returns. Connector grant time overlaps admission and must not
be added to it. Pi's connector-dispatch timing measures application receipt through worker
handoff using the connector's wall clock; other connectors may omit it. Gateway operation
duration is not browser end-to-end latency.
The capacity counter means the backend reported its explicit admission refusal; it is not proof of a particular final HTTP status. Disconnect and cancellation indicate what the gateway observed, not which upstream hop closed. A proxy-generated 503 that never reaches the gateway is invisible here. Compare proxy access logs and their request IDs separately, and do not infer network latency by subtracting clocks on different hosts.
For temporary per-request correlation, an operator may separately configure the gateway
process with AGENTCTL_RELAY_TRACE=1 and AGENTCTL_RELAY_TRACE_TOKEN_FILE pointing to a regular
credential file (not a symlink) owned by the gateway's effective UID and inaccessible to group/other users. Its
trimmed content must be 32–256 bytes. Missing, unreadable or unsafe configuration disables the
trace. This is opt-in and does not itself change the running service; use your normal approval
and secret-provisioning process. The credential is used only for a constant-time check and is
never returned or logged by this feature.
The gateway retains at most 512 completed records in memory until overwritten or process restart;
there is no time-based expiry. It stores an ephemeral-key HMAC of the request ID, locally minted
relay ID, phase durations and an outcome class, not the raw ID, identities, URL, arguments,
output, request body or error text. The key changes on restart. To retrieve records, send a POST
to the gateway dial listener's /internal/relay-trace from loopback, with the original
X-Request-Id header and the credential in an Authorization: Bearer header. Do not place the
credential or request ID in a URL, shell history, tickets or chat. The endpoint is not the
browser data plane and returns 404 for non-loopback, missing/incorrect credentials, or disabled
tracing. It returns Cache-Control: no-store.
Records cover the three cockpit collect/stream relay paths only. Detached background work, requests without a forwarded ID, coalesced followers and operations that never reach the gateway may have no record; absence is not proof that no work occurred. Duration fields may be missing independently, and an older connector or daemon cannot provide newer phases.