From e6add446b187f74ce7a13ab152af9fd3f87a6f8f Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Thu, 29 Oct 2026 20:55:33 -0400 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20deploy:=20headless=20Twitch=20s?= =?UTF-8?q?treamer=20for=20the=20Activity=20Monitor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds src/deploy/stream: a Debian image (Xvfb + Chromium + ffmpeg + a stdlib Go authproxy that injects Authorization: Bearer so the token never reaches the URL, history, logs or screen), an entrypoint that supervises every process with backoff, reloads the page every RELOAD_EVERY, encodes 1080p30 libx264 CBR with a silent audio track and pushes to Twitch RTMP, a healthcheck, docker compose, a Kustomize base in a dedicated hive-stream namespace and the hive-hosted overlay for hive's own spoke on hive-oke. Secrets are templates only; the owner creates them. Dashboard: `?kiosk=1` unattended display mode — hides sidebar, topbar (out-specifying theme.go's layout guard), avatar menu, notices, chat FAB, welcome/NPS dialogs and every section except the Activity Monitor, and skips the toast hover-pause. Guarded by TestKioskModeWiring. Publishing: .github/workflows/stream-image.yml pushes ghcr.io/hivecommons/hive-stream: and :v5-latest from v5 (PR builds only), registered as pinned [-v4] in release-lines.yml. Docs: src/docs/streaming-the-activity-monitor.md (Twitch Creator Dashboard steps, secrets, apply, verify, troubleshooting, privacy, OBS quick path). Fixes #15594 Signed-off-by: Andrew Anderson --- .github/release-lines.yml | 4 + .github/workflows/stream-image.yml | 146 +++++++++++++++ .../added-activity-monitor-twitch-streamer.md | 1 + src/deploy/README.md | 1 + src/deploy/stream/.gitignore | 2 + src/deploy/stream/Dockerfile | 49 +++++ src/deploy/stream/README.md | 41 +++++ src/deploy/stream/authproxy/main.go | 121 ++++++++++++ src/deploy/stream/authproxy/main_test.go | 59 ++++++ src/deploy/stream/docker-compose.yaml | 31 ++++ src/deploy/stream/entrypoint.sh | 138 ++++++++++++++ src/deploy/stream/healthcheck.sh | 15 ++ src/deploy/stream/k8s/configmap.yaml | 16 ++ src/deploy/stream/k8s/deployment.yaml | 81 +++++++++ src/deploy/stream/k8s/kustomization.yaml | 10 + src/deploy/stream/k8s/namespace.yaml | 10 + src/deploy/stream/k8s/networkpolicy.yaml | 39 ++++ src/deploy/stream/k8s/secret.yaml | 36 ++++ .../overlays/hive-hosted/kustomization.yaml | 28 +++ src/docs/documentation-map.md | 1 + src/docs/streaming-the-activity-monitor.md | 172 ++++++++++++++++++ src/pkg/dashboard/kiosk_mode_test.go | 34 ++++ src/pkg/dashboard/static-src/css/kiosk.css | 18 ++ src/pkg/dashboard/static-src/js/boot.js | 17 ++ src/pkg/dashboard/static-src/js/nps.js | 1 + .../static-src/js/tooltips-dialogs.js | 4 +- src/pkg/dashboard/static-src/js/welcome.js | 3 +- src/pkg/dashboard/static-src/manifest.txt | 1 + src/pkg/dashboard/static/index.html | 43 ++++- 29 files changed, 1118 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/stream-image.yml create mode 100644 changelog.d/added-activity-monitor-twitch-streamer.md create mode 100644 src/deploy/stream/.gitignore create mode 100644 src/deploy/stream/Dockerfile create mode 100644 src/deploy/stream/README.md create mode 100644 src/deploy/stream/authproxy/main.go create mode 100644 src/deploy/stream/authproxy/main_test.go create mode 100644 src/deploy/stream/docker-compose.yaml create mode 100755 src/deploy/stream/entrypoint.sh create mode 100755 src/deploy/stream/healthcheck.sh create mode 100644 src/deploy/stream/k8s/configmap.yaml create mode 100644 src/deploy/stream/k8s/deployment.yaml create mode 100644 src/deploy/stream/k8s/kustomization.yaml create mode 100644 src/deploy/stream/k8s/namespace.yaml create mode 100644 src/deploy/stream/k8s/networkpolicy.yaml create mode 100644 src/deploy/stream/k8s/secret.yaml create mode 100644 src/deploy/stream/overlays/hive-hosted/kustomization.yaml create mode 100644 src/docs/streaming-the-activity-monitor.md create mode 100644 src/pkg/dashboard/kiosk_mode_test.go create mode 100644 src/pkg/dashboard/static-src/css/kiosk.css diff --git a/.github/release-lines.yml b/.github/release-lines.yml index cbd48e19c3..767c6791e3 100644 --- a/.github/release-lines.yml +++ b/.github/release-lines.yml @@ -151,6 +151,10 @@ pinned: # filters name v5 only: the forge.Merger it exercises lives on v5, and v4 is # feature-frozen. forgejo-smoke.yml: [-v4] + # Publishes the headless Twitch streamer image (#15594) from v5 only: the + # dashboard's `?kiosk=1` mode it depends on lives on v5 and v4 is + # feature-frozen. The image is operator tooling, not a hive release channel. + stream-image.yml: [-v4] # Workflows that deliberately do NOT pin to the release lines. Each must keep a # wildcard branch filter; if one is ever narrowed to a fixed list, the guard diff --git a/.github/workflows/stream-image.yml b/.github/workflows/stream-image.yml new file mode 100644 index 0000000000..b0c3368b59 --- /dev/null +++ b/.github/workflows/stream-image.yml @@ -0,0 +1,146 @@ +# stream-image (#15594): build and publish the headless Twitch streamer image +# (src/deploy/stream/Dockerfile) that puts the hive Activity Monitor on a 24/7 +# stream. +# +# ── Why a sibling of docker.yml, not a row in it ──────────────────────────── +# +# docker.yml builds the hive binary image: multi-arch, cosign-signed, release +# channels, a test-image lane. The streamer is Xvfb + Chromium + ffmpeg plus a +# 100-line Go proxy — none of that machinery applies, and bolting a second +# Dockerfile onto docker.yml's matrix would make the hive image's publish gate +# depend on apt mirrors for chromium. ci-runner-image.yml is the precedent for +# a small, separately-published operator image; this follows it. +# +# ── Triggers ──────────────────────────────────────────────────────────────── +# +# push (v5) path-filtered to src/deploy/stream/** and this file. Pushes +# ghcr.io//hive-stream: (immutable) and +# ghcr.io//hive-stream:v5-latest (moving — what the +# Kustomize overlay references, so a merged fix rolls on the +# next pod restart). +# pull_request builds only (no login, no push), same path filter. The +# Dockerfile compiles the auth proxy and runs its tests, so +# this is the CI gate for src/deploy/stream changes. +# workflow_dispatch builds AND pushes from whatever ref it is run on; the +# moving tag is `-latest`. +# +# `branches: [v5]` only: the dashboard's `?kiosk=1` mode the streamer depends +# on lives on v5 and v4 is feature-frozen, so it is listed as `[-v4]` under +# `pinned` in .github/release-lines.yml. +# +# ── Where it runs ─────────────────────────────────────────────────────────── +# +# `ubuntu-latest`, like ci-runner-image.yml: the build is one apt-get of +# chromium/ffmpeg and a Go compile; GitHub-hosted runners have the egress and +# docker.yml already proves the GITHUB_TOKEN → GHCR push path from them. +# +# ── Cache policy ──────────────────────────────────────────────────────────── +# +# No `type=gha` cache — same reasoning as ci-runner-image.yml (the Actions +# cache is the resource #7206 measured as full). This builds rarely. +name: Stream Image + +on: + push: + branches: [v5] + paths: + - 'src/deploy/stream/**' + - '.github/workflows/stream-image.yml' + pull_request: + paths: + - 'src/deploy/stream/**' + - '.github/workflows/stream-image.yml' + workflow_dispatch: + +concurrency: + group: stream-image-${{ github.ref }} + cancel-in-progress: false + +permissions: + contents: read + packages: write + +env: + IMAGE: ghcr.io/${{ github.repository_owner }}/hive-stream + +jobs: + build: + name: ${{ github.event_name == 'pull_request' && 'Build (PR gate, no push)' || 'Build and push' }} + # GitHub-hosted on purpose — see the header. Do not route this through + # HIVE_RUNNER_LABELS. + runs-on: ubuntu-latest + timeout-minutes: 60 + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - name: Resolve tags + id: ref + env: + EVENT: ${{ github.event_name }} + REF_NAME: ${{ github.ref_name }} + SHA: ${{ github.sha }} + PR_NUMBER: ${{ github.event.pull_request.number }} + run: | + set -euo pipefail + if [ "$EVENT" = "pull_request" ]; then + echo "tags=${IMAGE}:pr-${PR_NUMBER}" >> "$GITHUB_OUTPUT" + echo "push=false" >> "$GITHUB_OUTPUT" + exit 0 + fi + # Moving tag is "-latest"; a branch name with "/" is not a + # valid tag component, so flatten it. + line="$(printf '%s' "$REF_NAME" | tr '/' '-')" + { + echo "tags=${IMAGE}:${SHA}"$'\n'"${IMAGE}:${line}-latest" + echo "push=true" + } >> "$GITHUB_OUTPUT" + + - name: Log in to GHCR + if: steps.ref.outputs.push == 'true' + uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 + + - name: Build${{ steps.ref.outputs.push == 'true' && ' and push' || '' }} + id: build + uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0 + with: + # Repo root: the Dockerfile compiles src/deploy/stream/authproxy. + context: . + file: src/deploy/stream/Dockerfile + platforms: linux/amd64 + push: ${{ steps.ref.outputs.push == 'true' }} + tags: ${{ steps.ref.outputs.tags }} + provenance: false + sbom: false + labels: | + org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} + org.opencontainers.image.revision=${{ github.sha }} + org.opencontainers.image.description=hivecommons/hive headless Twitch streamer for the Activity Monitor (#15594) + + - name: Summary + env: + TAGS: ${{ steps.ref.outputs.tags }} + DIGEST: ${{ steps.build.outputs.digest }} + PUSHED: ${{ steps.ref.outputs.push }} + run: | + { + echo "## hive-stream image" + echo + if [ "$PUSHED" = "true" ]; then + echo "Pushed:" + printf '%s\n' "$TAGS" | sed 's/^/- `/; s/$/`/' + echo + echo "Digest: \`$DIGEST\`" + echo + echo 'Roll it: `kubectl -n hive-stream rollout restart deploy/hive-stream` (the overlay tracks `v5-latest`).' + else + echo "Built (not pushed): \`$TAGS\`" + fi + } >> "$GITHUB_STEP_SUMMARY" diff --git a/changelog.d/added-activity-monitor-twitch-streamer.md b/changelog.d/added-activity-monitor-twitch-streamer.md new file mode 100644 index 0000000000..0d74c4a8a0 --- /dev/null +++ b/changelog.d/added-activity-monitor-twitch-streamer.md @@ -0,0 +1 @@ +- `src/deploy/stream/`: a headless Twitch streamer image (Xvfb + Chromium + ffmpeg, published as `ghcr.io/hivecommons/hive-stream`) with Kustomize manifests that put the dashboard's Activity Monitor on an unattended 24/7 stream, plus a dashboard `?kiosk=1` display mode that hides the chrome, dialogs and every other section ([#15594](https://github.com/hivecommons/hive/issues/15594)). Guide: `src/docs/streaming-the-activity-monitor.md`. diff --git a/src/deploy/README.md b/src/deploy/README.md index 1dbfd34df9..116ae5f514 100644 --- a/src/deploy/README.md +++ b/src/deploy/README.md @@ -29,6 +29,7 @@ Use it indirectly through the dashboard terminal link. If a terminal pane says i ## Other directories - `kustomize/overlays/`: the `standalone` (self-hosted, hub-less), `openshift`, `openshift-netadmin` and `backup-exec-restriction` overlays on top of `k8s/` and `inference/`. See the [standalone overlay README](kustomize/overlays/standalone/README.md). +- `stream/`: the headless Twitch streamer that puts the dashboard's Activity Monitor on a 24/7 stream (Xvfb + Chromium + ffmpeg image, Kustomize base and the `hive-hosted` overlay). See [its README](stream/README.md) and [Streaming the Activity Monitor](../docs/streaming-the-activity-monitor.md). - `ci-runners/`: manifests for the self-hosted GitHub Actions runners that serve this repository. See [its README](ci-runners/README.md). - `legacy-redirect/`: the hub legacy-host redirect that keeps the request path and query (#6430). See [its README](legacy-redirect/README.md). - `dibs-domain-cutover/`: staged manifests for moving dibs to `dibs.hivecommons.dev` (#5925). See [its README](dibs-domain-cutover/README.md). diff --git a/src/deploy/stream/.gitignore b/src/deploy/stream/.gitignore new file mode 100644 index 0000000000..246b96c5a0 --- /dev/null +++ b/src/deploy/stream/.gitignore @@ -0,0 +1,2 @@ +.env +out/ diff --git a/src/deploy/stream/Dockerfile b/src/deploy/stream/Dockerfile new file mode 100644 index 0000000000..d9acea76ea --- /dev/null +++ b/src/deploy/stream/Dockerfile @@ -0,0 +1,49 @@ +# hive-stream: headless Twitch streamer for the Hive activity monitor +# (hivecommons/hive#15594). See README.md here and +# src/docs/streaming-the-activity-monitor.md. +# +# Build context is the REPO ROOT (like src/Dockerfile): +# docker build -f src/deploy/stream/Dockerfile -t hive-stream . +# +# Base images are pinned by digest for the same supply-chain reason as +# src/Dockerfile.contributor (#3746); the golang digest is the one +# src/Dockerfile uses, the bookworm-slim digest the one Dockerfile.contributor +# uses, so a refresh of either is a one-line bump in lockstep with them. +ARG BASE_REGISTRY=docker.io/library + +FROM --platform=$BUILDPLATFORM ${BASE_REGISTRY}/golang:1.27-alpine@sha256:f2c872bcee949b7be9c490efd02b48a8a2fbf947cdf533f1c58525ec9d8170fd AS authproxy +ARG TARGETOS TARGETARCH +WORKDIR /build +COPY src/deploy/stream/authproxy/*.go ./ +# Stdlib-only: a throwaway module keeps this stage independent of the root +# go.mod/go.sum (no download, no replace directives to satisfy). +RUN go mod init hive-stream/authproxy >/dev/null 2>&1 \ + && CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -trimpath -ldflags='-s -w' -o /out/authproxy . + +FROM ${BASE_REGISTRY}/debian:bookworm-slim@sha256:7c7b2c966bc9ee8cedfeef67e0e279108992c77681fa595db4a9d65c06ccc587 +ENV DEBIAN_FRONTEND=noninteractive +# No PulseAudio on purpose: Twitch requires an audio track, which ffmpeg +# synthesises from anullsrc; Chromium runs --mute-audio. +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + ca-certificates curl tini procps \ + xvfb x11-utils xdotool \ + chromium \ + ffmpeg \ + fonts-dejavu-core fonts-noto-core fonts-noto-color-emoji fonts-liberation \ + && apt-get clean && rm -rf /var/lib/apt/lists/* \ + && useradd --uid 1000 --create-home --shell /usr/sbin/nologin stream \ + && install -d -o stream -g stream /run/stream + +COPY --from=authproxy /out/authproxy /usr/local/bin/authproxy +COPY src/deploy/stream/entrypoint.sh src/deploy/stream/healthcheck.sh /usr/local/bin/ +RUN chmod 0755 /usr/local/bin/entrypoint.sh /usr/local/bin/healthcheck.sh \ + && chromium --version && ffmpeg -version | head -1 && Xvfb -help >/dev/null 2>&1 + +USER stream +ENV HOME=/home/stream RUN_DIR=/run/stream \ + DASHBOARD_PATH="/?kiosk=1#section-activity-monitor-section" \ + TWITCH_INGEST=rtmp://live.twitch.tv/app \ + VIDEO_SIZE=1920x1080 FPS=30 BITRATE=4500k RELOAD_EVERY=30m +HEALTHCHECK --interval=30s --timeout=5s --start-period=90s --retries=3 CMD ["/usr/local/bin/healthcheck.sh"] +ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/entrypoint.sh"] diff --git a/src/deploy/stream/README.md b/src/deploy/stream/README.md new file mode 100644 index 0000000000..89f9400e6f --- /dev/null +++ b/src/deploy/stream/README.md @@ -0,0 +1,41 @@ +# `src/deploy/stream/` — headless Twitch streamer for the Activity Monitor + +Puts the dashboard's Activity Monitor (stage tracker) on an unattended 24/7 +Twitch stream. Operator guide, Twitch-side setup, and troubleshooting: +[`src/docs/streaming-the-activity-monitor.md`](../../docs/streaming-the-activity-monitor.md). + +| File | Purpose | +| --- | --- | +| `Dockerfile` | `debian:bookworm-slim` + Xvfb, Chromium, ffmpeg, xdotool, tini; builds `authproxy` in a `golang` stage. Build context is the **repo root**. Published as `ghcr.io/hivecommons/hive-stream:` / `:v5-latest` by `.github/workflows/stream-image.yml`. | +| `entrypoint.sh` | Supervisor: Xvfb → authproxy → Chromium `--kiosk` (restart with backoff) → periodic reload (`RELOAD_EVERY`) → ffmpeg `x11grab` + `anullsrc` → libx264 CBR → RTMP. Masks the stream key in ffmpeg output. | +| `authproxy/` | Loopback reverse proxy (stdlib Go) that adds `Authorization: Bearer $DASHBOARD_TOKEN` to every dashboard request so the token is never in a URL, in Chromium's history, or on screen. Logs when the upstream answers with a login redirect. | +| `healthcheck.sh` | Chromium alive + ffmpeg progress file fresher than 20 s with `frame>0`. Used by the image `HEALTHCHECK` and the Deployment's probes. | +| `docker-compose.yaml`, `.env.example` | Run the same image from a laptop. | +| `k8s/` | Kustomize base: Namespace `hive-stream`, ConfigMap, Deployment (1 replica, non-root, 512 Mi `/dev/shm`, 1–2 CPU / 2–3 Gi), NetworkPolicy (DNS, dashboard Service, public RTMP/HTTPS only). `secret.yaml` is a **template** and is not in the kustomization. | +| `overlays/hive-hosted/` | hive's own hosted spoke on `hive-oke`. | + +## Environment + +| Variable | Default | Meaning | +| --- | --- | --- | +| `DASHBOARD_URL` | required | Dashboard origin (`http://hive..svc.cluster.local:3002` in-cluster, or the public route). | +| `DASHBOARD_TOKEN` | — | Spoke `dashboard.auth_token` (in-cluster) or a GitHub token of a hub user with access (public route). | +| `DASHBOARD_PATH` | `/?kiosk=1#section-activity-monitor-section` | Path Chromium opens. `?kiosk=1` is the dashboard's unattended display mode. | +| `TWITCH_STREAM_KEY` | — | Primary Stream key. | +| `TWITCH_INGEST` | `rtmp://live.twitch.tv/app` | Ingest; pick a closer one from Twitch's ingest list if needed. | +| `VIDEO_SIZE` / `FPS` / `BITRATE` / `X264_PRESET` | `1920x1080` / `30` / `4500k` / `veryfast` | Encode settings. Keyframe interval is `2×FPS`. | +| `RELOAD_EVERY` | `30m` | Page reload cadence (picks up dashboard rolls). | +| `STREAM_OUTPUT` | — | Dry run: `null` discards, `*.flv` writes a file, anything else is a raw ffmpeg output. | +| `STREAM_SECONDS` | `0` | `>0` stops ffmpeg after N s and exits 0 (dry run); a non-zero ffmpeg exit fails the run. | + +## Dry run (no Twitch, no cluster) + +```sh +docker build -t hive-stream:local -f src/deploy/stream/Dockerfile . +docker run --rm --shm-size=512m -v "$PWD/src/deploy/stream/out:/out" \ + -e DASHBOARD_URL=https://.hive.hivecommons.dev -e DASHBOARD_TOKEN= \ + -e STREAM_OUTPUT=/out/test.flv -e STREAM_SECONDS=20 hive-stream:local +ffmpeg -ss 15 -i src/deploy/stream/out/test.flv -frames:v 1 src/deploy/stream/out/frame.png +``` + +`out/` is git-ignored. diff --git a/src/deploy/stream/authproxy/main.go b/src/deploy/stream/authproxy/main.go new file mode 100644 index 0000000000..908d851a64 --- /dev/null +++ b/src/deploy/stream/authproxy/main.go @@ -0,0 +1,121 @@ +// Command authproxy is the streamer's local credential injector +// (src/deploy/stream, hivecommons/hive#15594). +// +// Chromium cannot attach an Authorization header to a kiosk URL, and putting +// the token in the URL would paint it on the stream. So the browser talks to +// this proxy on loopback and the proxy forwards to the dashboard origin with +// `Authorization: Bearer $DASHBOARD_TOKEN` added. The token never reaches the +// renderer, the URL bar, or a screenshot. Stdlib only; one binary, one flag. +package main + +import ( + "flag" + "fmt" + "log" + "net" + "net/http" + "net/http/httputil" + "net/url" + "os" + "strings" + "time" +) + +const ( + defaultListen = "127.0.0.1:8099" + dialTimeout = 10 * time.Second + responseHeaderWindow = 60 * time.Second + idleConnWindow = 90 * time.Second + // Hop-by-hop Upgrade requests (ttyd websockets) are passed straight + // through by httputil; FlushInterval -1 keeps SSE (/api/events) flowing. + sseFlushInterval = -1 +) + +func main() { + listen := flag.String("listen", envOr("AUTHPROXY_LISTEN", defaultListen), "loopback address to serve the browser on") + target := flag.String("target", os.Getenv("DASHBOARD_URL"), "dashboard origin, e.g. https://hive.example.com (path is ignored)") + flag.Parse() + + token := strings.TrimSpace(os.Getenv("DASHBOARD_TOKEN")) + rp, err := newProxy(*target, token) + if err != nil { + log.Fatalf("authproxy: %v", err) + } + mux := http.NewServeMux() + mux.HandleFunc("/-/authproxy/healthz", func(w http.ResponseWriter, _ *http.Request) { _, _ = w.Write([]byte("ok\n")) }) + mux.Handle("/", rp) + srv := &http.Server{Addr: *listen, Handler: mux, ReadHeaderTimeout: dialTimeout} + log.Printf("authproxy: %s -> %s (token %s)", *listen, redactURL(*target), yesNo(token != "")) + log.Fatal(srv.ListenAndServe()) +} + +// newProxy builds the reverse proxy. It is split from main so a unit test can +// assert the header is injected and the Host rewritten without a listener. +func newProxy(target, token string) (*httputil.ReverseProxy, error) { + if target == "" { + return nil, fmt.Errorf("DASHBOARD_URL (or -target) is required") + } + u, err := url.Parse(target) + if err != nil || u.Scheme == "" || u.Host == "" { + return nil, fmt.Errorf("DASHBOARD_URL %q must be an absolute http(s) origin", redactURL(target)) + } + origin := &url.URL{Scheme: u.Scheme, Host: u.Host} + rp := &httputil.ReverseProxy{ + Rewrite: func(pr *httputil.ProxyRequest) { + pr.SetURL(origin) + pr.Out.Host = origin.Host + // Never forward the loopback client's own headers as if they + // were the user's — this proxy IS the client. + pr.Out.Header.Del("X-Forwarded-For") + if token != "" { + pr.Out.Header.Set("Authorization", "Bearer "+token) + } + }, + FlushInterval: sseFlushInterval, + Transport: &http.Transport{ + Proxy: http.ProxyFromEnvironment, + DialContext: (&net.Dialer{Timeout: dialTimeout}).DialContext, + ResponseHeaderTimeout: responseHeaderWindow, + IdleConnTimeout: idleConnWindow, + ForceAttemptHTTP2: true, + }, + ErrorHandler: func(w http.ResponseWriter, r *http.Request, err error) { + log.Printf("authproxy: upstream error for %s: %v", r.URL.Path, err) + http.Error(w, "dashboard unreachable", http.StatusBadGateway) + }, + } + // Cookies the dashboard sets are scoped to the loopback origin by the + // browser, which is what we want; nothing else needs rewriting. + rp.ModifyResponse = func(resp *http.Response) error { + // A hub login redirect means the token was rejected: surface it in the + // logs instead of letting Chromium bounce to github.com forever. + if loc := resp.Header.Get("Location"); resp.StatusCode/100 == 3 && strings.Contains(loc, "/login") { + log.Printf("authproxy: upstream redirected %s to login (%s) — DASHBOARD_TOKEN rejected or missing", resp.Request.URL.Path, redactURL(loc)) + } + return nil + } + return rp, nil +} + +func envOr(k, def string) string { + if v := os.Getenv(k); v != "" { + return v + } + return def +} + +func yesNo(b bool) string { + if b { + return "set" + } + return "UNSET" +} + +// redactURL drops the query so a token someone put in DASHBOARD_URL by +// mistake does not end up in the logs. +func redactURL(s string) string { + if i := strings.IndexByte(s, '?'); i >= 0 { + return s[:i] + "?…" + } + return s +} diff --git a/src/deploy/stream/authproxy/main_test.go b/src/deploy/stream/authproxy/main_test.go new file mode 100644 index 0000000000..66fc7fbd1a --- /dev/null +++ b/src/deploy/stream/authproxy/main_test.go @@ -0,0 +1,59 @@ +package main + +import ( + "net/http" + "net/http/httptest" + "testing" +) + +func TestProxyInjectsBearerAndRewritesHost(t *testing.T) { + var got http.Header + var gotHost string + upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + got = r.Header.Clone() + gotHost = r.Host + w.WriteHeader(http.StatusNoContent) + })) + defer upstream.Close() + + rp, err := newProxy(upstream.URL+"/ignored/path?kiosk=1", "s3cret") + if err != nil { + t.Fatal(err) + } + front := httptest.NewServer(rp) + defer front.Close() + + req, _ := http.NewRequest(http.MethodGet, front.URL+"/api/stage-tracker", nil) + req.Header.Set("Authorization", "Bearer from-browser") + resp, err := http.DefaultClient.Do(req) + if err != nil { + t.Fatal(err) + } + _ = resp.Body.Close() + if resp.StatusCode != http.StatusNoContent { + t.Fatalf("status = %d", resp.StatusCode) + } + if got.Get("Authorization") != "Bearer s3cret" { + t.Errorf("Authorization = %q, want the injected token to replace the browser's", got.Get("Authorization")) + } + if gotHost != upstream.Listener.Addr().String() { + t.Errorf("Host = %q, want upstream host", gotHost) + } + if got.Get("X-Forwarded-For") != "" { + t.Errorf("X-Forwarded-For leaked: %q", got.Get("X-Forwarded-For")) + } +} + +func TestProxyRejectsBadTarget(t *testing.T) { + for _, target := range []string{"", "hive.example.com", "/relative"} { + if _, err := newProxy(target, ""); err == nil { + t.Errorf("newProxy(%q) accepted an invalid origin", target) + } + } +} + +func TestRedactURL(t *testing.T) { + if got := redactURL("https://h/x?token=abc"); got != "https://h/x?…" { + t.Errorf("redactURL = %q", got) + } +} diff --git a/src/deploy/stream/docker-compose.yaml b/src/deploy/stream/docker-compose.yaml new file mode 100644 index 0000000000..b82ade3914 --- /dev/null +++ b/src/deploy/stream/docker-compose.yaml @@ -0,0 +1,31 @@ +# Run the Activity Monitor streamer from a laptop (Docker Desktop / colima): +# cp .env.example .env # fill in DASHBOARD_URL, DASHBOARD_TOKEN, TWITCH_STREAM_KEY +# docker compose -f src/deploy/stream/docker-compose.yaml up --build +# Dry run without Twitch: STREAM_OUTPUT=null STREAM_SECONDS=10 docker compose ... up +services: + hive-stream: + build: + context: ../../.. + dockerfile: src/deploy/stream/Dockerfile + image: ghcr.io/hivecommons/hive-stream:local + env_file: + - path: .env + required: false + environment: + DASHBOARD_URL: ${DASHBOARD_URL:?set DASHBOARD_URL to the dashboard https origin} + DASHBOARD_TOKEN: ${DASHBOARD_TOKEN:-} + TWITCH_STREAM_KEY: ${TWITCH_STREAM_KEY:-} + TWITCH_INGEST: ${TWITCH_INGEST:-rtmp://live.twitch.tv/app} + STREAM_OUTPUT: ${STREAM_OUTPUT:-} + STREAM_SECONDS: ${STREAM_SECONDS:-0} + VIDEO_SIZE: ${VIDEO_SIZE:-1920x1080} + RELOAD_EVERY: ${RELOAD_EVERY:-30m} + shm_size: 512m + restart: unless-stopped + deploy: + resources: + limits: + cpus: "2" + memory: 3g + volumes: + - ./out:/run/stream/out diff --git a/src/deploy/stream/entrypoint.sh b/src/deploy/stream/entrypoint.sh new file mode 100755 index 0000000000..044027ef90 --- /dev/null +++ b/src/deploy/stream/entrypoint.sh @@ -0,0 +1,138 @@ +#!/usr/bin/env bash +# Headless Activity Monitor streamer (hivecommons/hive#15594). +# +# Xvfb ─► Chromium --kiosk ─► (loopback authproxy) ─► dashboard +# └────────────── ffmpeg x11grab + silent audio ─► Twitch RTMP +# +# Every process is supervised here: Chromium and ffmpeg are restarted with +# backoff when they exit, the page is reloaded every RELOAD_EVERY so a rolled +# SPA is picked up, and a progress file for the healthcheck is kept fresh by +# ffmpeg itself. Nothing in this script ever prints a secret. +set -euo pipefail + +: "${DASHBOARD_URL:?DASHBOARD_URL is required (https origin of the hive dashboard)}" +DASHBOARD_TOKEN="${DASHBOARD_TOKEN:-}" +DASHBOARD_PATH="${DASHBOARD_PATH:-/?kiosk=1#section-activity-monitor-section}" +TWITCH_INGEST="${TWITCH_INGEST:-rtmp://live.twitch.tv/app}" +TWITCH_STREAM_KEY="${TWITCH_STREAM_KEY:-}" +# STREAM_OUTPUT overrides the RTMP sink: "null" discards (dry run), a path +# writes an FLV file, anything else is used verbatim as an ffmpeg output URL. +STREAM_OUTPUT="${STREAM_OUTPUT:-}" +STREAM_SECONDS="${STREAM_SECONDS:-0}" # >0 = stop ffmpeg after N seconds (dry run) +VIDEO_SIZE="${VIDEO_SIZE:-1920x1080}" +FPS="${FPS:-30}" +BITRATE="${BITRATE:-4500k}" +X264_PRESET="${X264_PRESET:-veryfast}" +RELOAD_EVERY="${RELOAD_EVERY:-30m}" +DISPLAY_NUM="${DISPLAY_NUM:-:99}" +AUTHPROXY_LISTEN="${AUTHPROXY_LISTEN:-127.0.0.1:8099}" +RUN_DIR="${RUN_DIR:-/run/stream}" +BACKOFF_MIN=2 +BACKOFF_MAX=60 +KEYINT=$(( FPS * 2 )) # Twitch wants a 2 s keyframe interval +BUFSIZE="$(( ${BITRATE%k} * 2 ))k" + +export DISPLAY="$DISPLAY_NUM" AUTHPROXY_LISTEN DASHBOARD_URL DASHBOARD_TOKEN +mkdir -p "$RUN_DIR/profile"; rm -f "$RUN_DIR/done" +PROGRESS="$RUN_DIR/ffmpeg-progress.txt" +: > "$PROGRESS" +log() { printf '%s stream: %s\n' "$(date -u +%FT%TZ)" "$*"; } + +pids=() +cleanup() { trap - EXIT INT TERM; log "shutting down"; kill "${pids[@]}" 2>/dev/null || true; wait 2>/dev/null || true; } +trap cleanup EXIT INT TERM + +# ---- 1. Xvfb ----------------------------------------------------------------- +Xvfb "$DISPLAY_NUM" -screen 0 "${VIDEO_SIZE}x24" -nolisten tcp -nocursor +extension RANDR >/dev/null 2>&1 & +pids+=($!) +for _ in $(seq 1 50); do xdpyinfo -display "$DISPLAY_NUM" >/dev/null 2>&1 && break; sleep 0.2; done +xdpyinfo -display "$DISPLAY_NUM" >/dev/null 2>&1 || { log "Xvfb failed to start"; exit 1; } +log "Xvfb up on $DISPLAY_NUM (${VIDEO_SIZE})" + +# ---- 2. authproxy (adds Authorization: Bearer, token stays off-screen) ------ +authproxy -listen "$AUTHPROXY_LISTEN" & +pids+=($!) +for _ in $(seq 1 50); do curl -fsS "http://$AUTHPROXY_LISTEN/-/authproxy/healthz" >/dev/null 2>&1 && break; sleep 0.2; done +curl -fsS "http://$AUTHPROXY_LISTEN/-/authproxy/healthz" >/dev/null 2>&1 || { log "authproxy failed to start"; exit 1; } +KIOSK_URL="http://$AUTHPROXY_LISTEN$DASHBOARD_PATH" +log "authproxy up; kiosk URL $KIOSK_URL -> ${DASHBOARD_URL%%\?*} (token $([ -n "$DASHBOARD_TOKEN" ] && echo set || echo UNSET))" + +# ---- 3. Chromium kiosk, restarted with backoff ------------------------------ +chromium_loop() { + local backoff=$BACKOFF_MIN + while :; do + local started=$SECONDS + log "chromium starting" + chromium \ + --kiosk --no-first-run --no-default-browser-check --disable-gpu \ + --autoplay-policy=no-user-gesture-required --mute-audio \ + --window-size="${VIDEO_SIZE/x/,}" --window-position=0,0 --force-device-scale-factor=1 \ + --disable-infobars --disable-session-crashed-bubble --noerrdialogs --hide-scrollbars \ + --disable-features=TranslateUI,MediaRouter --check-for-update-interval=31536000 \ + --disable-background-networking --disable-component-update --disable-sync \ + --user-data-dir="$RUN_DIR/profile" --no-sandbox \ + "$KIOSK_URL" >"$RUN_DIR/chromium.log" 2>&1 || true + (( SECONDS - started > 60 )) && backoff=$BACKOFF_MIN + log "chromium exited; restarting in ${backoff}s" + sleep "$backoff"; backoff=$(( backoff * 2 > BACKOFF_MAX ? BACKOFF_MAX : backoff * 2 )) + done +} +chromium_loop & +pids+=($!) + +# ---- 4. periodic reload (new SPA rolls) ------------------------------------- +reload_loop() { + while :; do + sleep "$RELOAD_EVERY" + if xdotool search --onlyvisible --class chromium >/dev/null 2>&1; then + xdotool search --onlyvisible --class chromium | head -1 | xargs -r -I{} xdotool key --window {} F5 && log "page reloaded (RELOAD_EVERY=$RELOAD_EVERY)" + fi + done +} +reload_loop & +pids+=($!) + +# ---- 5. ffmpeg, restarted with backoff -------------------------------------- +sink() { + case "$STREAM_OUTPUT" in + null) printf -- '-f null -' ;; + '') [ -n "$TWITCH_STREAM_KEY" ] || { log "TWITCH_STREAM_KEY is unset and STREAM_OUTPUT is empty — nothing to stream to"; return 1; } + printf -- '-f flv %s/%s' "$TWITCH_INGEST" "$TWITCH_STREAM_KEY" ;; + *.flv) printf -- '-f flv %s' "$STREAM_OUTPUT" ;; + *) printf -- '%s' "$STREAM_OUTPUT" ;; + esac +} +ffmpeg_loop() { + local backoff=$BACKOFF_MIN out limit=() rc=0 + out="$(sink)" || exit 1 + (( STREAM_SECONDS > 0 )) && limit=(-t "$STREAM_SECONDS") + # Give Chromium a moment to paint before the first frame goes out. + sleep 5 + while :; do + local started=$SECONDS + log "ffmpeg starting (${VIDEO_SIZE}@${FPS}, ${BITRATE} CBR, keyint ${KEYINT}, sink ${out%%/*}…)" + # shellcheck disable=SC2086 + ffmpeg -nostdin -y -hide_banner -loglevel warning -progress "$PROGRESS" \ + -f x11grab -framerate "$FPS" -video_size "$VIDEO_SIZE" -draw_mouse 0 -i "$DISPLAY_NUM" \ + -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 \ + -c:v libx264 -preset "$X264_PRESET" -tune zerolatency -pix_fmt yuv420p \ + -b:v "$BITRATE" -minrate "$BITRATE" -maxrate "$BITRATE" -bufsize "$BUFSIZE" \ + -g "$KEYINT" -keyint_min "$KEYINT" -sc_threshold 0 -r "$FPS" \ + -c:a aac -b:a 128k -ar 44100 -shortest "${limit[@]}" \ + $out > >(sed -u "s#${TWITCH_STREAM_KEY:-__none__}#***#g") 2>&1 && rc=0 || rc=$? + if (( STREAM_SECONDS > 0 )); then + if (( rc != 0 )); then log "ffmpeg bounded run FAILED (exit $rc)"; exit "$rc"; fi + log "ffmpeg finished a ${STREAM_SECONDS}s bounded run"; : > "$RUN_DIR/done"; return + fi + (( SECONDS - started > 60 )) && backoff=$BACKOFF_MIN + log "ffmpeg exited (rc=$rc); restarting in ${backoff}s" + sleep "$backoff"; backoff=$(( backoff * 2 > BACKOFF_MAX ? BACKOFF_MAX : backoff * 2 )) + done +} +ffmpeg_loop & +pids+=($!) + +wait -n "${pids[@]}" || true +if [ -e "$RUN_DIR/done" ]; then log "bounded run complete"; exit 0; fi +log "a supervised process left the loop; exiting so the orchestrator restarts the pod" +exit 1 diff --git a/src/deploy/stream/healthcheck.sh b/src/deploy/stream/healthcheck.sh new file mode 100755 index 0000000000..bb2a16d7fc --- /dev/null +++ b/src/deploy/stream/healthcheck.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +# Liveness for the streamer: Chromium is running and ffmpeg pushed frames +# within the last STALL_SECONDS (its -progress file is rewritten per frame +# batch). Exit 1 restarts the container. +set -u +RUN_DIR="${RUN_DIR:-/run/stream}" +STALL_SECONDS="${STALL_SECONDS:-20}" +pgrep -x chromium >/dev/null 2>&1 || pgrep -f 'chromium.*--kiosk' >/dev/null 2>&1 || { echo "chromium not running"; exit 1; } +p="$RUN_DIR/ffmpeg-progress.txt" +[ -s "$p" ] || { echo "ffmpeg has not reported progress yet"; exit 1; } +age=$(( $(date +%s) - $(stat -c %Y "$p") )) +[ "$age" -le "$STALL_SECONDS" ] || { echo "ffmpeg progress stale (${age}s)"; exit 1; } +frames=$(grep -a '^frame=' "$p" | tail -1 | cut -d= -f2) +[ "${frames:-0}" -gt 0 ] || { echo "ffmpeg has encoded 0 frames"; exit 1; } +echo "ok frames=${frames} progress_age=${age}s" diff --git a/src/deploy/stream/k8s/configmap.yaml b/src/deploy/stream/k8s/configmap.yaml new file mode 100644 index 0000000000..db740a391d --- /dev/null +++ b/src/deploy/stream/k8s/configmap.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: hive-stream + namespace: hive-stream +data: + # Origin of the dashboard the streamer renders. The overlay points this at + # the hive's in-cluster Service; the public route also works (see docs). + DASHBOARD_URL: "http://hive.CHANGE-ME-hive-namespace.svc.cluster.local:3002" + DASHBOARD_PATH: "/?kiosk=1#section-activity-monitor-section" + TWITCH_INGEST: "rtmp://live.twitch.tv/app" + VIDEO_SIZE: "1920x1080" + FPS: "30" + BITRATE: "4500k" + X264_PRESET: "veryfast" + RELOAD_EVERY: "30m" diff --git a/src/deploy/stream/k8s/deployment.yaml b/src/deploy/stream/k8s/deployment.yaml new file mode 100644 index 0000000000..83029f564c --- /dev/null +++ b/src/deploy/stream/k8s/deployment.yaml @@ -0,0 +1,81 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: hive-stream + namespace: hive-stream + labels: + app.kubernetes.io/name: hive-stream +spec: + replicas: 1 + revisionHistoryLimit: 2 + # Twitch accepts ONE publisher per key; two pods would fight for it. + strategy: + type: Recreate + selector: + matchLabels: + app.kubernetes.io/name: hive-stream + template: + metadata: + labels: + app.kubernetes.io/name: hive-stream + spec: + automountServiceAccountToken: false + securityContext: + runAsNonRoot: true + runAsUser: 1000 + runAsGroup: 1000 + fsGroup: 1000 + seccompProfile: + type: RuntimeDefault + containers: + - name: stream + image: ghcr.io/hivecommons/hive-stream:v5-latest + imagePullPolicy: Always + envFrom: + - configMapRef: + name: hive-stream + - secretRef: + name: twitch-stream + - secretRef: + name: dashboard-token + # Chromium's own sandbox needs user namespaces the pod does not get, + # so the entrypoint passes --no-sandbox; the pod sandbox (non-root, + # no caps, seccomp, no SA token) is the boundary instead. The page is + # first-party. + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: ["ALL"] + resources: + requests: + cpu: "1" + memory: 2Gi + limits: + cpu: "2" + memory: 3Gi + volumeMounts: + - name: shm + mountPath: /dev/shm + - name: run + mountPath: /run/stream + startupProbe: + exec: + command: ["/usr/local/bin/healthcheck.sh"] + periodSeconds: 10 + failureThreshold: 18 + livenessProbe: + exec: + command: ["/usr/local/bin/healthcheck.sh"] + periodSeconds: 30 + timeoutSeconds: 5 + failureThreshold: 3 + volumes: + # Chromium renderers share memory through /dev/shm; the 64Mi container + # default makes tabs crash at 1080p. + - name: shm + emptyDir: + medium: Memory + sizeLimit: 512Mi + - name: run + emptyDir: + sizeLimit: 256Mi diff --git a/src/deploy/stream/k8s/kustomization.yaml b/src/deploy/stream/k8s/kustomization.yaml new file mode 100644 index 0000000000..70e5613463 --- /dev/null +++ b/src/deploy/stream/k8s/kustomization.yaml @@ -0,0 +1,10 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +namespace: hive-stream +resources: + - namespace.yaml + - configmap.yaml + - deployment.yaml + - networkpolicy.yaml +# secret.yaml is deliberately NOT a resource: it documents the two Secrets the +# operator creates with `kubectl create secret` (see the file header). diff --git a/src/deploy/stream/k8s/namespace.yaml b/src/deploy/stream/k8s/namespace.yaml new file mode 100644 index 0000000000..20c11e1f03 --- /dev/null +++ b/src/deploy/stream/k8s/namespace.yaml @@ -0,0 +1,10 @@ +# Dedicated namespace: the hosted hive's own namespace is created and deleted +# wholesale by the hub's provisioner (pkg/hub/saas_provision.go), so the +# streamer and its Twitch secret live beside it, not inside it. +apiVersion: v1 +kind: Namespace +metadata: + name: hive-stream + labels: + app.kubernetes.io/name: hive-stream + pod-security.kubernetes.io/enforce: baseline diff --git a/src/deploy/stream/k8s/networkpolicy.yaml b/src/deploy/stream/k8s/networkpolicy.yaml new file mode 100644 index 0000000000..f10956831e --- /dev/null +++ b/src/deploy/stream/k8s/networkpolicy.yaml @@ -0,0 +1,39 @@ +# Egress only: DNS, the dashboard (in-cluster Service of the hive's namespace, +# patched by the overlay, or 443 for the public route) and RTMP/RTMPS to +# Twitch ingest. Twitch publishes no stable ingest CIDRs, so RTMP egress is +# allowed to any PUBLIC address on 1935/443 and denied to RFC1918 space. +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: hive-stream + namespace: hive-stream +spec: + podSelector: + matchLabels: + app.kubernetes.io/name: hive-stream + policyTypes: ["Ingress", "Egress"] + ingress: [] + egress: + - to: + - namespaceSelector: + matchLabels: + kubernetes.io/metadata.name: kube-system + ports: + - { protocol: UDP, port: 53 } + - { protocol: TCP, port: 53 } + - to: + - namespaceSelector: + matchLabels: + kubernetes.io/metadata.name: CHANGE-ME-hive-namespace + podSelector: + matchLabels: + app.kubernetes.io/name: hive + ports: + - { protocol: TCP, port: 3002 } + - to: + - ipBlock: + cidr: 0.0.0.0/0 + except: ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"] + ports: + - { protocol: TCP, port: 1935 } + - { protocol: TCP, port: 443 } diff --git a/src/deploy/stream/k8s/secret.yaml b/src/deploy/stream/k8s/secret.yaml new file mode 100644 index 0000000000..5ece654d24 --- /dev/null +++ b/src/deploy/stream/k8s/secret.yaml @@ -0,0 +1,36 @@ +# TEMPLATES ONLY — both Secrets are created out of band and never committed: +# +# kubectl -n hive-stream create secret generic twitch-stream \ +# --from-literal=TWITCH_STREAM_KEY='live_xxxxxxxx_yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy' +# +# # copy the spoke's shared dashboard token from its own namespace +# kubectl -n hive-stream create secret generic dashboard-token \ +# --from-literal=DASHBOARD_TOKEN="$(kubectl -n get secret hive-secrets \ +# -o jsonpath='{.data.dashboard-token}' | base64 -d)" +# +# (or, for the public route, DASHBOARD_TOKEN = a GitHub token of a user with +# access to the hive on the hub — see src/docs/streaming-the-activity-monitor.md) +# +# They are listed here so `kubectl apply -k` fails loudly if they are missing +# rather than starting a pod that streams a login page. +apiVersion: v1 +kind: Secret +metadata: + name: twitch-stream + namespace: hive-stream + annotations: + hive.hivecommons.dev/template: "replace with kubectl create secret; do not apply this file" +type: Opaque +stringData: + TWITCH_STREAM_KEY: "REPLACE-ME" +--- +apiVersion: v1 +kind: Secret +metadata: + name: dashboard-token + namespace: hive-stream + annotations: + hive.hivecommons.dev/template: "replace with kubectl create secret; do not apply this file" +type: Opaque +stringData: + DASHBOARD_TOKEN: "REPLACE-ME" diff --git a/src/deploy/stream/overlays/hive-hosted/kustomization.yaml b/src/deploy/stream/overlays/hive-hosted/kustomization.yaml new file mode 100644 index 0000000000..7eb705173d --- /dev/null +++ b/src/deploy/stream/overlays/hive-hosted/kustomization.yaml @@ -0,0 +1,28 @@ +# hive's own hosted spoke on hive-oke: namespace +# hive-hosted-hosted-available-oke-11-placeholder-r05x, dashboard Service +# `hive` port 3002. The streamer reaches it in-cluster with the spoke's shared +# dashboard token (hub_proxied: true keeps the Bearer path enabled there). +# +# kubectl --context hive-oke apply -k src/deploy/stream/overlays/hive-hosted +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - ../../k8s +images: + - name: ghcr.io/hivecommons/hive-stream + newTag: v5-latest +patches: + - target: + kind: ConfigMap + name: hive-stream + patch: |- + - op: replace + path: /data/DASHBOARD_URL + value: http://hive.hive-hosted-hosted-available-oke-11-placeholder-r05x.svc.cluster.local:3002 + - target: + kind: NetworkPolicy + name: hive-stream + patch: |- + - op: replace + path: /spec/egress/1/to/0/namespaceSelector/matchLabels/kubernetes.io~1metadata.name + value: hive-hosted-hosted-available-oke-11-placeholder-r05x diff --git a/src/docs/documentation-map.md b/src/docs/documentation-map.md index a3d9d4c419..96fd74ab5a 100644 --- a/src/docs/documentation-map.md +++ b/src/docs/documentation-map.md @@ -127,6 +127,7 @@ Documentation for the current Hive line (branch `v5`; the code and docs live und - [Backup and restore](backup-restore.md) — choose runtime-specific backups, encryption, safe restoration, and migration. Covers identity checks and rootless ownership traps. - [Hub disaster recovery](../../docs/HUB_DISASTER_RECOVERY.md) — the hub-level runbook that goes beyond per-hive backup: hub backup and key escrow, spoke fleet recovery, Slack blast, and the full rebuild-from-zero procedure after a catastrophic loss. - [Deployment helper scripts](deployment-scripts.md) — the all-in-one LXC setup, Proxmox LXC, and blue-green Compose helpers. All are Docker-only; the page states each script's runtime scope and where a Podman operator should go instead. +- [Streaming the Activity Monitor](streaming-the-activity-monitor.md) — put the dashboard's stage tracker on an unattended 24/7 Twitch stream: Twitch-side setup, the `hive-stream` image and Kustomize overlay, verification and troubleshooting. - [`bin/` pipeline script index](../../bin/README.md) — map of the deterministic pipeline and operational scripts, grouped by function. - [Dashboard API reference](api-reference.md) — pragmatic route index for dashboard and hub endpoints; one page per area under `api-reference/` (health, auth, configuration, agents, ACMM, cost, knowledge, contribute, nous, inception, beads, misc, hub SaaS, hub server). - [Dashboard OpenAPI spec](../../dashboard/openapi.json) — machine-readable REST API reference for integrations. diff --git a/src/docs/streaming-the-activity-monitor.md b/src/docs/streaming-the-activity-monitor.md new file mode 100644 index 0000000000..249563730a --- /dev/null +++ b/src/docs/streaming-the-activity-monitor.md @@ -0,0 +1,172 @@ +# Streaming the Activity Monitor to Twitch + +An unattended, 24/7 Twitch stream of the hive dashboard's **Activity Monitor** +(the stage tracker: every tracked issue and PR walking Open → Actionable → +Claimed → PR in progress → CI / Review → Merge queue). The first stream is +hive's own hosted spoke on `hive-oke`, channel +[`twitch.tv/hivecommons`](https://www.twitch.tv/hivecommons). + +Everything lives in [`src/deploy/stream/`](../deploy/stream/README.md): a +container that renders the dashboard in a virtual display and pushes it to +Twitch, and the Kubernetes manifests that run it next to the hive it watches. + +``` +Deployment hive-stream (ns hive-stream, 1 replica) + Xvfb :99 1920x1080 + authproxy 127.0.0.1:8099 ──Authorization: Bearer──▶ hive dashboard Service :3002 + Chromium --kiosk http://127.0.0.1:8099/?kiosk=1#section-activity-monitor-section + ffmpeg x11grab 30 fps + silent audio ──libx264 4500 kbps CBR──▶ rtmp://live.twitch.tv/app/ +``` + +Nothing here touches Twitch or the cluster until **you** create the Secrets and +apply the overlay — the steps below are all yours to run. + +## 1. Twitch side (once) + +Open the Creator Dashboard at `dashboard.twitch.tv` while logged in as +`hivecommons`. + +1. **Settings → Stream → Stream Key & Preferences**. Copy the **Primary Stream + key** (`live_…`). Treat it like a password: anyone holding it can broadcast + on the channel. Use **Reset** here if it ever leaks; then update the Secret + (step 2) and restart the pod. +2. Still on that page: **Disconnect protection** on (hides short drops during + Chromium/ffmpeg restarts), **Latency mode** → Normal, and **Store past + broadcasts** off unless you want 7-day VODs. Clips can stay on; nothing on + the tracker is sensitive (see [Privacy](#privacy)). +3. **Stream Manager → Edit Stream Info**: title (e.g. `hive 🐝 Activity Monitor + — autonomous PR pipeline, live`), **Category → Software and Game + Development**, tags `programming`, `opensource`, `golang`, `ai`. Language + English, **not** mature. +4. **Settings → Moderation**: Followers-only or Email-verified chat, AutoMod + level 2 — nobody is watching chat on an unattended stream. +5. Optional: **Settings → Channel → Brand** for a panel pointing at + `github.com/hivecommons/hive`. + +## 2. Create the Secrets + +Both Secrets are created out of band and never committed +(`src/deploy/stream/k8s/secret.yaml` is a template only). Namespace +`hive-stream` is dedicated: the hub provisioner owns the hosted spoke's +namespace outright and would reclaim anything placed there. + +```sh +kubectl --context hive-oke create namespace hive-stream + +# Twitch Creator Dashboard → Settings → Stream → Primary Stream key +kubectl --context hive-oke -n hive-stream create secret generic twitch-stream \ + --from-literal=TWITCH_STREAM_KEY='live_PASTE_THE_KEY_HERE' + +# The spoke's shared dashboard token, copied from its own namespace +kubectl --context hive-oke -n hive-stream create secret generic dashboard-token \ + --from-literal=DASHBOARD_TOKEN="$(kubectl --context hive-oke \ + -n hive-hosted-hosted-available-oke-11-placeholder-r05x \ + get secret hive-secrets -o jsonpath='{.data.dashboard-token}' | base64 -d)" +``` + +The shared token works because the streamer reaches the dashboard over the +in-cluster Service and hive's hive is `hub_proxied: true`, so the spoke still +honours `Authorization: Bearer `. The token is injected +by a loopback proxy inside the pod; it never appears in the URL, in Chromium's +history, in logs, or on screen. + +**Alternative — the public route.** To stream a hive you cannot reach +in-cluster (or from a laptop with `docker compose`), set `DASHBOARD_URL` to the +public route (`https://.hive.hivecommons.dev`) and `DASHBOARD_TOKEN` to +a **GitHub token** of a user who has access to that hive on the hub; the +route's `auth-url` check accepts `Authorization: Bearer ` and +needs no OAuth scopes. Prefer a dedicated read-only viewer account so the +stream never shows an owner's Welcome/NPS prompts or the action menus. + +## 3. Apply + +The image is published by `.github/workflows/stream-image.yml` on every merge +to `v5` that touches `src/deploy/stream/**`, as +`ghcr.io/hivecommons/hive-stream:` and `:v5-latest`. The overlay tracks +`v5-latest`. + +```sh +kubectl --context hive-oke apply -k src/deploy/stream/overlays/hive-hosted +kubectl --context hive-oke -n hive-stream rollout status deploy/hive-stream +``` + +For another hive, copy `overlays/hive-hosted/` and change the two +`CHANGE-ME` patches (dashboard Service URL and the NetworkPolicy's namespace). + +## 4. Verify + +```sh +kubectl --context hive-oke -n hive-stream logs deploy/hive-stream -f +``` + +Healthy start-up reads: + +``` +stream: Xvfb up on :99 (1920x1080) +authproxy: 127.0.0.1:8099 -> http://hive..svc.cluster.local:3002 (token set) +stream: authproxy up; kiosk URL http://127.0.0.1:8099/?kiosk=1#section-activity-monitor-section … +stream: chromium starting +stream: ffmpeg starting (1920x1080@30, 4500k CBR, keyint 60, sink -f flv …) +``` + +Then open **Stream Manager** on Twitch: the preview should show the tracker +within ~30 s, with the **Live** badge and bitrate around 4500 kbps. The pod's +`healthcheck.sh` (used by the liveness probe) demands that Chromium is running +and ffmpeg has written progress in the last 20 s: + +```sh +kubectl --context hive-oke -n hive-stream exec deploy/hive-stream -- healthcheck.sh +# ok frames=12345 +``` + +A page reload fires every `RELOAD_EVERY` (default `30m`) so a newly rolled +dashboard build is picked up without restarting the pod. + +## Troubleshooting + +| Symptom | Cause / fix | +| --- | --- | +| Stream shows a **login page** or **403** | Auth. Logs will say `authproxy: upstream redirected … to login`. In-cluster: the `dashboard-token` Secret is wrong or the hive is not `hub_proxied`. Public route: the GitHub token's user has no access to this hive. | +| **Black** or blank frame | Chromium crashed or has not painted yet. Check `kubectl logs` for `chromium exited; restarting`; the usual cause is `/dev/shm` too small (the Deployment mounts a 512 Mi memory emptyDir — keep it). | +| Twitch says **"Bitrate too high/unstable"** | Drop `BITRATE` to `3000k` in the ConfigMap, or `VIDEO_SIZE=1280x720` (and the matching `Xvfb` size is derived automatically). CPU-bound encodes also benefit from `X264_PRESET=superfast`. | +| Pod **CrashLoopBackOff** on start | `DASHBOARD_URL` unset, or ffmpeg cannot reach `live.twitch.tv:1935` — check the NetworkPolicy allows egress to public IPs and that the cluster permits outbound RTMP. | +| Stream drops every few minutes | Twitch rejected the key (reset in Creator Dashboard?). ffmpeg restarts with 2→60 s backoff; the logs show the masked `***` key, never the real one. | +| Old UI after a dashboard roll | Wait for the next `RELOAD_EVERY` tick or `kubectl rollout restart deploy/hive-stream`. | +| Pod is `Running` but Twitch is offline | `healthcheck.sh` in the pod; if `frames` is not increasing, the ffmpeg sink is failing — look for `rtmp` errors in the logs. | + +Pure CPU budget: software x264 at 1080p30 `veryfast` uses roughly 1.5 cores; +the Deployment requests 1 CPU / 2 Gi and limits 2 CPU / 3 Gi. + +## Privacy + +The tracker renders what GitHub already shows publicly for the repos this hive +tracks: issue and PR numbers, titles, authors, labels, CI state and merge-queue +position. For hive's hive that is `hivecommons/hive`, a public repository. It +does **not** render tokens, secrets, settings, webhooks, chat, or the +operator's agent terminals; `?kiosk=1` additionally hides the sidebar, topbar, +avatar/settings menus, notices, the Welcome and NPS dialogs, and every other +dashboard section. Do not point the streamer at a hive tracking private +repositories without reviewing what the tracker would show. + +## Quick manual test with OBS (no cluster) + +1. In OBS add a **Browser** source, 1920×1080, URL + `https://.hive.hivecommons.dev/?kiosk=1#section-activity-monitor-section`; + tick **Shutdown source when not visible** off. +2. Right-click the source → **Interact**, log in with GitHub once (OBS keeps + the session cookie). +3. **Settings → Stream**: Service Twitch, paste the Primary Stream key. +4. **Settings → Output**: 4500 kbps CBR, keyframe interval 2 s, x264 + `veryfast`. +5. **Start Streaming**. + +## Running the container from a laptop + +```sh +cd src/deploy/stream && cp .env.example .env # fill DASHBOARD_URL / DASHBOARD_TOKEN / TWITCH_STREAM_KEY +docker compose up --build +``` + +Dry run without Twitch: `STREAM_OUTPUT=null STREAM_SECONDS=20 docker compose up` +(or `STREAM_OUTPUT=/run/stream/out/test.flv` with `./out` mounted) proves +capture and encode without a stream key. diff --git a/src/pkg/dashboard/kiosk_mode_test.go b/src/pkg/dashboard/kiosk_mode_test.go new file mode 100644 index 0000000000..0b9be0e000 --- /dev/null +++ b/src/pkg/dashboard/kiosk_mode_test.go @@ -0,0 +1,34 @@ +package dashboard + +import ( + "strings" + "testing" +) + +// TestKioskModeWiring guards the `?kiosk=1` display mode the headless Twitch +// streamer (src/deploy/stream) loads: the flag is read before first paint, the +// chrome and every non-tracker section are removed from flow, and the two +// dialogs that would otherwise park on an unattended screen are suppressed. +func TestKioskModeWiring(t *testing.T) { + html := indexHTML(t) + for _, want := range []string{ + `searchParams.get('kiosk')==='1'`, + `window.hiveKioskMode=function(){ return !!window.HIVE_KIOSK; };`, + `document.body.classList.add('kiosk-mode');`, + `#section-activity-monitor-section'`, + `body.kiosk-mode .oc-sidebar, body.kiosk-mode .oc-sidebar-resize, body.kiosk-mode .oc-topbar,`, + // Must out-specify theme.go's layout guard `body #oc-topbar.oc-topbar{display:grid!important}`. + `body.kiosk-mode #oc-topbar.oc-topbar { display: none !important; }`, + `body.kiosk-mode #hive-dashboard-root > [data-dashboard-section]:not(#activity-monitor-section) { display: none !important; }`, + `if (!_welcomeState.dismissed && !(window.hiveKioskMode && window.hiveKioskMode())) openWelcomeDialog();`, + `if (window.hiveKioskMode && window.hiveKioskMode()) return;`, + `if (!el._countdownWired && !(window.hiveKioskMode && window.hiveKioskMode())) {`, + } { + if !strings.Contains(html, want) { + t.Errorf("index.html missing kiosk-mode wiring %q", want) + } + } + if strings.Contains(html, `localStorage.setItem('hive-kiosk`) { + t.Error("kiosk mode must not persist state in localStorage") + } +} diff --git a/src/pkg/dashboard/static-src/css/kiosk.css b/src/pkg/dashboard/static-src/css/kiosk.css new file mode 100644 index 0000000000..e583cb4b09 --- /dev/null +++ b/src/pkg/dashboard/static-src/css/kiosk.css @@ -0,0 +1,18 @@ +/* ---- kiosk: unattended display mode (#15594) ---- + `?kiosk=1` (see js/boot.js) is what the headless Twitch streamer in + src/deploy/stream loads. The page becomes the Hive activity monitor and + nothing else: no sidebar, topbar, avatar menu, chat FAB or notices, and + the other sections are removed from flow so the tracker fills 1920x1080. + Toasts and the merge banners stay — they are part of the show. */ + body.kiosk-mode { padding: var(--sp-5) var(--sp-7) var(--sp-7) var(--sp-7); cursor: none; --navbar-sticky-height: 0px; } + body.kiosk-mode .oc-sidebar, body.kiosk-mode .oc-sidebar-resize, body.kiosk-mode .oc-topbar, + body.kiosk-mode #dash-notices, body.kiosk-mode #oc-agent-detail, body.kiosk-mode .hive-chat-fab, + body.kiosk-mode .hive-chat-panel, body.kiosk-mode #welcome-overlay, body.kiosk-mode .nps-card { display: none !important; } + /* /api/theme.css ships a layout guard `body #oc-topbar.oc-topbar{display:grid!important}` + (theme/theme.go); match its id specificity so kiosk still wins. */ + body.kiosk-mode #oc-topbar.oc-topbar { display: none !important; } + body.kiosk-mode #hive-dashboard-root > [data-dashboard-section]:not(#activity-monitor-section) { display: none !important; } + body.kiosk-mode #activity-monitor-section .dashboard-grip, body.kiosk-mode #activity-monitor-section .section-chevron { display: none !important; } + body.kiosk-mode #activity-monitor-section > .section-label { pointer-events: none; } + body.kiosk-mode .ham-sticky { top: 0; } + body.kiosk-mode .ham-cols { top: var(--ham-sticky-bar-h); } diff --git a/src/pkg/dashboard/static-src/js/boot.js b/src/pkg/dashboard/static-src/js/boot.js index 0d04fae2d4..326de55b01 100644 --- a/src/pkg/dashboard/static-src/js/boot.js +++ b/src/pkg/dashboard/static-src/js/boot.js @@ -5,6 +5,23 @@ // for toggle labels; the DOMContentLoaded hook below guarantees it runs // once the topbar/sidebar buttons exist, so the label and body class always // sync from storage. +// Kiosk mode (#15594): `?kiosk=1` turns the dashboard into an unattended +// display for a headless streamer (src/deploy/stream). It is a pure +// presentation flag — it grants nothing, hides the chrome (sidebar, topbar, +// avatar menu, chat FAB, notices) and every section except the Hive activity +// monitor, suppresses the welcome/NPS dialogs and the toast hover-pause, and +// never writes to localStorage so a rolled SPA can't inherit stale state. +// The class is set here, before first paint, so the chrome never flashes. +(function(){ + var kiosk=false; + try { kiosk=new URL(window.location.href).searchParams.get('kiosk')==='1'; } catch(e) {} + window.HIVE_KIOSK=kiosk; + window.hiveKioskMode=function(){ return !!window.HIVE_KIOSK; }; + if(kiosk){ + document.body.classList.add('kiosk-mode'); + if(!location.hash) history.replaceState(null,'',location.pathname+location.search+'#section-activity-monitor-section'); + } +})(); (function(){ var m=localStorage.getItem('hive-layout-mode'); if(m==='openclaw')m='light'; diff --git a/src/pkg/dashboard/static-src/js/nps.js b/src/pkg/dashboard/static-src/js/nps.js index 4af5691f57..98551e541a 100644 --- a/src/pkg/dashboard/static-src/js/nps.js +++ b/src/pkg/dashboard/static-src/js/nps.js @@ -236,6 +236,7 @@ function showNPSSurvey(status) { if (_npsShownThisLoad || _npsCard) return; + if (window.hiveKioskMode && window.hiveKioskMode()) return; _npsShownThisLoad = true; const maxChars = Number(status && status.max_feedback_chars) || 0; let selected = null; diff --git a/src/pkg/dashboard/static-src/js/tooltips-dialogs.js b/src/pkg/dashboard/static-src/js/tooltips-dialogs.js index d3d975a102..d861466a1f 100644 --- a/src/pkg/dashboard/static-src/js/tooltips-dialogs.js +++ b/src/pkg/dashboard/static-src/js/tooltips-dialogs.js @@ -761,7 +761,9 @@ cd.remaining = Math.max(0, cd.remaining - (Date.now() - cd.startedAt)); bar.style.animationPlayState = 'paused'; }; - if (!el._countdownWired) { + // A kiosk (#15594) has no pointer; the hidden cursor must never park a + // toast on screen for the whole stream. + if (!el._countdownWired && !(window.hiveKioskMode && window.hiveKioskMode())) { el._countdownWired = true; const c = () => el._countdown; el.addEventListener('mouseenter', () => { const x = c(); if (x) { x.hovered = true; x.pause(); } }); diff --git a/src/pkg/dashboard/static-src/js/welcome.js b/src/pkg/dashboard/static-src/js/welcome.js index cf7a5d1854..9c839f8388 100644 --- a/src/pkg/dashboard/static-src/js/welcome.js +++ b/src/pkg/dashboard/static-src/js/welcome.js @@ -44,7 +44,8 @@ if (navItem) navItem.style.display = ''; const topBtn = document.getElementById('welcome-topbar-btn'); if (topBtn) topBtn.style.display = ''; - if (!_welcomeState.dismissed) openWelcomeDialog(); + // Kiosk displays (#15594) are unattended: nothing can dismiss a dialog. + if (!_welcomeState.dismissed && !(window.hiveKioskMode && window.hiveKioskMode())) openWelcomeDialog(); } function openWelcomeDialog() { diff --git a/src/pkg/dashboard/static-src/manifest.txt b/src/pkg/dashboard/static-src/manifest.txt index 343b88f9e1..bf69df686a 100644 --- a/src/pkg/dashboard/static-src/manifest.txt +++ b/src/pkg/dashboard/static-src/manifest.txt @@ -30,6 +30,7 @@ css/responsive.css css/recipes-utilities.css css/welcome.css css/review-campaigns.css +css/kiosk.css css/variables.css glue/style-close-body-open.html js/boot.js diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 8e805c0719..f43d387190 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -6623,6 +6623,24 @@ .review-priority { display: inline-block; padding: var(--sp-1) var(--sp-4); border-radius: var(--r-sm); font-size: var(--fs-2xs); color: var(--muted); border: 1px solid var(--blue); } .review-priority-high { border-color: var(--red); } .review-priority-low { border-color: var(--muted); } +/* ---- kiosk: unattended display mode (#15594) ---- + `?kiosk=1` (see js/boot.js) is what the headless Twitch streamer in + src/deploy/stream loads. The page becomes the Hive activity monitor and + nothing else: no sidebar, topbar, avatar menu, chat FAB or notices, and + the other sections are removed from flow so the tracker fills 1920x1080. + Toasts and the merge banners stay — they are part of the show. */ + body.kiosk-mode { padding: var(--sp-5) var(--sp-7) var(--sp-7) var(--sp-7); cursor: none; --navbar-sticky-height: 0px; } + body.kiosk-mode .oc-sidebar, body.kiosk-mode .oc-sidebar-resize, body.kiosk-mode .oc-topbar, + body.kiosk-mode #dash-notices, body.kiosk-mode #oc-agent-detail, body.kiosk-mode .hive-chat-fab, + body.kiosk-mode .hive-chat-panel, body.kiosk-mode #welcome-overlay, body.kiosk-mode .nps-card { display: none !important; } + /* /api/theme.css ships a layout guard `body #oc-topbar.oc-topbar{display:grid!important}` + (theme/theme.go); match its id specificity so kiosk still wins. */ + body.kiosk-mode #oc-topbar.oc-topbar { display: none !important; } + body.kiosk-mode #hive-dashboard-root > [data-dashboard-section]:not(#activity-monitor-section) { display: none !important; } + body.kiosk-mode #activity-monitor-section .dashboard-grip, body.kiosk-mode #activity-monitor-section .section-chevron { display: none !important; } + body.kiosk-mode #activity-monitor-section > .section-label { pointer-events: none; } + body.kiosk-mode .ham-sticky { top: 0; } + body.kiosk-mode .ham-cols { top: var(--ham-sticky-bar-h); } .var-empty{color:var(--muted);font-size:var(--fs-sm);padding:var(--sp-2) var(--sp-0)} .var-section{margin-top:var(--sp-6);border-top:1px solid var(--border);padding-top:var(--sp-5)} .var-heading{font-weight:600;font-size:var(--fs-sm);margin-bottom:var(--sp-4)} @@ -6647,6 +6665,23 @@ // for toggle labels; the DOMContentLoaded hook below guarantees it runs // once the topbar/sidebar buttons exist, so the label and body class always // sync from storage. +// Kiosk mode (#15594): `?kiosk=1` turns the dashboard into an unattended +// display for a headless streamer (src/deploy/stream). It is a pure +// presentation flag — it grants nothing, hides the chrome (sidebar, topbar, +// avatar menu, chat FAB, notices) and every section except the Hive activity +// monitor, suppresses the welcome/NPS dialogs and the toast hover-pause, and +// never writes to localStorage so a rolled SPA can't inherit stale state. +// The class is set here, before first paint, so the chrome never flashes. +(function(){ + var kiosk=false; + try { kiosk=new URL(window.location.href).searchParams.get('kiosk')==='1'; } catch(e) {} + window.HIVE_KIOSK=kiosk; + window.hiveKioskMode=function(){ return !!window.HIVE_KIOSK; }; + if(kiosk){ + document.body.classList.add('kiosk-mode'); + if(!location.hash) history.replaceState(null,'',location.pathname+location.search+'#section-activity-monitor-section'); + } +})(); (function(){ var m=localStorage.getItem('hive-layout-mode'); if(m==='openclaw')m='light'; @@ -42376,7 +42411,9 @@

GitHub Projects sync

cd.remaining = Math.max(0, cd.remaining - (Date.now() - cd.startedAt)); bar.style.animationPlayState = 'paused'; }; - if (!el._countdownWired) { + // A kiosk (#15594) has no pointer; the hidden cursor must never park a + // toast on screen for the whole stream. + if (!el._countdownWired && !(window.hiveKioskMode && window.hiveKioskMode())) { el._countdownWired = true; const c = () => el._countdown; el.addEventListener('mouseenter', () => { const x = c(); if (x) { x.hovered = true; x.pause(); } }); @@ -61280,6 +61317,7 @@

${esc(s.title)}

function showNPSSurvey(status) { if (_npsShownThisLoad || _npsCard) return; + if (window.hiveKioskMode && window.hiveKioskMode()) return; _npsShownThisLoad = true; const maxChars = Number(status && status.max_feedback_chars) || 0; let selected = null; @@ -61425,7 +61463,8 @@

${esc(s.title)}

if (navItem) navItem.style.display = ''; const topBtn = document.getElementById('welcome-topbar-btn'); if (topBtn) topBtn.style.display = ''; - if (!_welcomeState.dismissed) openWelcomeDialog(); + // Kiosk displays (#15594) are unattended: nothing can dismiss a dialog. + if (!_welcomeState.dismissed && !(window.hiveKioskMode && window.hiveKioskMode())) openWelcomeDialog(); } function openWelcomeDialog() { From 17ad060449de87bf983ca4dd52a2863a15644ba8 Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Thu, 29 Oct 2026 21:11:34 -0400 Subject: [PATCH 2/2] fix(kiosk): hide the topbar with an id+attribute selector MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TestNavbarStickyThreeZoneLayout scans every `.oc-topbar {` rule and requires its display to be grid; the kiosk override (and its comment) matched. Use `html body.kiosk-mode #oc-topbar[id]` instead — still (1,2,2), still beats theme.go's layout guard — and reword the comment. Signed-off-by: Andrew Anderson --- src/pkg/dashboard/kiosk_mode_test.go | 4 ++-- src/pkg/dashboard/static-src/css/kiosk.css | 6 +++--- src/pkg/dashboard/static/index.html | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/pkg/dashboard/kiosk_mode_test.go b/src/pkg/dashboard/kiosk_mode_test.go index 0b9be0e000..2c43ace190 100644 --- a/src/pkg/dashboard/kiosk_mode_test.go +++ b/src/pkg/dashboard/kiosk_mode_test.go @@ -17,8 +17,8 @@ func TestKioskModeWiring(t *testing.T) { `document.body.classList.add('kiosk-mode');`, `#section-activity-monitor-section'`, `body.kiosk-mode .oc-sidebar, body.kiosk-mode .oc-sidebar-resize, body.kiosk-mode .oc-topbar,`, - // Must out-specify theme.go's layout guard `body #oc-topbar.oc-topbar{display:grid!important}`. - `body.kiosk-mode #oc-topbar.oc-topbar { display: none !important; }`, + // Must out-specify theme.go's layoutGuardCSS, which forces the topbar visible with id specificity. + `html body.kiosk-mode #oc-topbar[id] { display: none !important; }`, `body.kiosk-mode #hive-dashboard-root > [data-dashboard-section]:not(#activity-monitor-section) { display: none !important; }`, `if (!_welcomeState.dismissed && !(window.hiveKioskMode && window.hiveKioskMode())) openWelcomeDialog();`, `if (window.hiveKioskMode && window.hiveKioskMode()) return;`, diff --git a/src/pkg/dashboard/static-src/css/kiosk.css b/src/pkg/dashboard/static-src/css/kiosk.css index e583cb4b09..4f185ca451 100644 --- a/src/pkg/dashboard/static-src/css/kiosk.css +++ b/src/pkg/dashboard/static-src/css/kiosk.css @@ -8,9 +8,9 @@ body.kiosk-mode .oc-sidebar, body.kiosk-mode .oc-sidebar-resize, body.kiosk-mode .oc-topbar, body.kiosk-mode #dash-notices, body.kiosk-mode #oc-agent-detail, body.kiosk-mode .hive-chat-fab, body.kiosk-mode .hive-chat-panel, body.kiosk-mode #welcome-overlay, body.kiosk-mode .nps-card { display: none !important; } - /* /api/theme.css ships a layout guard `body #oc-topbar.oc-topbar{display:grid!important}` - (theme/theme.go); match its id specificity so kiosk still wins. */ - body.kiosk-mode #oc-topbar.oc-topbar { display: none !important; } + /* /api/theme.css (theme/theme.go layoutGuardCSS) forces the topbar to + display:grid!important with id specificity; beat it with (1,2,2). */ + html body.kiosk-mode #oc-topbar[id] { display: none !important; } body.kiosk-mode #hive-dashboard-root > [data-dashboard-section]:not(#activity-monitor-section) { display: none !important; } body.kiosk-mode #activity-monitor-section .dashboard-grip, body.kiosk-mode #activity-monitor-section .section-chevron { display: none !important; } body.kiosk-mode #activity-monitor-section > .section-label { pointer-events: none; } diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index f43d387190..ef06763b3a 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -6633,9 +6633,9 @@ body.kiosk-mode .oc-sidebar, body.kiosk-mode .oc-sidebar-resize, body.kiosk-mode .oc-topbar, body.kiosk-mode #dash-notices, body.kiosk-mode #oc-agent-detail, body.kiosk-mode .hive-chat-fab, body.kiosk-mode .hive-chat-panel, body.kiosk-mode #welcome-overlay, body.kiosk-mode .nps-card { display: none !important; } - /* /api/theme.css ships a layout guard `body #oc-topbar.oc-topbar{display:grid!important}` - (theme/theme.go); match its id specificity so kiosk still wins. */ - body.kiosk-mode #oc-topbar.oc-topbar { display: none !important; } + /* /api/theme.css (theme/theme.go layoutGuardCSS) forces the topbar to + display:grid!important with id specificity; beat it with (1,2,2). */ + html body.kiosk-mode #oc-topbar[id] { display: none !important; } body.kiosk-mode #hive-dashboard-root > [data-dashboard-section]:not(#activity-monitor-section) { display: none !important; } body.kiosk-mode #activity-monitor-section .dashboard-grip, body.kiosk-mode #activity-monitor-section .section-chevron { display: none !important; } body.kiosk-mode #activity-monitor-section > .section-label { pointer-events: none; }