pi-cloudflare 0.7.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-cloudflare",
3
- "version": "0.7.0",
3
+ "version": "0.8.1",
4
4
  "description": "Cloudflare Agent Plugin and native Pi extension providing official skills and cf_-prefixed MCP tools.",
5
5
  "keywords": [
6
6
  "agent-plugin",
package/plugin.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
3
3
  "name": "pi-cloudflare",
4
- "version": "0.7.0",
4
+ "version": "0.8.1",
5
5
  "description": "Cloudflare skills and cf_-prefixed MCP tools, with a native Pi adapter and an Agent Plugins 1.0 portable runtime.",
6
6
  "author": {
7
7
  "name": "0xPlayerOne",
@@ -103,6 +103,53 @@ PUT /zones/:zone_id/bot_management
103
103
  edge, injects no script, and costs nothing. Prefer it when the user wants bot
104
104
  protection without the performance hit.
105
105
 
106
+ ## Workers
107
+
108
+ Inventory scripts, then check each one's settings:
109
+
110
+ ```bash
111
+ GET /accounts/:account_id/workers/scripts
112
+ GET /accounts/:account_id/workers/scripts/:script/settings
113
+ ```
114
+
115
+ Three things to check per script:
116
+
117
+ - **`observability.enabled`** — free, and off by default in some deploy paths.
118
+ Workers with it off produce no logs when something breaks, so treat an estate
119
+ with mixed states as a gap and align it.
120
+ - **`compatibility_date`** — anything more than a few months old is worth
121
+ flagging; stale dates silently gate new runtime behaviour.
122
+ - **`bindings`** — confirm the script has what it needs and nothing orphaned.
123
+
124
+ Two traps on this endpoint:
125
+
126
+ - **`PATCH` requires `multipart/form-data`, not JSON.** A JSON body fails with
127
+ `Content-Type must be one of: multipart/form-data`. Send the settings as a
128
+ `settings` part:
129
+
130
+ ```js
131
+ const fd = new FormData()
132
+ fd.append('settings', new Blob([JSON.stringify({
133
+ observability: { enabled: true, head_sampling_rate: 1 },
134
+ })], { type: 'application/json' }))
135
+ fetch(`.../workers/scripts/:script/settings`, { method: 'PATCH', headers, body: fd })
136
+ ```
137
+
138
+ - **`GET /accounts/:id/workers/domains` ignores the `worker_name` filter** and
139
+ returns every custom domain on the account. Do not conclude that several
140
+ workers share one hostname from that response — map hostnames by the `service`
141
+ field, or query without a filter and group client-side.
142
+
143
+ Custom-domain mapping (the clean way):
144
+
145
+ ```bash
146
+ GET /accounts/:account_id/workers/domains
147
+ # each entry: { hostname, service } — service is the worker name
148
+ ```
149
+
150
+ A preview worker should have **no** custom domain; if it does, that is worth
151
+ reporting. Preview URLs should sit behind an Access app.
152
+
106
153
  ## Free managed WAF ruleset
107
154
 
108
155
  The managed ruleset object **already exists** on every zone but is not applied —
@@ -234,10 +281,33 @@ The response carries the record to hand the user:
234
281
  <zone>. 3600 IN DS <key_tag> <algorithm> <digest_type> <digest>
235
282
  ```
236
283
 
237
- **There is no API to publish the DS.** Confirmed by searching Cloudflare's
238
- published OpenAPI spec for `dnssec`/`ds_record` in every registrar section (no
239
- matches) and by writing to the registrar endpoint, which returns `200` and
240
- ignores the field. The user finishes this in the dashboard or at their registrar.
284
+ **There is no API to publish the DS** — and this matters more than it looks,
285
+ because it splits by registrar:
286
+
287
+ - **Domain registered with Cloudflare Registrar:** the dashboard's
288
+ **Enable DNSSEC** button publishes the DS to the registry automatically
289
+ ("one-click DNSSEC"). An API enablement does **not** trigger that registrar
290
+ sync, so a zone enabled over the API can sit at `pending` for days even though
291
+ everything else is correct. The fix is a dashboard visit: toggle DNSSEC off and
292
+ back on in **DNS → Settings**, which re-runs the flow that publishes the DS.
293
+ Verified externally by the `ad` flag — a `pending` zone answers without it,
294
+ an `active` zone answers with it.
295
+ - **Domain registered elsewhere:** add the DS record at that registrar. The zone
296
+ publishes CDS/CDNSKEY, so a registrar that supports RFC 8078 can pick it up
297
+ automatically.
298
+
299
+ Either way the API cannot do the last step: the new
300
+ `/accounts/:id/registrar/registrations/:domain` update endpoint documents
301
+ "currently supports updating `auto_renew` only", `?include=dnssec` is accepted
302
+ and returns nothing, and the dashboard serves a bot challenge to headless
303
+ browsers. Do not promise the user a fully automated DNSSEC rollout.
304
+
305
+ Confirm the outcome from outside rather than from the API — the zone will read
306
+ `active` or `pending` regardless, so the registry is the source of truth:
307
+
308
+ ```bash
309
+ dig +dnssec <zone> @1.1.1.1 | grep -o "ad" # ad flag = validating end to end
310
+ ```
241
311
 
242
312
  ## Turnstile
243
313
 
@@ -121,6 +121,9 @@ const RULESET_PHASES = [
121
121
  'http_request_firewall_custom',
122
122
  ]
123
123
 
124
+ // A compatibility date older than this means new runtime behaviour is gated off.
125
+ const COMPAT_CUTOFF = '2024-06-01'
126
+
124
127
  // Headers we expect on a hardened content response. HSTS is handled separately
125
128
  // because enabling includeSubDomains needs care and sign-off.
126
129
  const EXPECTED_HEADERS = ['x-content-type-options', 'referrer-policy']
@@ -330,6 +333,62 @@ async function auditAccount(account) {
330
333
  return summary
331
334
  }
332
335
 
336
+ /**
337
+ * Workers inventory: observability, compatibility date, and custom-domain
338
+ * mapping. Note the domains endpoint ignores worker_name filters, so hostnames
339
+ * are grouped by their `service` field rather than trusted from a per-worker
340
+ * query.
341
+ */
342
+ async function auditWorkers(account) {
343
+ const accountStart = findings.length
344
+ const summary = { observabilityOff: [], staleCompat: [] }
345
+
346
+ const scripts = await get(`/accounts/${account.id}/workers/scripts`)
347
+ if (scripts.error) {
348
+ add(account.name, 'blocked', 'workers', scripts.error, 'grant Workers Scripts read')
349
+ summary.findings = findings.slice(accountStart)
350
+ return summary
351
+ }
352
+
353
+ const names = (scripts.result ?? []).map((s) => s.id ?? s.name)
354
+ summary.workers = names
355
+
356
+ for (const name of names) {
357
+ const settings = await get(`/accounts/${account.id}/workers/scripts/${name}/settings`)
358
+ if (settings.error) continue
359
+ const r = settings.result ?? {}
360
+
361
+ if (r.observability?.enabled !== true) {
362
+ summary.observabilityOff.push(name)
363
+ add(
364
+ account.name,
365
+ 'medium',
366
+ `worker ${name}`,
367
+ 'observability is OFF — no logs when it breaks',
368
+ 'PATCH settings with observability enabled (multipart/form-data, not JSON)'
369
+ )
370
+ }
371
+
372
+ const compat = r.compatibility_date
373
+ if (compat && compat < COMPAT_CUTOFF) {
374
+ summary.staleCompat.push(`${name} (${compat})`)
375
+ add(account.name, 'info', `worker ${name}`, `compatibility_date ${compat} is stale`, 'update to gate in newer runtime behaviour')
376
+ }
377
+ }
378
+
379
+ const domains = await get(`/accounts/${account.id}/workers/domains`)
380
+ if (Array.isArray(domains.result)) {
381
+ summary.customDomains = domains.result.map((d) => ({ hostname: d.hostname, service: d.service }))
382
+ const previewish = summary.customDomains.filter((d) => /preview|staging|dev\b/i.test(d.hostname))
383
+ if (previewish.length === 0 && names.some((n) => /preview|staging/i.test(n))) {
384
+ add(account.name, 'info', 'preview workers', 'no custom domain attached', 'correct by design; preview URLs should sit behind Access')
385
+ }
386
+ }
387
+
388
+ summary.findings = findings.slice(accountStart)
389
+ return summary
390
+ }
391
+
333
392
  // --- main ---
334
393
 
335
394
  const accountsRes = await get('/accounts?per_page=50')
@@ -357,7 +416,11 @@ const auditedZones = []
357
416
  for (const zone of zones) auditedZones.push(await auditZone(zone))
358
417
 
359
418
  const auditedAccounts = []
360
- for (const account of accounts) auditedAccounts.push(await auditAccount(account))
419
+ for (const account of accounts) {
420
+ const summary = await auditAccount(account)
421
+ summary.workers = await auditWorkers(account)
422
+ auditedAccounts.push(summary)
423
+ }
361
424
 
362
425
  const report = {
363
426
  generatedAt: new Date().toISOString(),