Validate policy params for LLM operationPolicies and the policies list - #3383
Validate policy params for LLM operationPolicies and the policies list#3383thivindu wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughLLM operation-level and deprecated policy attachments now validate per-path parameters against resolved policy schemas. Validation coerces rendered values, checks absent parameter maps, and reports schema errors. Tests cover valid, invalid, schema-less, unresolved, deprecated, and template-related cases. ChangesLLM policy parameter validation
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This change validates LLM policy attachment parameters against their policy schemas, including required fields, coercion, deprecated policies, and unresolved references. The covered validation behavior is ready to merge. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Purpose
PolicyValidatorvalidates policyparamsagainst the policy definition's declared JSON Schema for most artifact types, but silently skips it for two of the five policy collections anLlmProvider/LlmProxycan declare.validateLLMPolicyRefsresolved the policy reference for the operation-level and deprecated lists and then discarded the resolved definition:Only the global (api-level) list routed through
validatePolicy, which performs the schema check.Coverage before this PR:
RestApispec.policies,spec.operations[].policiesMcpspec.policiesLlmProvider/LlmProxyspec.globalPoliciesLlmProvider/LlmProxyspec.operationPolicies[].paths[].paramsLlmProvider/LlmProxyspec.policies[].paths[].params(deprecated)A misconfigured operation-level LLM policy therefore deployed successfully instead of being rejected: missing required params, out-of-range values and unknown properties all passed. The failure surfaced later at runtime, where the policy is dropped or misbehaves with no deploy-time signal — and the same params on the same policy were correctly rejected when attached as a
globalPolicy, which made the behavior look arbitrary.Resolves:
operationPoliciesand the deprecatedpolicieslist #3381Goals
Schema-validate
paramsfor the two remaining LLM policy collections, so an invalid operation-level policy fails at deploy time with a field path naming the offending param — matching whatRestApi,Mcpand LLMglobalPoliciesalready do.Approach
validateLLMPolicyRefsnow uses the*models.PolicyDefinitionthatvalidatePolicyRefwas already returning, and validates each path attachment's params:A new
validateAttachedPolicyParamshelper coerces then schema-checks one params map. It handles the two things that differ from the api-level path:params:entirely would bypass a schema'srequiredlist.{{ env "LIMIT" }}→"100"for an integer param), mirroringvalidatePolicy's handling of api-level params. Both call sites validate rendered config (RenderSpecatllm_deployment.go:270/:457, validation at:312/:498), so this is the correct order.An unresolvable name/version reports once and skips param validation, rather than repeating the same error per path.
User stories
As an API platform user deploying an
LlmProvider/LlmProxy, when I attach an operation-level policy with invalid params, the deploy is rejected with an error naming the param — instead of succeeding and silently misbehaving at runtime.Automation tests
policy_validator_llm_test.go(+188 lines), covering: valid params; missing required / out-of-range / unknown-property; absentparamsmap; string→int coercion; a definition with no parameter schema; unresolvable ref not re-reporting per path; the deprecatedpolicieslist; and the template-merge rationale. Fullgateway-controllermodule passes (go build ./...,go vet,go test ./...).Regression check against real policy definitions
Because this turns previously-accepted config into rejected config, verified it doesn't reject anything valid: loaded all 36 real policy definitions from
wso2/gateway-controllersand validated every operation-level/deprecatedparamsblock ingateway/examples/*.yaml(api-key-auth,content-length-guardrail,llm-header-router,llm-cost-based-ratelimit,openai-to-bedrock-transformer, …) — all clean, no false positives.Behavior change to be aware of: an
LlmProvider/LlmProxyalready deployed with invalid operation-level policy params will now fail validation on its next deploy/update. That is the intended fix, but it can surface as a new failure on config that previously "worked".Test environment
Go 1.26.2, macOS (darwin 24.6.0). Validation logic is platform- and DB-independent; no browser or database involvement.