Document the demo abuse alert design and activation settings
1 file changed,
+106
−0
docs/superpowers/notes/demo-abuse-alerts.md+106 −0
diff --git a/docs/superpowers/notes/demo-abuse-alerts.md b/docs/superpowers/notes/demo-abuse-alerts.md| new file mode 100644 |
| index 000000000..ceadac888 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/demo-abuse-alerts.md |
| @@ -0,0 +1,106 @@ |
| +# Demo abuse alerts (draft) |
| + |
| +Paul needs operator alerts before opening the flagship demo window. This branch |
| +adds an opt-in console worker; activation and copy review remain with Paul. |
| + |
| +## Findings and choice |
| + |
| +Admission budgets already use SQLite and salted HMAC-SHA256 |
| +(`internal/console/demo_store.go:139`, `:162`). They count charged attempts, |
| +including invalid uploads, rather than successful deployments. IPv6 budgets |
| +already group by /64 (`internal/demo/config.go:151`). There is a rolling daily |
| +budget; there is no separate hourly create budget in this implementation. |
| +Reports and report attempts are local (`internal/console/demo_reports.go:33`). |
| +The Plan 2 report-key cache exception is unchanged. |
| + |
| +The fleet engine has operator scope, not just tenant scope |
| +(`internal/console/alertsignals.go:444`). Its incident step, reminders and |
| +outbox are useful (`alertengine.go:98`, `alertstore.go:366`, `alertnotify.go:41`, |
| +all under `internal/console`). But its pass requires a release store and reads |
| +box objects before evaluating signals (`alertengine_pass.go:124`, `:157`). Its |
| +first notification waits five minutes (`alertengine.go:79`), and its default |
| +recipients are every confirmed fleet connector (`alertengine_pass.go:369`). |
| +Demo managers instead include configured system operators and ops owners |
| +(`internal/console/apisystemupdate.go:144`). Reworking that engine's scheduling, |
| +recipient rules and daily digest is larger than this local alert source. |
| + |
| +Use the existing direct notification path: recipient grants from |
| +`internal/console/alertwatch.go:64`, `Server.sendApp` from `server.go:1248`, and |
| +per-recipient success state from `store.go:2721` and `:2738`. Email uses the |
| +existing console sender (`consolemail.go:209`), with a cached-verified-only |
| +entry point: an alert must never call the identity ensure/verify path, which |
| +can read S3 (`consolemail.go:128`, `:147`). No new S3 read, list or polling. |
| +A missing verified sender or grant leaves delivery retryable and visible in |
| +the worker error. Each pass rechecks the recipient list. |
| + |
| +## Signals and SQL |
| + |
| +All windows exclude future rows. Create windows are rolling; refusal windows |
| +are UTC minute buckets, including the current partial minute. Queries use |
| +parameters, not interpolated operator input. |
| + |
| +| Signal | SQL shape | Default | |
| +| --- | --- | --- | |
| +| Daily budget | `count(*) FROM demo_admissions WHERE attempted_at > ? AND attempted_at <= ?` | count × 100 >= daily budget × 80 | |
| +| Few IP budgets | sum the largest K `count(*) GROUP BY ip_hash` in the create window | 20 attempts from the busiest 3 budgets in 1h | |
| +| One prefix | largest `count(*) GROUP BY prefix_hash`, excluding NULL | 30 attempts in 1h | |
| +| Refusals | `sum(refusals) FROM demo_admission_refusals WHERE minute >= ? AND minute <= ?` | 30 in 10 minute buckets | |
| +| Reports now | `count(*) FROM demo_reports WHERE created_at > ? AND created_at <= ?` | more than 5 in a rolling hour | |
| +| Report digest | count reports after this recipient's last successful digest cutoff | once per UTC day, if any arrived | |
| + |
| +Prefix hashes use the admission salt and HMAC-SHA256 over the masked IPv4 /24 |
| +or IPv6 /48 string. /48 catches rotation across the /64 budgets inside a common |
| +site allocation; it is a concentration hint, not proof of one person. |
| +Old admission rows have NULL prefixes until they expire. No raw address is |
| +added. Prefixes disappear with their admission rows after 24h. Refusals store |
| +only bounded minute counters, pruned after 24h, including during quiet periods. |
| +Existing app abuse metadata and its retention are unchanged. |
| + |
| +A persistent firing bit per recipient prevents repeated mail while a condition |
| +stays true. A quiet observation rearms it without sending a clear. Failed sends |
| +retry on later passes; a crash after mail acceptance but before recording |
| +success can duplicate mail. No reminders are added. Digests retain a cutoff |
| +per recipient, so failed sends and midnight do not lose reports. The first |
| +digest covers the preceding 24h; later digests cover surviving reports since |
| +the previous successful cutoff. Resolved reports still count as arrivals. |
| + |
| +## Operator settings |
| + |
| +Use console environment/drop-in settings, followed by a console restart. This |
| +is the brief's permitted fallback: existing demo limits already use environment |
| +settings (`internal/demo/config.go:35`), while the operator API currently edits |
| +only serving (`internal/console/apidemooperator.go:20`). It avoids adding a new |
| +CLI command and root-binary census changes for this first demo window. |
| + |
| +Every name below starts with `CONSOLE_DEMO_ALERT_`: |
| + |
| +| Suffix | Default | Meaning | |
| +| --- | --- | --- | |
| +| `ENABLED` | `false` | explicit opt-in; off means no signals or delivery | |
| +| `BUDGET_PERCENT` | `80` | integer 1 through 100 | |
| +| `IP_COUNT`, `FEW_IPS` | `20`, `3` | attempts across the busiest K IP budgets | |
| +| `PREFIX_COUNT`, `CREATE_WINDOW` | `30`, `1h` | attempts per /24 or /48 | |
| +| `REFUSAL_COUNT`, `REFUSAL_WINDOW` | `30`, `10m` | refusal spike | |
| +| `REPORTS_PER_HOUR` | `5` | send when the count exceeds N; zero means any report | |
| +| `DIGEST` | `true` | daily report digest, still gated by ENABLED | |
| + |
| +Counts are bounded positive integers except REPORTS_PER_HOUR, which permits |
| +zero. Windows must be whole minutes from 1m through 24h. Invalid settings fail |
| +startup. To enable, set ENABLED=true, configure CARLOS_SYSTEM_OPERATORS (ops |
| +owners also receive notices), and use an already verified console mail sender |
| +or the operator's existing Keymail grant. Settings do not change demo limits. |
| + |
| +The worker runs once a minute while enabled, including when serving is off. |
| +Immediate reports therefore arrive on the next pass rather than waiting for |
| +the digest. Costs are a handful of indexed SQLite aggregates per minute, |
| +local counter writes on refused admissions, and mail only on transitions or |
| +nonempty digests. Alert text contains aggregate counts, never IP hashes, |
| +report details, demo names or claim tokens. |
| + |
| +## Open questions before activation |
| + |
| +- Paul edits the draft strings in `internal/console/demo_alert_copy.go`. |
| +- Confirm recipients, verified email readiness, thresholds and the switch-on |
| + date for the flagship demo window. This branch does not activate anything. |
| +- Environment settings require a restart. If live tuning becomes routine, |
| + extend the demo operator API and CLI in a later reviewed change. |