Removing the K8s Dependency: Local kyverno-json Validation

Table of contents
- π Why Kyverno JSON?
- π§ How Do Other Engines Handle This?
- π§ Serve kyverno-json policies Locally β No K8s Needed
- π οΈ Proposed Idea: Local JSON Policy Validation Server
- π¦ Directory Structure
- π‘ Send JSON Payloads to Be Scanned
- π§© Under the Hood
- π Why This Matters
- π§ͺ Try It, or Contribute

Kyverno is well-known for its Kubernetes-native policy engine that enables users to validate, mutate, and generate resources using YAML-based policies.
But what if you want to apply Kyverno policies to non-Kubernetes workloads? Enter Kyverno JSON β a powerful sub-project of Kyverno designed to work with any JSON payload.
π Why Kyverno JSON?
Kyverno JSON, a sub-project of Kyverno, bridges the gap between Kubernetes policies and the broader JSON ecosystem. Whether you're validating Dockerfiles, CI/CD manifests, or arbitrary JSON configurations, kyverno-json enables policy-as-code outside the cluster.
However, one common limitation developers face is this:
β kyverno-json doesn't support local policy testing without spinning up a cluster yet. It requires a Kuberenetes cluster, hence a kuberentes dependency.
π§ How Do Other Engines Handle This?
The policy engines already support local testing and donβt require Kubernetes to function:
Open Policy Agent (OPA) β Supports local testing via
opa run --server policies/
KubeWarden β Uses WebAssembly (Wasm) modules that can be tested locally
This proposal aims to bring similar local testing convenience to the Kyverno ecosystem.
π§ Serve kyverno-json policies Locally β No K8s Needed
To address the gap and remove the Kubernetes dependency for JSON policy evaluation, Iβve added local server functionality to kyverno-json
.
This allows developers to validate JSON payloads against Kyverno policies entirely locally β making it easier to test and iterate during development or in CI pipelines.
βοΈ Note: This is a proposed feature, and Iβve opened a pull request (PR) to share the changes.
π οΈ Proposed Idea: Local JSON Policy Validation Server
Run the Command
kyverno-json -h
kyverno-json is a CLI tool to apply policies to json resources.
Available Commands:
...
scan scan
serve serve
...
Start the Server
kyverno-json serve --policy-dir pkg/commands/serve/testdata
Youβll see the server listening on port 8080:
Listening on: 8080
2025/06/17 00:36:45 configured route /api/scan
This launches an HTTP server with /api/scan
and /api/scan/:policy_name
endpoints.
π¦ Directory Structure
The βpolicy-dir
Flag points to your policy directory. This directory must contain one or more Kyverno policies written in the standard YAML format.
pkg/commands/serve/testdata/
βββ dockerfile-policy.yaml
βββ payload.json
π‘ Send JSON Payloads to Be Scanned
Now in Terminal 2, send a JSON payload using curl
:
π§ͺ Scan with All Policies
curl -X POST http://localhost:8080/api/scan \
-H "Content-Type: application/json" \
--data-binary @pkg/commands/serve/testdata/payload.json | jq .
π Sample Output
{
"results": [
{
"policy": "check-dockerfile",
"rule": "deny-external-calls",
"result": "fail",
"message": "-> HTTP calls are not allowed...\n-> wget is not allowed..."
}
]
}
π¨ The policy "check-dockerfile"
flagged the usage of wget
and external HTTP calls in the Dockerfile as violations.
π― Scan Against a Specific Policy
Want to test against just one policy?
curl -X POST http://localhost:8080/api/scan/check-dockerfile \
-H "Content-Type: application/json" \
--data-binary @pkg/commands/serve/testdata/payload.json | jq .
π§© Under the Hood
Cobra CLI β Adds a
--policy-dir
flag toserve
modeRouting β Exposes
/api/scan
and/api/scan/:policy_name
inroutes.go
Policy Provider Layer β Handles loading and caching of policies from disk
π Why This Matters
β No cluster required β run policies locally during CI or development
β Lightning fast β instant feedback on JSON compliance
β Language-agnostic β works with any JSON-producing system
π§ͺ Try It, or Contribute
This is an early-stage proposed feature, and Iβd love feedback or suggestions. Iβll update my blog once this feature is merged.
With this, we hope to make policy testing easier, faster, and more accessible β anywhere JSON exists.
β¨ For more blog updates like this, follow me on Hashnode and Twitter. Thanks for reading! π
Subscribe to my newsletter
Read articles from Ruhika directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
