busweb: web UIs over the YAPL bus; httpsec.BearerTokens

busweb.Serve runs a <name>.web@N request (verse/web, D-200) against a
UI's http.Handler; Prefix/User/FromBus tell the handler where it is
mounted and who yasta says is logged in; WithPrefix serves the same
handler on a TCP port. httpsec.BearerTokens is the access control of a
UI without user management (a reverse proxy or yasta sends the token).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
terminarandClaude Opus 5.5 committed 2026-11-04 13:27:48 +01:00
1 parent fb2cb7bcfa
commit 7afb6a022a
7 files changed
+365

No files matched your search

+35
View File
@@ -175,6 +175,41 @@ the standard library, wrapped inside `Headers`.
Order: `Headers(Gate(cop.Handler(app)))` -- the headers also reach a 421
or 403.
- `BearerTokens(h, tokens)` (v0.4.0) -- for a UI without user
management of its own: only requests with `Authorization: Bearer <one
of tokens>` pass (constant-time compare), others get 401. A reverse
proxy in front sets the header (Traefik `headers.customRequestHeaders`),
or yasta for a UI shown over the bus. No tokens: everything passes --
bind such a UI to loopback only.
## Web UI over the YAPL bus: package `busweb` (v0.4.0)
`teruna.dev/yetano/yetano-webui-template/busweb` (meta-repo
`docs/verse/protocols.md` §18, D-200; types in `yetano.dev/yetano/verse/web`).
A YAPL participant provides `<name>.web@1`; yasta mounts its UI at
`/apps/<service>/` of yasta's web UI and sends each HTTP request as one
call. The same `http.Handler` serves both ways:
```go
app := myUI() // links/redirects use busweb.Prefix(r)
// over the bus: in the capability handler
resp := busweb.Serve(ctx, httpsec.BearerTokens(app, tokens), req) // req web.Request
// on a TCP port (optional), e.g. behind Traefik
h := busweb.WithPrefix(app, basePath)
h = httpsec.BearerTokens(h, tokens)
h = httpsec.Headers(httpsec.Gate(http.NewCrossOriginProtection().Handler(h), hosts, "web.allowed_hosts"), httpsec.HeaderOptions{})
```
- `Prefix(r)` -- where the UI is mounted; set `PageHeader.BasePath` to it
per request (it differs between the bus, the TCP port and yasta's web
relay).
- `User(r)` -- the yasta web user for a request over the bus (yasta's
claim; require yasta's token if other participants may call the
capability), `FromBus(r)`.
- `Serve` hands the handler the path below the prefix with `RequestURI`
as the browser sent it (so `ApplyAppearance` works), keeps only the
allowed response headers and cuts bodies over 512 KiB.
## Migration status
Eight projects use it, all on `v0.3.0` (2026-10-31): the built-in theme