design: console Protection tab (draft for builder check)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+226
−0
docs/superpowers/specs/2026-10-30-console-protection-tab-design.md+226 −0
diff --git a/docs/superpowers/specs/2026-10-30-console-protection-tab-design.md b/docs/superpowers/specs/2026-10-30-console-protection-tab-design.md| new file mode 100644 |
| index 000000000..0089ff9cb |
| --- /dev/null |
| +++ b/docs/superpowers/specs/2026-10-30-console-protection-tab-design.md |
| @@ -0,0 +1,226 @@ |
| +# Console Protection tab: how much bad traffic the edge catches |
| + |
| +Status: draft for Paul, 2026-10-30. Branch `design-console-protection-tab`. |
| + |
| +Builds on the edge request protection design |
| +(`docs/superpowers/specs/2026-10-24-edge-request-protection-design.md`, |
| +"the protection spec" below). Plans 1 (request records, 6e2d9817) and 2 |
| +(hard and probe tiers in watch mode, 96564cf3) are merged and live. |
| + |
| +## 1. What this is for |
| + |
| +Paul, 2026-10-29/30: "I want to know plainly how much bad traffic the WAF is |
| +filtering so that I know it's working!" |
| + |
| +Today the only evidence is `watch probe` lines in an app's Logs tab, mixed |
| +with the app's own lines. Nobody can tell from the console whether |
| +protection is on, how much it caught this week, or what the probes were |
| +after. The per-minute records (`kind=minute`, with `block` and `watch` |
| +counts) exist but nothing adds them up. |
| + |
| +The tab answers one question first: **is protection working on this app, |
| +and how much did it catch?** Everything else on the page supports that |
| +answer. |
| + |
| +Who reads it: |
| +- Paul, as the operator, checking protection works across the flagship. |
| +- An app's owners, checking their app is covered. The framing must |
| + reassure: "we caught these and they reached nothing" rather than "you |
| + are under attack". |
| + |
| +## 2. Goals, non-goals, anti-goals |
| + |
| +Goals: |
| +1. A per-app **Protection** tab in the console showing, for the last 7 days |
| + (30 days on request): how many requests the edge caught, blocked versus |
| + only recorded, the share of all the app's requests that was, and |
| + whether protection is watching or blocking. |
| +2. A breakdown by what the requests were after, in plain words (secret |
| + files, WordPress, PHP admin tools...), from the catalogue's groups. |
| +3. The rate-limit refusals the edge already counts (shed, per-client |
| + ceiling, plan throttle) on the same page, as the other half of "bad |
| + traffic". |
| +4. A platform-wide view for system operators: the same totals across every |
| + app, so Paul can see protection working on the whole flagship at once. |
| +5. A way from any count to the requests behind it (the Logs tab, filtered |
| + to protection records). |
| + |
| +Non-goals (v1): |
| +- Top paths, top client addresses, top countries. The request records in |
| + Logs carry them for 7 days; aggregating them needs top-k sketches and is |
| + a later step. |
| +- Alerts or emails when an app is being probed. |
| +- Any control: turning rules on or off, tenant rules, allow rules, the |
| + under-attack switch. The protection spec puts those on this tab later |
| + (§6.2, §5.6); this design leaves room for them but builds none. |
| +- A CLI command. The tab reads a JSON door, so a `carlos` command can |
| + follow cheaply. |
| + |
| +Anti-goals (a failure even if it works): |
| +- **A number that overstates.** A request counted twice (hub and fleet box, |
| + ingress and backhauled box), or a burst-rule match below its limit |
| + counted as "caught", makes the page lie in the flattering direction. |
| +- **Zero that means "not counting".** A box that does not count yet, or an |
| + app whose traffic was served by such a box, must never read as "nothing |
| + caught". |
| +- **New storage traffic.** No new per-box polling and no new writes per |
| + request or per flush (house rule: S3 requests cost money). |
| +- **A previous owner's traffic.** A host that changed hands shows the new |
| + owner only their own counts, as the rate-limit counts already do. |
| +- **Alarm.** Copy that frightens app owners about routine internet noise. |
| + |
| +## 3. Where the numbers come from |
| + |
| +### 3.1 Counting at the edge |
| + |
| +The edge already writes per-host, per-hour counters every 5 minutes into the |
| +box's usage edge day (`usage.EdgeRow` in |
| +`usage/edge/<box>/days/<date>.json`, `internal/usage/edge.go`), and the |
| +rate-limit refusals ride there today (`RateShed`, `RateCeiling`, |
| +`PlanThrottled`). Protection counts ride the same object, so they add no |
| +request. |
| + |
| +On `usage.EdgeRow` (per host, per hour), additive and `omitempty` like the |
| +hop and rate counters: |
| +- `guard_block`: requests a protection rule blocked. |
| +- `guard_watch`: requests a protection rule matched and let through. |
| + |
| +Both are inside `Requests`, never added to it. They are counted at the |
| +moment the edge files a Match record (`observeRecords`, |
| +`internal/edge/reqrecords.go`), by the same rule, so they are counted |
| +exactly once fleet-wide (the box that answered, not the box that forwarded |
| +over a tunnel). They are counted whether request records are on or off |
| +(`CARLOS_EDGE_RECORDS=off` stops records, not counts). Counts are exact: |
| +unlike records, they are never sampled. |
| + |
| +A burst-mode rule's match counts only when the edge treats it as a watch or |
| +block (the limit was passed), never below its limit. |
| + |
| +Per host, per **day** (not per hour, to keep the object small): the counts |
| +by catalogue group, keyed `<tier>/<group>` (`hard/secrets`, |
| +`probe/wordpress`...), with the same owner label. The catalogue has 16 |
| +groups today. *My call:* the map holds at most 32 keys, and anything past |
| +that counts under `other`, so a future tier cannot grow it without bound. |
| +*My call:* this sits on `usage.EdgeDay` as a host-keyed map beside `hours`, |
| +not on the hourly row, because 24 copies of a group map per host would |
| +multiply the object's size. |
| + |
| +Owner labelling follows `EdgeRow.SetOwner`: when a row or the group map |
| +changes account or app, the protection counters start again from zero, |
| +exactly as the rate-limit counters do. |
| + |
| +Per box, per hour: the protection mode the box was running |
| +(`watch` / `block` / `off` / `catalogue`, from `CARLOS_EDGE_PROTECT`, |
| +`internal/edge/guard.go`), written with every flush. This is how the |
| +console tells "nothing caught" from "not counting": an hour with traffic |
| +for the app but no mode on the box that served it was served by a box that |
| +does not count yet. |
| + |
| +### 3.2 Reading in the console |
| + |
| +The console sums the app's rows (matching account and app, as |
| +`rateLimitCounts` does in `internal/console/apiinstances_ratelimit.go`) |
| +over every box's edge days in the window. |
| + |
| +It reads through the economics sweep's settled-day cache |
| +(`internal/console/usagedays.go`): settled days are read once and kept for |
| +6 hours, and the hourly economics pass already leaves the month's settled |
| +days there, so a Protection view usually reads only today and yesterday. |
| +It must read the same set of boxes the economics sweep reads, including |
| +fleet boxes under their status prefix. *Note:* `rateLimitCounts` reads only |
| +the root `usage/edge/` prefix today. If that misses fleet boxes, fix it in |
| +the same shared reader so both counts agree. |
| + |
| +### 3.3 Request budget |
| + |
| +- Writes: none added. Counters ride the existing 5-minute conditional put. |
| +- Reads: a cold per-app view reads today's and yesterday's edge day for |
| + each metering box (about 2 × boxes GETs). Settled days come from the |
| + cache, which the economics pass fills at no extra cost. The operator view |
| + reads the same objects, since every app's rows are in them. |
| +- Object size: two integers per host-hour with matches, one group map per |
| + host-day, and one mode per box-hour. The builder measures the largest |
| + flagship edge day before and after on a test fixture shaped like it, and |
| + the result must stay well under `usageDayReadCap` and |
| + `usageDayCacheMaxBody` (1 MiB). |
| + |
| +## 4. What the tab shows |
| + |
| +All wording below is indicative. Every string goes through copy review |
| +before it is written into a template (house rule), in the house voice: no |
| +em dashes, plain words, reassuring. |
| + |
| +The tab sits in the app nav between Analytics and Activity, labelled |
| +**Protection**. App members who can see Logs can see it. |
| + |
| +1. **The headline.** One sentence that answers the question. |
| + - Watching: "In the last 7 days, 1,284 requests to this app looked like |
| + attacks. Protection is recording them and letting them through while |
| + we check it never stops a real visitor." |
| + - Blocking: "In the last 7 days, protection blocked 1,284 requests to |
| + this app." |
| + - With the share beside it: "That's 3% of its 41,200 requests." |
| + - Nothing caught: "Nothing in the last 7 days looked like an attack." |
| + - Not counting: "Protection counts started on 4 November." Or, when part |
| + of the window was served by boxes that do not count: "Some of this |
| + app's traffic was served before counting started, so the real number |
| + may be higher." |
| +2. **Day by day.** A bar per day of caught requests, blocked and recorded |
| + shown apart. Plain numbers on hover or beneath. |
| +3. **What they were after.** A short table by catalogue group, largest |
| + first, with a plain name for each group ("Secret files such as .env and |
| + .git", "WordPress logins and admin pages", "PHP admin tools", "Database |
| + dumps"...) and its count. The group names are copy, kept beside the |
| + catalogue so a new group cannot ship without one. |
| +4. **Rate limits.** The rate-limit refusals for the same window: requests |
| + slowed because an instance was busy, requests from one client over the |
| + per-client ceiling, requests slowed by the account's plan. In observe |
| + mode these read as "would have been slowed". |
| +5. **See the requests.** A link to the Logs tab filtered to protection |
| + records. If Logs cannot filter by record kind today, the builder adds |
| + that filter. |
| + |
| +Window: 7 days by default, with a 30-day choice, both ending now. *My |
| +call:* no custom ranges in v1. |
| + |
| +### 4.1 Operator view |
| + |
| +System operators (`CARLOS_SYSTEM_OPERATORS`) get the same headline, |
| +day-by-day bars and group table for every app at once, plus a table of |
| +apps sorted by caught requests (account, app, caught, blocked, share of |
| +its requests). *My call:* it lives as a section of the existing operator |
| +pages (`/fleet/economics` neighbourhood) rather than a new top-level page; |
| +the builder picks the exact spot. It reads the same objects as the per-app |
| +view. |
| + |
| +### 4.2 The JSON door |
| + |
| +The tab renders from one JSON endpoint per app (and one for the operator |
| +view) returning the window's totals, per-day rows, group counts, rate-limit |
| +counts, the modes seen and a `counting_since` / `partial` flag. The page |
| +and any later CLI command read the same answer. |
| + |
| +## 5. Constraints |
| + |
| +- **Provider-neutral.** Everything goes through `release.Store`. No AWS |
| + service is touched beyond the existing store. |
| +- **Census.** The edge day gains fields the agent writes and the console |
| + reads. Run `make census-card`; the reviewer decides the census classes |
| + (AGENTS.md, "The census: the reviewer decides"). |
| +- **Old boxes and old objects.** A day object written before these fields |
| + parses with them zero and no mode, and reads as "not counting". An older |
| + binary reading a new object ignores the new fields. |
| +- **No tenant names** in code, fixtures, copy or docs. |
| +- **Rollout:** dev boxes, dev console, check, flagship boxes, flagship |
| + console. Counts start from the roll, so the tab's first week will show |
| + "counting started on". |
| + |
| +## 6. Left to the builder |
| + |
| +- Field names and the exact JSON shape of the door. |
| +- Where the group plain names live (catalogue file or a console table), as |
| + long as a group without a name fails a test. |
| +- The chart drawing, within the console's existing look (match the |
| + Analytics tab). |
| +- How the Logs filter link is expressed. |
| +- The exact spot of the operator section. |