Conversation
Step 4: NewPolicyMiddleware in pkg/gateway/ - PEPConfig with PDPClient, EnforcementMode, ObligationRegistry, DecisionCache - Full PEP flow: badge verify, break-glass, cache, PDP, enforce, obligations - 95.2% test coverage (33 test cases) Step 5: Proto changes in proto/capiscio/v1/mcp.proto - EvaluateToolAccessRequest: enforcement_mode, capability_class, envelope_id, delegation_depth, constraints_json, parent_constraints_json - EvaluateToolAccessResponse: policy_decision_id, policy_decision, enforcement_mode, repeated MCPObligation obligations - New MCPObligation message Step 6: Guard PDP integration in pkg/mcp/ - GuardOption pattern: WithPDPClient, WithEnforcementMode, WithObligationRegistry - evaluateWithPDP: builds PIP request, queries PDP, handles EM matrix - evaluateInlinePolicy: refactored legacy trust level + tool glob checks - PDP replaces inline policy (authentication always runs first) - 15 PDP-specific test cases, evaluateWithPDP 100% coverage Implements Steps 4-6 of the RFC-005 PIP implementation guide v1.2.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
Implements RFC-005 PIP integration steps 4–6 by adding a full HTTP-layer PEP middleware, extending MCP proto messages with PDP/envelope fields, and wiring a PDP-backed authorization path into the MCP Guard while preserving backward compatibility.
Changes:
- Added
NewPolicyMiddlewareinpkg/gateway/implementing badge verification, break-glass, caching, PDP evaluation, obligations, and telemetry callbacks. - Extended
EvaluateToolAccessrequest/response protos (and regenerated Go bindings) with RFC-005 decision context + RFC-008 envelope placeholders. - Integrated a PDP client into
pkg/mcp/Guardvia functional options and added PDP-focused tests.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| proto/capiscio/v1/mcp.proto | Adds RFC-005/RFC-008 fields and MCPObligation message. |
| pkg/rpc/gen/capiscio/v1/mcp.pb.go | Regenerated bindings reflecting the proto changes. |
| pkg/pip/breakglass.go | Adds ParseBreakGlassJWS helper for verifying break-glass JWS tokens. |
| pkg/gateway/middleware.go | Introduces PEPConfig + NewPolicyMiddleware PEP flow and helpers. |
| pkg/gateway/policy_middleware_test.go | Adds comprehensive PEP middleware tests (badge-only, PDP, cache, obligations, break-glass, txn_id, etc.). |
| pkg/mcp/guard.go | Adds PDP integration via GuardOption and PDP/inline policy split. |
| pkg/mcp/guard_pdp_test.go | Adds Guard PDP integration tests. |
| pkg/mcp/types.go | Extends EvaluateResult with PDP decision metadata fields. |
Split NewPolicyMiddleware (complexity 25) into pep struct with methods: - serveHTTP (5), evaluatePolicy (7), handleCachedDecision (7), handleBreakGlass (3), handlePDPUnavailable (2), handlePDPDeny (3), enforceObligations (4), buildPIPRequest (2) All functions now well under gocyclo threshold of 15. No behavioral changes — all 33 tests pass unchanged.
- Validate PDP response (Decision + DecisionID) in gateway and guard - Guard nil logger safety in WithGuardLogger - Replace uuid.Must(uuid.NewV7()) with error-handled fallback - Restrict ParseBreakGlassJWS to EdDSA only - Add panic recovery to emitPolicyEvent callbacks
- Cached DENY in EM-OBSERVE now allows through with ALLOW_OBSERVE - Use cached PDP reason in 403 response when available - Fix PolicyEventCallback comment: synchronous, not non-blocking
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
Implements Steps 4-6 of the RFC-005 PIP implementation guide v1.2. Follows PR #40 (Steps 1-3, merged).
Step 4:
NewPolicyMiddleware— HTTP PEP (pkg/gateway/)New
NewPolicyMiddlewarefunction implementing the full HTTP-layer PEP flow:PEPConfigstruct:PDPClient,EnforcementMode,ObligationRegistry,DecisionCache,BreakGlassKey,PEPID,Workspace,Logger, telemetry callbackParseBreakGlassJWSadded topkg/pip/breakglass.go(usinggo-jose/v4)NewAuthMiddlewarepreserved (markedDeprecated)Tests: 33 test cases in
policy_middleware_test.go— 95.2% coverageStep 5: Proto changes (
proto/capiscio/v1/mcp.proto)New fields for RFC-005 PIP envelope:
EvaluateToolAccessRequest:enforcement_modecapability_classenvelope_iddelegation_depthconstraints_jsonparent_constraints_jsonEvaluateToolAccessResponse:policy_decision_idpolicy_decisionenforcement_modeobligationsNew
MCPObligationmessage:type(1),params_json(2)Generated via
make proto(buf v2). Field 9 reserved per implementation guide.Step 6: Guard PDP integration (
pkg/mcp/)Wired PDP into the existing
Guardusing the functional options pattern for backward compatibility:GuardOption:WithPDPClient,WithEnforcementMode,WithObligationRegistry,WithGuardLoggerevaluateWithPDP: builds PIP request, queries PDP, handles unavailability per EM (OBSERVE → allow, others → fail-closed), enforces decision per EM matrix, runs obligation enforcementevaluateInlinePolicy: refactored legacy trust level + tool glob checksNewGuardsignature:...GuardOptionvariadic — fully backward compatibleTests: 15 PDP-specific test cases in
guard_pdp_test.go:Coverage:
evaluateWithPDP100%,EvaluateToolAccess96.2%, all options 100%Files changed (8 files, +2285/-88)
pkg/gateway/middleware.gopkg/gateway/policy_middleware_test.gopkg/mcp/guard.gopkg/mcp/guard_pdp_test.gopkg/mcp/types.gopkg/pip/breakglass.gopkg/rpc/gen/capiscio/v1/mcp.pb.goproto/capiscio/v1/mcp.protoTest results
All packages pass with zero regressions:
Related
8532cc6)internal-docs/engineering/rfc005-pip-implementation-guide.mdv1.2