Repository navigation
feat(relay): forge-v2 webhooks with chain-encrypted secrets - #27
Merged
Merged
Conversation
forge-core gains envelope (Platform's encryptedFor ecdh-secp256k1-aes256-cbc via platform-encryption, known-answer tested), an SDK-free identity key view, and webhooks (the forge-collab webhook document: newest per (repoId, hookId), maintainer-signed create/remove, relay-side secret decryption with key and length checks). dg webhook add/list/remove writes them. forge-relay is rewritten for forge-v2: it discovers hooks addressed to its identity through the relay index, requires the writer to still be a maintainer, decrypts secrets in memory, and polls each repo's refUpdate/protectedRefUpdate, release, issue, patch, event/authorEvent, comment, review and checkRun streams. New release and pull_request_review payloads. The SSRF guard now uses reqwest's own URL parser, refuses userinfo and NAT64/multicast/reserved ranges; delivery is bounded per host with a body cap. v1 registry lookups and the plaintext secrets map are gone. Dockerfiles plus a release job that publishes ghcr.io forge-relay images. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Delivery no longer blocks polling: per-hook workers with bounded queues, a circuit breaker with exponential cool-down, per-destination-IP pools and a per-repo time budget per cycle. Stream cursors are (createdAt, seen ids) instead of a start_after id, so a deleted comment or review no longer kills its stream. Pushes are reported only when the update moves its ref by the protected-ref rule (rules::is_update_valid, now public); the CI example verifies the folded ref tip (repo::read_ref_state). Late-appearing repos start no earlier than the relay's start and resume where they stopped. Secrets must be 32..=96 printable ASCII bytes, checked on add and on decrypt (the real wrong-key check). dg webhook add refuses URLs with a query or userinfo unless --force; logs show scheme and host only. The relay loads a minimal ENCRYPTION-key file. Merges are merged:true only when the oid was a valid base-ref tip. Open PR heads seed and bound check_run streams; thread streams are limited to open or recently active targets. webhook remove writes its tombstone first, addressed to the remover. The image push job needs publish and the release environment; archives are checksummed before imaging; base images are pinned by digest and protoc is sha256-checked. Signing moved to forge_core::webhooks. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Polls are never cancelled mid-stream: the hard per-repo timeout is gone, the deadline is checked between streams, and a stream's cursor is saved only after its events are enqueued. Merges are checked against a per-repo set of valid tips per base ref (backfilled once at init, fed by the ref streams) and require baseRefNameHash to match baseRefName. Discovery and repo setup run in their own task with timeouts; repos are polled concurrently (8 at once), skipping one whose last poll is still running. Check-run heads carry their own baseline, so a restart or a re-pushed oid never replays old runs; only recently opened PRs are seeded. A repo coming back resumes no earlier than its hook, and streams only some hooks want start no earlier than those hooks. Config is read after the ref streams and a failed config read defers judging. Threads beyond the priority set are read in rotation. Delivery takes a slot per attempt (2 per address and host under 8 per address), releases it during backoff, and a slot wait does not trip the breaker; removed hooks drop their queues. Secrets are wiped on drop and the relay warns about key files holding more than ENCRYPTION keys. The CI example checks that a valid update set the ref to the pushed oid. INSTALL.md documents the two release approvals. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A new repo is published to the poller only after the dispatcher knows its hooks and its wants are set, under one lock, and enqueue logs once per repo if a served repo has no hook. The event feed is skipped in a cycle whose ref streams or config could not be read, so merges are never judged against stale tips. With a Tail baseline, init_repo primes the config, issue and PR cursors from the reads that built its state (and the ref cursors from their newest page), so nothing written between setup and the first poll is lost. A poll resumes at the stage (repo streams, threads, check runs) where its deadline stopped it, and the thread rotation advances only by the threads read. Merge tips are tracked only for PR base refs, backfilled per refNameHash. Pruned heads drop their checkRun cursors. A slot timeout now fails only that attempt; the shared-CDN-address limit is documented. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…racts Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Warning Review limit reachedNext included review available in 6 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (31)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This was referenced Sep 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR rewrites forge-relay for forge-v2: it turns on-chain activity into GitHub-shaped webhooks, signed with an HMAC secret that is stored encrypted on chain. It is part 1 of 3 of PR G. The others are import/migrate, then the GitHub Mirror Action.
dg webhook add|list|remove. This writes awebhookdocument holding the URL, the events, and the HMAC secret. The secret is encrypted to the relay identity's ENCRYPTION key usingecdh-secp256k1-aes256-cbc(forge_core::envelope, via theplatform-encryptioncrate) and recorded withencryptedFor.forge_core::webhooksholds the shared document codec.refUpdate,protectedRefUpdate, config, issues, patches, comments, reviews, events, releases and check runs.push,issues,pull_request,issue_comment,pull_request_review,release,check_run) withX-Hub-Signature-256.--allow-privateis passed.DEAD-LETTER.merged: falsewithdash_merge_unverified: true.Zeroizingbuffers and never logged.crates/forge-relay/Dockerfilebuilds from source.Dockerfile.releaseis used byrelease.yml, whose newrelay-image/relay-image-pushjobs publishghcr.io/pastapastapasta/forge-relay.releaseenvironment and afterpublish.docs/INSTALL.mdand the relay README cover running it.Three independent security reviews were run. All High and Medium findings are fixed; the remaining items are listed under Gaps.
Live verification (devnet moutai, re-registered contracts from #25)
relay-e2e(3HKxeeGrJjfVP6msx7yEKUPp9ghev2sAPFHEFLQ1c1x1) under the test OWNER identity.dg webhook add --events push --secret-env. The webhook document was accepted with the secret encrypted to RELAY key 4.forge-relay run --allow-privatewith an ENCRYPTION-only key file against a local receiver that checks the HMAC.event=push,hmac_valid=true, and responded 200 on the first attempt. That was 2.9 s after therefUpdate's$createdAt.dg webhook remove. The relay dropped the repo on its next refresh, and a second push produced no delivery.Gates
cargo fmt --check,cargo clippy --workspace --all-targets -D warnings,cargo test --workspace, and actionlint onrelease.ymlall pass.Gaps
DEAD-LETTERlog line).dg webhook removepath that writes a tombstone over another maintainer's still-current hook was not tested live.check_runupdated in place (queued → completed) is not observed; only creations are.🤖 Generated with Claude Code