buzz icon indicating copy to clipboard operation
buzz copied to clipboard

Git: pre-receive hook fails closed on pushes with more than ~20 refs; denial reasons never reach the pusher

Open Zigoljube opened this issue 4 months ago • 1 comments

Git: pre-receive hook fails closed on pushes with more than ~20 refs, and the denial reason never reaches the pusher

Summary

Pushing a real-world repository into Buzz's git hosting is effectively impossible without insider knowledge: any push carrying more than roughly 20 ref updates is atomically rejected with a bare pre-receive hook declined on every ref, and the human-readable denial reasons the policy endpoint computes are never surfaced to the client.

Reproduction

Mirroring OriginTrail/dkg (1,339 heads+tags; 2,898 refs with GitHub's refs/pull/*) into a repo announced via kind 30617 with a valid buzz-channel binding, pushed by the repo owner key (so role = Owner, which evaluate_push should wave through):

Push shape Result
git push --mirror (2,898 refs) every ref ! [remote rejected] … (pre-receive hook declined)
25-ref batches rejected
≤20-ref batches accepted
single refs accepted

Same commit content, same pusher, same repo — only the ref count per push changes the outcome. The relay log shows only:

WARN git receive-pack report-status contains a rejected (ng) ref update
WARN receive-pack exited non-zero (e.g. pre-receive hook decline); skipping CAS publish and kind:30618

— no policy denial is logged and none is transmitted in the sideband, so the pusher cannot distinguish "role denied" from "hook infrastructure gave up".

Likely cause

crates/buzz-relay/src/api/git/policy.rs:

  • MAX_CALLBACK_AGE_SECS = 30 — "Push is synchronous so 30s is generous". The hook computes git merge-base --is-ancestor per ref before POSTing the HMAC-signed callback; with thousands (or even dozens) of refs on a cold ephemeral hydration, the callback timestamp exceeds the TTL by the time it is assembled → fail-closed 403 → every ref denied (push is atomic per evaluate_push).
  • Fail-closed is the right default, but the failure mode here is indistinguishable from a permissions denial.

Suggested fixes (independent, any subset helps)

  1. Surface denial reasons. HookCallbackResponse already carries per-ref reasons; print them to the git sideband (pre-receive stderr is shown to the pusher verbatim) so requires admin role, callback expired, etc. are visible.
  2. Start the TTL clock at callback assembly, or scale it with ref count — the current constant assumes per-push cost is O(1) when it is O(refs).
  3. Batch or skip the per-ref ancestor checks (git merge-base --is-ancestor per ref is the expensive step; for creates from the zero OID it is a constant false and needs no subprocess at all — which is every ref of an initial mirror push).

Environment

Relay at 63496cc1d, macOS host, pushes over HTTPS via Tailscale Serve with git-credential-nostr; observed 2026-08-01.

Zigoljube avatar Aug 01 '26 22:08 Zigoljube

Correction from the reporter, after controlled reproduction — two claims in my original report were wrong, and the real root cause is simpler and more precise:

  1. The threshold is not ~20 refs and the 30s-TTL theory is withdrawn. Probing the same live deployment with batches of newly created tags: 30 refs → accepted, 300 refs → accepted, 2,000 refs → atomically declined. The hook computes its HMAC timestamp after the per-ref loop, so the callback TTL was never the issue. (Our original "≤20 works" observation conflated this with the streamed-POST 401 failure that became #4195.)
  2. Denial reasons DO reach the pusher — the hook cats the policy response to stderr and git relays it as remote: lines. Our original capture truncated them. With full output the 2,000-ref push shows exactly:
    remote: error: push denied by policy (HTTP 403)
    remote: invalid ref_updates count
    

Actual root cause: the policy endpoint hard-caps ref_updates at 500 per push (crates/buzz-relay/src/api/git/policy.rs: req.ref_updates.is_empty() || req.ref_updates.len() > 500 → 403). A reasonable DoS bound — but since a push is atomic and git push --mirror cannot self-batch, mirroring any repository with >500 refs (most real repos, once GitHub's refs/pull/* are included) fails wholesale.

Revised, smaller asks:

  • Make the error self-describing: invalid ref_updates count (max 500 per push — split large pushes into smaller batches). The current message names neither the limit nor the remedy.
  • Document the cap wherever git hosting is documented (it interacts with --mirror in a way nobody will guess).
  • Optionally: consider whether the receive path could chunk internally, since the client-side workaround (batched refspec pushes, ≤500 per invocation) works but is not discoverable.

Apologies for the noise in the original report — the observations were real, the attribution was wrong.

Zigoljube avatar Aug 02 '26 15:08 Zigoljube