Skip to content

fix(git): let webhook URLs use their own origin - #704

Merged
pikann merged 3 commits into
Paca-AI:masterfrom
siedlegroup:fix/git-webhook-public-url
Nov 5, 2026
Merged

pikann merged 3 commits into
Paca-AI:masterfrom
siedlegroup:fix/git-webhook-public-url

Conversation

@kayahk

@kayahk kayahk commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #703.

Problem

A deployment whose public edge forwards only the browser and setup paths cannot receive Git webhooks. PUBLIC_URL is the one origin for everything — the setup CallbackURL, browser links, comment footers, the access-grant callback and the passkey relying party — so it cannot be pointed at a webhook-only host.

Approach

Add GIT_WEBHOOK_PUBLIC_URL (chart: gitWebhookPublicUrl) as an override for only the origin webhook URLs are built from:

  • ServerConfig.WebhookPublicURL ← GIT_WEBHOOK_PUBLIC_URL, empty by default.
  • gitsvc.Service.WithWebhookBaseURL + webhookOrigin(), which falls back to publicURL.
  • Used in setup.go (provider WebhookURL) and repo_webhooks.go (per-repository hooks). CallbackURL, links and the passkey RP stay on PUBLIC_URL.
  • Chart: API env, values.yaml, values.schema.json, README; Compose, .env.example, installer .env and the deploy docs.

Providers receive the URL through the SPI fields that already exist (CallbackURL and WebhookURL are separate), so the plugins need no change.

Testing

  • New TestBeginIdentitySetup_WebhookOriginCanDifferFromTheBrowserOrigin: asserts the provider gets the override origin for WebhookURL, keeps PUBLIC_URL for CallbackURL, that the reserved endpoint key matches the published URL, and that a return URL on the webhook origin is still refused.
  • TestRepoWebhook_RegisteredOnLinkAndRemovedWithTheLastLink now sets the override and asserts the registered hook uses it.
  • Sabotage run: with webhookOrigin() returning publicURL, both tests fail with the wrong origin (webhook url = "https://paca.example.com/api/v1/git/webhooks/…", want "https://hooks.example.com/…"; ensure webhook = [{… URL:https://paca.example.com/api/v1/git/webhooks/key1}]). Restored → green.
  • go build ./..., go vet, go test ./internal/service/git ./internal/config, git diff --check clean. helm template -s templates/api/deployment.yaml renders GIT_WEBHOOK_PUBLIC_URL: "" by default and the value with --set; the schema still type-checks it. bash -n scripts/install.sh clean.

Migration note

Existing webhooks are not rewritten: an App's hook URL lives in its GitHub settings and is set from the manifest, and re-registering a PAT repository hook PATCHes only a hook whose config.url already matches (otherwise it POSTs a new one and the stale hook stays). After changing the value, edit each App or unlink/relink each repository, then remove the old hooks. Documented in deploy/README.md.

Not covered

No live provider setup or delivery was exercised; golangci-lint is not installed in my environment, so it was not run.

A public edge that forwards only the browser and setup paths cannot serve
/api/v1/git/webhooks, and PUBLIC_URL cannot say otherwise without moving the
setup callback, browser links and the passkey relying party with it.

GIT_WEBHOOK_PUBLIC_URL (chart: gitWebhookPublicUrl) overrides only the origin
webhook URLs are built from; unset keeps PUBLIC_URL.
The installer writes the .env a later `docker compose` restart reads, so a
GIT_WEBHOOK_PUBLIC_URL exported only for that one run would be lost and the
webhook origin would silently fall back to PUBLIC_URL.

Also state in the deploy docs that existing webhooks are not moved.

@pullfrog pullfrog 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.

ℹ️ No critical issues — minor documentation and operational notes below.

Reviewed changes

  • Webhook origin override in core — ServerConfig.WebhookPublicURL reads GIT_WEBHOOK_PUBLIC_URL; Service.WithWebhookBaseURL stores it and webhookOrigin() falls back to publicURL, so BeginIdentitySetup and per-repository webhookURL build on the override while CallbackURL, links, the access-grant callback and the passkey RP stay on PUBLIC_URL.
  • Return-URL validation unchanged — sameOrigin still compares against publicURL, and the new test pins that a return URL on the webhook origin is refused.
  • Deployment plumbing — env in Compose/installer/.env examples, Helm gitWebhookPublicUrl (values, schema, api Deployment), plus deploy/README.md and chart README entries.
  • Tests — new TestBeginIdentitySetup_WebhookOriginCanDifferFromTheBrowserOrigin, and the existing repo-webhook registration test now asserts the override URL; go test ./internal/service/git ./internal/config passes locally.

ℹ️ The chart's bundled gateway and Ingress still serve only publicUrl's host

Setting gitWebhookPublicUrl to a different host publishes webhook URLs that the chart's own edge does not route, so deliveries fail until the operator adds a route for that host.

Technical details
# Chart edge is bound to one host

## Affected sites
- `deploy/helm/paca/templates/_helpers.tpl:197-205` — `paca.gatewaySiteAddress` binds Caddy to `publicUrl`'s host (or `:80` when empty/ingress).
- `deploy/helm/paca/templates/ingress.yaml:19-24` — a single `ingress.host`.
- `deploy/helm/paca/files/Caddyfile:95` — `{$SITE_ADDRESS::80}` site block.

## Required outcome
- The chart README and/or the `gitWebhookPublicUrl` value comment states that the webhook host must reach the API separately (a second Ingress or the operator's own edge), since the bundled gateway/ingress serves only `publicUrl`'s host.

## Open questions for the human
- Should the chart offer a host for this value (e.g. a second Ingress), or is documenting the external-routing requirement enough?

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

Comment thread deploy/README.md Resolved
Comment thread scripts/install.sh Resolved

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Migration guidance corrected — deploy/README.md now tells operators to update each GitHub App's webhook URL or unlink/relink each repository and remove stale hooks, rather than pointing at a re-register path the UI does not offer.
  • Separate-routing requirement documented — the chart README and values.yaml comment now state that a distinct gitWebhookPublicUrl host must be routed to the API separately, since the bundled gateway and Ingress serve only their configured host.
  • Installer parity — scripts/install.sh lists GIT_WEBHOOK_PUBLIC_URL in its Network usage block and writes it into the generated .env (scripts/install.sh:887).

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pikann pikann 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.

LGTM! Thank you for the contribution! 🚀

@pikann
pikann merged commit b428fee into Paca-AI:master Nov 5, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Git webhooks cannot use an origin other than PUBLIC_URL

2 participants