Skip to content

docs(labeler): operator guide, ATProto reference, and keygen script - #2031

Merged
ascorbic merged 2 commits into
feat/plugin-registry-labelling-servicefrom
docs/labeler-operator-guide
Jul 14, 2026
Merged

ascorbic merged 2 commits into
feat/plugin-registry-labelling-servicefrom
docs/labeler-operator-guide

Conversation

@ascorbic

@ascorbic ascorbic commented Jul 14, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Adds the labeler service's first documentation set, plus a keygen helper script.

Four Markdown files under apps/labeler/:

  • README.md — overview, how the pieces fit together, local-dev scripts, a numbered deploy checklist (Access app + AUD tag → keypair → migrations → deploy), and a config reference table (vars vs secrets).
  • docs/atproto.md — ATProto foundations for anyone consuming the labeler or working on it: decentralized identity and DIDs, did:web vs did:plc and why a labeler picks did:web, the actual DID-document shape served at /.well-known/did.json, the label and subject model, P-256 signing and boot-time key validation, the XRPC surface, Jetstream ingestion, and the end-to-end consumer trust chain.
  • docs/operating.md — operator console guide: Cloudflare Access sign-in, the reviewer/admin capability split, and each workflow (review/issue/retract, rerun, false-positive override + override-retract, emergency ceremonies, the automation kill-switch, the dead-letter queue, and the audit log).
  • docs/moderation-model.md — the full label vocabulary (all 23 labels with effect / subject / cidRule / issuer), the public policy URL and current policyVersion, eligibility evaluation and its precedence order, the §10 rule, and the no-cascade rule.

The keygen script (apps/labeler/scripts/keygen.mjs, wired as pnpm --filter @emdash-cms/labeler keygen) generates a P-256 signing keypair in the exact formats the Worker validates on boot: the private key as unpadded base64url of the raw 32-byte scalar (LABEL_SIGNING_PRIVATE_KEY) and the public key as a canonical P-256 Multikey (LABEL_SIGNING_PUBLIC_KEY). Verified: the private value round-trips to 32 bytes and reimporting it re-derives the same public Multikey. Adds @atcute/multibase as a devDependency (the script needs toBase64Url).

Every emdash-specific claim in the docs was checked against the merged source (identity.ts, index.ts, xrpc-router.ts, the eligibility evaluator in registry-moderation, wrangler.jsonc, and the policy fixture).

Closes #

Type of change

  • Documentation
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (if applicable)
  • I have added a changeset (if this PR changes a published package)
  • New features link to an approved Discussion

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Opus 4.8 (drafted), reviewed against source by Claude Opus 4.8

Screenshots / test output

pnpm --filter @emdash-cms/labeler keygen prints the two values in the documented formats; the private key round-trips to 32 bytes and reimport re-derives the same public Multikey.


Try this PR

Open a fresh playground →

A full working EmDash site, deployed from this branch. Each visit gets its own session-scoped sandbox: no login needed and no shared state. Try the admin, edit content, hit the public site.

Tracks docs/labeler-operator-guide. Updated automatically when the playground redeploys.

Add developer and operator documentation for the labeler service:
README (overview, local dev, deploy checklist, config reference),
docs/atproto.md (DIDs, did:web, the DID document, labels, signing,
XRPC surface), docs/operating.md (console roles and workflows), and
docs/moderation-model.md (label vocabulary and eligibility evaluation).

Add a `keygen` script that generates a P-256 signing keypair in the
exact formats the Worker validates on boot: the private key as unpadded
base64url of the raw 32-byte scalar and the public key as a canonical
P-256 Multikey.

Claude-Session: https://claude.ai/code/session_014rikrGMh25h1rJczUQyTMM
@changeset-bot

changeset-bot Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: e01a842

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions Bot added review/needs-review No maintainer or bot review yet size/L cla: signed labels Jul 14, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-do e01a842 Jul 14 2026, 06:57 AM

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach judgment: This is a documentation + small tooling PR (four Markdown docs under apps/labeler/, plus a keygen script and its @atcute/multibase devDep). It's the right kind of change for this branch — documenting an already-merged labeler service and adding a keypair helper for the deploy workflow. No published package changes (@emdash-cms/labeler is private), so no changeset is needed; no admin-UI strings are touched, so the Lingui/RTL conventions don't apply. The approach is sound.

What I verified:

  • keygen.mjs API usage — P256PrivateKeyExportable.createKeypair(), exportPrivateKey("raw"), exportPublicKey("multikey"), and toBase64Url from @atcute/multibase are exactly the APIs the aggregator tests (apps/aggregator/test/labels-consumer.test.ts, label-ingestor.test.ts, etc.) already use, so the imports are real and the formats are correct.
  • Private-key format — toBase64Url(exportPrivateKey("raw")) produces canonical unpadded base64url of the 32-byte scalar, which is precisely what importPrivateScalar in packages/registry-moderation/src/index.ts validates (BASE64URL regex, 32 bytes, toBase64Url(bytes) === value, scalar in range). Round-trips.
  • Public-key format — exportPublicKey("multikey") is canonical, matching validatePublicMultikey in apps/labeler/src/config.ts (which re-exports and requires equality). The keygen output will pass boot-time config validation.
  • Docs vs. source — checked the DID-document shape and content-type (identity.ts), the XRPC surface and createReport → NotSupported (index.ts), subscribeLabels cursor rules, the 300s policy cache, Cloudflare Access RS256/issuer/audience/exp verification and admin-inherits-reviewer (access-auth.ts), the emergency intent phrases (console-mutation-api.ts EMERGENCY_INTENT: CONFIRM TAKEDOWN/CONFIRM COMPROMISE/CONFIRM RETRACT), X-EmDash-Request: 1 CSRF (mutation-guard.ts), whoami, NO_ACTIVE_LABEL → 404, the dead-letter status='new' single-flip resolve, and the automation kill-switch gating only ingestion (automation-state.ts). All match.
  • moderation-model.md — all 23 labels, categories, effects, cidRules, issuance modes, policyVersion (2026-07-10.experimental.3), the override rule, and the precedence order match the fixtures/moderation-policy.json fixture and the evaluateReleaseModerationCore evaluator exactly.

Headline conclusion: The docs are unusually accurate against the source. One substantive inaccuracy: the "validates on boot / fails the deploy / refuses to start" keypair-mismatch guarantee is repeated in three places but does not match the code — the private↔public-key match check is lazy (run only when a signer is constructed, i.e. on the first signing operation such as a discovery batch, a queryLabels re-sign, or a console mutation), not at boot or deploy time. wrangler deploy only enforces that the LABEL_SIGNING_PRIVATE_KEY secret exists; it does not check it matches the public key. An operator could deploy a mismatched pair and not learn of it until the first sign operation. Worth fixing the wording; not a code break, so comment rather than request_changes.

Comment thread apps/labeler/README.md Outdated

## Deploying

The Worker validates on boot that its signing keypair matches the public key published in its DID document, so a copy error fails the deploy rather than shipping a labeler whose signatures cannot be verified. Work through the checklist in order.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[needs fixing] This sentence (and the same claim repeated in docs/atproto.md:82 and scripts/keygen.mjs:11-12) states the Worker "validates on boot that its signing keypair matches the public key" and that a mismatch "fails the deploy" / the Worker "refuses to start." That does not match the code.

The keypair-match check lives in createLabelSigner (packages/registry-moderation/src/index.ts), which compares key.exportPublicKey("multikey") against the resolved #atproto_label key. It is only invoked via createRuntimeSigner, and the labeler calls that lazily — inside queryLabels (only when there are stale labels to re-sign), inside console mutations that sign, and inside createProductionDiscoveryDeps when a discovery batch is processed (discovery-consumer.ts:~511). Nothing runs it at module load, in a DO constructor, or in the scheduled handler. getLabelerIdentityConfig (run per request) validates only the public key's format/canonicity, not that the private key matches it. The only deploy-time guarantee is the unrelated required: ["LABEL_SIGNING_PRIVATE_KEY"] in wrangler.jsonc, which makes wrangler deploy refuse only if the secret is unset — not if it mismatches the public key.

So a freshly deployed Worker with a mismatched pair boots fine, serves /.well-known/did.json and the policy, and only throws when the first signing operation runs. The docs' safety guarantee ("a copy error fails the deploy rather than shipping a labeler whose signatures cannot be verified") is therefore overstated and could lead an operator to assume a successful deploy means the pair is consistent — exactly the scenario a key-rotation runbook needs to get right.

Suggested change
The Worker validates on boot that its signing keypair matches the public key published in its DID document, so a copy error fails the deploy rather than shipping a labeler whose signatures cannot be verified. Work through the checklist in order.
The Worker checks, when it first builds a signer (the first label it signs or re-signs — e.g. a discovery batch, a `queryLabels` re-sign, or a console mutation), that the configured private key derives the public key published in its DID document; a mismatch throws at that point. This is separate from the deploy-time required-secret check: `wrangler deploy` only refuses if `LABEL_SIGNING_PRIVATE_KEY` has not been set — it does not verify the pair matches, so confirm the values yourself when rotating. Work through the checklist in order.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-playground e01a842 Jul 14 2026, 06:57 AM

@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond and removed review/needs-review No maintainer or bot review yet labels Jul 14, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-cache e01a842 Jul 14 2026, 06:56 AM

The keypair mismatch check runs lazily when the signer is first
constructed (the first signing operation), not at boot or deploy.
`wrangler deploy` only enforces that the private-key secret exists.
Reword the README, atproto doc, and keygen comment so operators know a
mismatched pair deploys cleanly and fails on the first sign, and to
exercise a signing path after setting or rotating the key.

Claude-Session: https://claude.ai/code/session_014rikrGMh25h1rJczUQyTMM
@github-actions github-actions Bot added review/needs-rereview New commits since the last review and removed review/awaiting-author Reviewed; waiting on the author to respond labels Jul 14, 2026
@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Jul 14, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review. This is a documentation + small tooling PR for the (already-merged) labeler service: four Markdown files under apps/labeler/, a keygen script, and the @atcute/multibase devDep. The approach is sound — documenting existing behavior and adding a keypair helper for the deploy workflow; no published package changes (so no changeset), no admin-UI strings touched (so Lingui/RTL don't apply). Nothing here is a new feature needing an approved Discussion.

Prior finding — resolved. My previous review flagged a substantive inaccuracy: the "validates on boot / fails the deploy / refuses to start" keypair-mismatch guarantee was stated in three places but did not match the code — the private↔public match is checked lazily inside createLabelSigner (run only when a signer is constructed), not at boot or deploy. The author has corrected all three locations:

  • README.md (Deploying section): "The Worker checks that its signing keypair matches the public key … the first time it signs a label — not at deploy time. wrangler deploy only enforces that the LABEL_SIGNING_PRIVATE_KEY secret exists, so a mismatched pair deploys cleanly and then fails on the first signing operation."
  • docs/atproto.md (Signing): "The Worker checks that the configured private key derives the public key … when it constructs its signer — which happens lazily, on the first signing operation, not at boot or deploy."
  • scripts/keygen.mjs (header comment): "The Worker verifies the pair the first time it signs (not at deploy), so a mismatch surfaces as a failed signing operation rather than at boot."

I re-verified the corrected wording against the source: createLabelSigner (packages/registry-moderation/src/index.ts) is the only place the keypair is matched (key.exportPublicKey("multikey") !== resolved.exportPublicKey("multikey")), and it's reached via createRuntimeSigner (signing-runtime.ts), which is called lazily — as a factory for queryLabels (index.ts), as createSigner: async () => … for console mutations, and inside createProductionDiscoveryDeps for discovery. So the lazy description is now accurate.

What else I verified (no regressions):

  • keygen.mjs API usage — P256PrivateKeyExportable.createKeypair(), exportPrivateKey("raw") wrapped with toBase64Url, and exportPublicKey("multikey") are exactly what apps/aggregator/test/label-ingestor.test.ts and labels-consumer.test.ts use; imports are real.
  • Catalog / lockfile — @atcute/multibase (^1.2.0) and @atcute/crypto (^2.4.1) are both in pnpm-workspace.yaml's catalog, and @atcute/multibase is added to apps/labeler/package.json devDeps with a matching pnpm-lock.yaml entry.
  • Private-key format — importPrivateScalar validates BASE64URL regex, 32 bytes, toBase64Url(bytes) === value, and scalar-in-range; the keygen output satisfies this.
  • Public-key format — validatePublicMultikey in config.ts requires canonical equality to the re-exported Multikey; the keygen output satisfies this.
  • wrangler.jsonc — LABEL_SIGNING_PRIVATE_KEY is declared under secrets.required, so wrangler deploy does validate the secret exists (just not that it matches the public key) — consistent with the README's wording.
  • moderation-model.md — policyVersion 2026-07-10.experimental.3 and the precedence array (manual-block → label-state-collision → assessment-error → assessment-pending → automated-block → missing-assessment-pass → eligible) match fixtures/moderation-policy.json; the 23 labels and their effect/cidRule/issuer columns match the fixture (spot-checked !takedown, security-yanked, publisher-compromised, package-disputed, assessment-overridden).

Headline conclusion: The prior inaccuracy is fixed, the fix is accurate, and the rest of the docs/script remain correct against the source. No new findings. Clean to merge.

@github-actions github-actions Bot added review/approved Approved; no new commits since and removed review/needs-rereview New commits since the last review labels Jul 14, 2026
@ascorbic
ascorbic merged commit 2881e37 into feat/plugin-registry-labelling-service Jul 14, 2026
10 checks passed
@ascorbic
ascorbic deleted the docs/labeler-operator-guide branch July 14, 2026 20:15
@ascorbic ascorbic mentioned this pull request Jul 14, 2026
60 of 81 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:review Trigger an emdashbot code review on this PR cla: signed review/approved Approved; no new commits since size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant