Repository navigation
Expose verified GitHub comment intake in Code - #1082
Conversation
2a8c533 to
82e2e58
Compare
|
@mjudeikis-bot review |
mjudeikis
left a comment
There was a problem hiding this comment.
Two Warnings and one Note on the mount. The Webhook handler comes from the base PR (#1081). This PR makes it reachable, so I reviewed the handler as a newly exposed anonymous surface.
Not anchored
docs/provider-connectivity-contract.md:184still describes class (g) as/webhooks/{kind}/{clusterID}/{name}/{token}with an "HMAC token" and names only agents as the example. Code's route has no{token}segment and authenticates with theX-Hub-Signature-256HMAC over the body. Note: add Code's shape to that row, or the next provider author copies the wrong grammar.
Checked
- Read beyond the diff:
providers/code/githubworkflow/server.go(Webhook,binding,duplicateReceipt,Context,ServeHTTP,CheckPublication),github.go(Verify),provider-sdk/serve/serve.go(Extra,prefixForClass, longest-prefix dispatch),providers/agents/main.go(the other class-(g) mount),pkg/hub/providers/proxy.go(setHeaders, anonymous forwarding), andserver_test.go's webhook helper. - Correctness: the handler flow (size cap, HMAC, event/action filter, installation/repo identity, dedupe,
Create) is sound. Binding errors of any kind are reported as 404 "connection unavailable", including transient kcp failures (see the first inline finding). - Concurrency: no shared state is added. The only duplicate race is the Create-then-AlreadyExists path, and
Webhookhandles it by re-checkingduplicateReceipt. - Tenancy and kcp:
{cluster}comes from the URL and is used forAsProvider(cluster). That is intended for class (g), but it is attacker-addressable before authentication (first inline finding). No second credential is added, and no APIExport claims change. - Provider contract: the mount is
ClassWebhookunder/webhooks/, and there is no/api/*route and no bearer.make verify-provider-contractpasses. No verb is added, so the manifest and chart are unchanged. - API, codegen and storage: not applicable, because no
apis/or CRD change. - Security: the HMAC is checked in constant time with a 32-byte minimum key, and the body is capped at 1 MiB. The pre-auth reads and error distinctions are covered in the first finding.
- Portal: not applicable, no portal change.
- Tests: the
Webhookbehaviour has tests ingithubworkflow/server_test.go. The mount itself has none (second finding). - Commands:
cd providers/code && go build ./... && go vet ./...fail only for the root package (assets.go: pattern all:portal/dist: no matching files found, because the portal is not built in this checkout).go test -count=1 ./...passes for every other package, includinggithubworkflow. The rootmainpackage tests could not be run for the same reason.make verify-provider-contractpasses (21/21 plus the permission-claim policy scan). - Not run: root
make build,make lintandmake verify-codegen, since the diff is confined toproviders/codeand the README. No e2e was run:make e2e-code-providerwas not attempted and nothing exercises the mount.
| } | ||
|
|
||
| webhooks := http.NewServeMux() | ||
| webhooks.HandleFunc("POST /webhooks/github/{cluster}/{name}", workflow.Webhook) |
There was a problem hiding this comment.
Warning: Anonymous callers reach kcp reads, and failure responses reveal what exists, before the signature is checked
The hub forwards /services/providers/code/webhooks/... anonymously, and {cluster} and {name} come straight from the URL. Webhook (githubworkflow/server.go:164) calls AsProvider(cluster) and binding() for them before it verifies the HMAC. binding() does three provider-credentialed reads: the Connection, the credential Secret and the Repository. The replies differ by stage: 503 workspace unavailable, 404 connection unavailable, 403 invalid signature. Any unauthenticated client can therefore probe which connection names exist in a workspace and trigger kcp and Secret reads at request rate, with no throttle. In addition, any transient kcp or Secret error is reported as a 404 "connection unavailable", so an operator reading GitHub's delivery log is told the connection is gone.
The reads are unavoidable, because the signing key lives in the Secret. The fix is to make every pre-signature failure indistinguishable and to log the real cause server-side:
b, err := s.binding(ctx, dyn, name, false)
if err != nil {
log.Printf("github webhook %s/%s: %v", cluster, name, err)
reply(w, http.StatusNotFound, map[string]string{"error": "not found"})
return
}
// and in the AsProvider failure branch: the same 404 bodyThere was a problem hiding this comment.
Addressed in 56b6f97 and 239c7f9. Every failure before the signature check now returns the same 404 {"error":"not found"}: workspace unavailable, missing or unusable binding, transient kcp or Secret errors, and a bad signature. The real cause is logged server-side. TestWebhookPreAuthenticationFailuresMatch checks that the three responses are identical. 239c7f9 closes one more oracle: the 1 MiB body bound ran after the binding reads, so an unsigned oversized POST returned 400 only for connections that exist. The body is now read and bounded before any lookup, and TestWebhookOversizedBodyDoesNotRevealTheConnection covers it (it fails on the previous handler). Not addressed here: rate limiting of the pre-signature reads, and the timing difference between a missing connection and a bad signature.
| MCP: mcpHandler, | ||
| Actions: codeActions, | ||
| DataPlane: dataPlane, | ||
| Extra: []serve.Route{{Prefix: serve.WebhooksPrefix, Class: serve.ClassWebhook, Handler: webhooks}}, |
There was a problem hiding this comment.
Warning: Nothing tests that the webhook route is mounted and reachable through serve.New
The existing tests call Server.Webhook directly and inject r.SetPathValue("cluster", ...) and r.SetPathValue("name", ...) (server_test.go:121). They would still pass if the mux pattern at line 222 used different wildcard names, which would leave both path values empty. They would also pass if the Extra route were dropped from serve.Options. This PR's whole purpose is that wiring, and there is no test for it. A table-style test in the providers/code main package (it already has native_routing_test.go) should build the handler as main does and assert a signed POST to /webhooks/github/<cluster>/<name> reaches Webhook with both values set. It should also assert that a GET to the same path returns 405 and that an unknown /webhooks/other path returns 404. For example:
func TestWebhookRouteMounted(t *testing.T) {
var gotCluster, gotName string
mux := http.NewServeMux()
mux.HandleFunc("POST /webhooks/github/{cluster}/{name}", func(w http.ResponseWriter, r *http.Request) {
gotCluster, gotName = r.PathValue("cluster"), r.PathValue("name")
})
// serve.New with Extra: []serve.Route{{Prefix: serve.WebhooksPrefix, Class: serve.ClassWebhook, Handler: mux}}
// POST /webhooks/github/c1/app -> gotCluster=="c1", gotName=="app"; GET -> 405
}Better still, pull the route registration into a helper that main and the test both call.
There was a problem hiding this comment.
Addressed in 56b6f97. The mux registration is pulled into codeWebhookRoutes, which both main and the test call. TestWebhookRouteMounted builds the handler through serve.New and checks that a POST to /webhooks/github/c1/app reaches the webhook with cluster and name set and the signature header intact. It also checks that GET returns 405 and that /webhooks/other returns 404. Verified locally with go test -count=1 ./... in providers/code (all packages pass, using a placeholder portal/dist).
|
Re the note about |
The size check ran after the Connection, Secret and Repository reads, so an unsigned oversized POST got 400 for a connection that exists and 404 for one that does not, which is still an existence probe. Read and bound the body first: every pre-signature reply is now independent of what exists, and oversized requests cost no kcp reads. Co-Authored-By: Claude Opus 5.5 <[email protected]>
b4f25d9 to
12c57d2
Compare
Mount the signed GitHub issue-comment webhook and document its repository and installation binding. The base draft provides the verified receipt and tests. Repository webhook configuration remains explicit.
Stacked on #1081. This draft supplies the webhook for the Factory PR-comment intake follow-up.
Validation: Code provider tests and provider-contract checks passed locally.