Webhook Middleware Phase 2: Validating webhook middleware#4314
Draft
Sanskarzz wants to merge 9 commits intostacklok:mainfrom
Draft
Webhook Middleware Phase 2: Validating webhook middleware#4314Sanskarzz wants to merge 9 commits intostacklok:mainfrom
Sanskarzz wants to merge 9 commits intostacklok:mainfrom
Conversation
Signed-off-by: Sanskarzz <sanskar.gur@gmail.com>
Signed-off-by: Sanskarzz <sanskar.gur@gmail.com>
Signed-off-by: Sanskarzz <sanskar.gur@gmail.com>
Signed-off-by: Sanskarzz <sanskar.gur@gmail.com>
Contributor
There was a problem hiding this comment.
Large PR Detected
This PR exceeds 1000 lines of changes and requires justification before it can be reviewed.
How to unblock this PR:
Add a section to your PR description with the following format:
## Large PR Justification
[Explain why this PR must be large, such as:]
- Generated code that cannot be split
- Large refactoring that must be atomic
- Multiple related changes that would break if separated
- Migration or data transformationAlternative:
Consider splitting this PR into smaller, focused changes (< 1000 lines each) for easier review and reduced risk.
See our Contributing Guidelines for more details.
This review will be automatically dismissed once you add the justification section.
Signed-off-by: Sanskarzz <sanskar.gur@gmail.com>
656c138 to
315001a
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4314 +/- ##
==========================================
+ Coverage 68.77% 69.09% +0.32%
==========================================
Files 473 479 +6
Lines 47919 48184 +265
==========================================
+ Hits 32955 33294 +339
- Misses 12299 12300 +1
+ Partials 2665 2590 -75 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
[WIP]
Overview
This PR implements Phase 2 of the Dynamic Webhook Middleware feature by introducing the Validating Webhook Middleware. Validating webhooks allow ToolHive to call external HTTP services (such as policy engines, bespoke approval workflows, or rate limiters) to strictly evaluate, approve, or deny MCP requests before they reach backend tools.
Fixes #3397
Depends on Phase 1 PR (Core Webhook Package) (This PR needs rebase onto main after Phase 1 PR gets merged.)
Key Changes
1.
pkg/webhook/validatingPackageconfig.go): AddedMiddlewareParamsstruct supporting a chain ofwebhook.Configelements. Includes setup validation requiring >0 webhooks to be explicitly declared.middleware.go):types.Middlewareinterface factory.MCPRequest, extracting User Principal attributes directly from theauth.Identitycontext, and recording the request Origin Context (SourceIP,Transport,ServerName).allowed: false.FailurePolicyFail(fail-closed, blocks request on network/server errors) andFailurePolicyIgnore(fail-open, logs a warning on exception but continues pipeline).middleware_test.go): Complete parallelized test-suite coveringAllowed=truepaths, denial paths, both failure policies, connection errors, and safe bypass for non-MCP calls. (Test Coverage sits above 88%).2. Runner Integration (
pkg/runner)middleware.go:validating.CreateMiddlewareinsideGetSupportedMiddlewareFactories.addValidatingWebhookMiddleware) securely positioning the validating evaluation block sequentially aftermcp-parserbut precisely before auditing (telemetry,authz). Thus blocking unverified telemetry pollution or unauthorized execution.config.go:RunConfigexposing theValidatingWebhooks []webhook.Configslice.Testing Performed
go test ./pkg/webhook/validating/... ./pkg/runner/...(All unit tests passing).task lint/task lint-fixagainst the overall project (clean).Type of change
Test plan
task test)task test-e2e)task lint-fix)