diff --git a/docs/design/infra.md b/docs/design/infra.md index e6aea86..33a21b5 100644 --- a/docs/design/infra.md +++ b/docs/design/infra.md @@ -555,7 +555,7 @@ into this project. | What | Where | Mode | |---|---|---| -| source of truth | `pass twitch/-key`, `twitch/-key`, `twitch/helix-client-id`, `twitch/helix-client-secret`, `twitch/fly-pokemon-bot-token` | WSL box only | +| source of truth | `pass twitch/-key`, `twitch/-key`, `twitch/-client-id`, `twitch/-client-secret`, `twitch/-token` | WSL box only | | stream key, in CT | `/etc/fly/creds/twitch-key.cred` | `root:root 0400`, dir `0700` | | bridge app creds, in CT | `/etc/fly/creds/twitch-app.cred` | `root:root 0400` | | bridge refresh tokens | `/var/lib/fly/bridge/tokens.json` | `fly:fly 0600` | diff --git a/docs/design/stage-bridge.md b/docs/design/stage-bridge.md index c05aa44..782231e 100644 --- a/docs/design/stage-bridge.md +++ b/docs/design/stage-bridge.md @@ -177,7 +177,7 @@ Node 22, TypeScript, `tsx` for dev, `node --test` for tests. Deps: `@twurple/aut One-time interactive authorization in `tools/authorize.mts`, run by hand on the WSL box, producing a refresh token. Primary path: authorization-code flow with a temporary `http://localhost:3000/callback` listener (Twitch permits `http://localhost` redirects) and `exchangeCode` from `@twurple/auth`. Device-code grant against `https://id.twitch.tv/oauth2/device` is the fallback for headless authorization; twurple's first-class support for it is **unverified**, so if used it is 30 lines of hand-rolled polling rather than a library claim. -Runtime uses `RefreshingAuthProvider` with `onRefresh` persisting to `/var/lib/flybridge/tokens.json`, written `0600` by an atomic temp-file rename, owned by the service user, never in git (`.gitignore` plus a repo-level check). `TWITCH_CLIENT_ID` and `TWITCH_CLIENT_SECRET` arrive via systemd `LoadCredentialEncrypted=`, sourced from `pass` on the WSL box under `twitch/fly-pokemon-client-{id,secret}`, matching the stream-key posture already documented. +Runtime uses `RefreshingAuthProvider` with `onRefresh` persisting to `/var/lib/flybridge/tokens.json`, written `0600` by an atomic temp-file rename, owned by the service user, never in git (`.gitignore` plus a repo-level check). `TWITCH_CLIENT_ID` and `TWITCH_CLIENT_SECRET` arrive via systemd `LoadCredentialEncrypted=`, sourced from `pass` on the WSL box under `twitch/-client-{id,secret}`, matching the stream-key posture already documented. Two identities, both registered on the provider: the **bot account** (chat send) and the **broadcaster account** (redemptions, predictions, markers). Scopes to request, with the intent recorded per scope: diff --git a/infra/06-secrets.sh b/infra/06-secrets.sh index f6d27b8..7a571c6 100755 --- a/infra/06-secrets.sh +++ b/infra/06-secrets.sh @@ -26,7 +26,7 @@ # docs/design/stage-bridge.md section B1 has flybridge read # TWITCH_CLIENT_ID and TWITCH_CLIENT_SECRET as two separate # LoadCredentialEncrypted= values sourced from -# twitch/fly-pokemon-client-{id,secret}. This script follows infra.md (the +# twitch/-client-{id,secret}. This script follows infra.md (the # doc this task implements) and writes ONE twitch-app.cred containing both # values as two lines ("\n\n"); flybridge's own # implementation (out of scope here, not yet written) will need to parse @@ -118,9 +118,14 @@ fi # docs/stream-mvp-plan.md's rollout order) — install only if both pass # entries already exist, so running this before the Twitch app is # registered is a clean no-op rather than a hard failure. -BRIDGE_ID_KEY="${BRIDGE_ID_KEY:-twitch/helix-client-id}" -BRIDGE_SECRET_KEY="${BRIDGE_SECRET_KEY:-twitch/helix-client-secret}" -if command -v pass >/dev/null 2>&1 \ +# The two entry NAMES come from the env file (BRIDGE_ID_KEY, BRIDGE_SECRET_KEY): a +# `pass` entry name identifies the operator's store, so it is not spelled here. +BRIDGE_ID_KEY="${BRIDGE_ID_KEY:-}" +BRIDGE_SECRET_KEY="${BRIDGE_SECRET_KEY:-}" +if [ -z "$BRIDGE_ID_KEY" ] || [ -z "$BRIDGE_SECRET_KEY" ]; then + log "06-secrets: WARNING: BRIDGE_ID_KEY / BRIDGE_SECRET_KEY are not set in the env file, skipping twitch-app." \ + "Set both to the pass entry names of the Twitch app id and secret (infra/env/example.env) to install it." +elif command -v pass >/dev/null 2>&1 \ && pass show "$BRIDGE_ID_KEY" >/dev/null 2>&1 \ && pass show "$BRIDGE_SECRET_KEY" >/dev/null 2>&1; then log "06-secrets: installing twitch-app from pass:${BRIDGE_ID_KEY} + pass:${BRIDGE_SECRET_KEY}" diff --git a/infra/docs/secrets-history-scan.md b/infra/docs/secrets-history-scan.md index 6e5e257..dbe137b 100644 --- a/infra/docs/secrets-history-scan.md +++ b/infra/docs/secrets-history-scan.md @@ -49,7 +49,7 @@ a credential. Full list: | # | shape matched | path | commits (first → last touching) | verdict | | --- | --- | --- | --- | --- | -| 1 | `pass show "$PASS_KEY"` shell pipelines, 4 blobs | `infra/06-secrets.sh` | `0d1a762` → `69816e6` | **False positive.** The script's whole job is to pipe `pass show` into `systemd-creds` on the container; the value never lands in a file and never in git. `PASS_KEY` holds a pass *entry name* (`twitch/fly-pokemon-key`), not a secret. | +| 1 | `pass show "$PASS_KEY"` shell pipelines, 4 blobs | `infra/06-secrets.sh` | `0d1a762` → `69816e6` | **False positive.** The script's whole job is to pipe `pass show` into `systemd-creds` on the container; the value never lands in a file and never in git. `PASS_KEY` holds a pass *entry name* (`twitch/-key`), not a secret. | | 2 | `pass show … \| head -c8` in a verify helper, 6 blobs | `infra/verify.sh` | `0d1a762` → `57276d4` | **False positive.** Reads the first 8 bytes of the stored key to compare a prefix against what the container holds. The prefix is computed at run time and printed nowhere that is committed. | | 3 | `accessToken:` / `refreshToken:` struct fields, 3 blobs | `services/bridge/src/auth.ts` | `d9f00b6` → `48cd40a` | **False positive.** Twurple `AccessToken` field names in code (`accessToken: token.accessToken`). No literal values. | | 4 | `accessToken:` / `refreshToken:` struct fields, 1 blob | `services/bridge/tools/authorize.mts` | `77f5892` | **False positive.** Same: the interactive authorize tool writes the token it just fetched to a path outside the repo. | diff --git a/infra/env/example.env b/infra/env/example.env index 4dae070..b4a9604 100644 --- a/infra/env/example.env +++ b/infra/env/example.env @@ -216,6 +216,11 @@ TWITCH_CHANNEL= # never is. 06-secrets.sh reads it on the operator box and installs it as a # systemd credential. PASS_KEY=twitch/-key +# The `pass` entries holding the Twitch app client id and secret (names only). +# 06-secrets.sh installs them together as the twitch-app credential; unset means +# it skips twitch-app with a warning. +BRIDGE_ID_KEY=twitch/-client-id +BRIDGE_SECRET_KEY=twitch/-client-secret # --- flybridge (services/bridge/src/config.ts) ------------------------------ # 05-deploy.sh writes these into /etc/fly/fly.env, which flybridge.service reads diff --git a/services/bridge/README.md b/services/bridge/README.md index 7d9d638..8f5c960 100644 --- a/services/bridge/README.md +++ b/services/bridge/README.md @@ -244,7 +244,7 @@ The unit itself lives in `infra/`, not here (W4 in `docs/stream-mvp-plan.md`). W provide: - `LoadCredentialEncrypted=twitch-client-id:...` and `...twitch-client-secret:...`, sourced from - `pass` (`twitch/fly-pokemon-client-{id,secret}`), giving `$CREDENTIALS_DIRECTORY` the two files + `pass` (`twitch/-client-{id,secret}`), giving `$CREDENTIALS_DIRECTORY` the two files `src/config.ts` reads. - A writable, persistent directory for `TOKENS_FILE`, `REDEMPTION_STATE_FILE` and `NOTICE_STATE_FILE` (default `/var/lib/flybridge/`), owned by the service user.