kshield is an open source Go CLI that scans Kubernetes manifests and live clusters that run AI and LLM workloads (vLLM, Ollama, Triton, Text Generation Inference, Text Embeddings Inference, LocalAI, SGLang, llama.cpp, lmdeploy, TensorRT-LLM, KubeRay, KServe, Qdrant, Milvus). It finds security misconfigurations such as root containers, unauthenticated inference APIs, --trust-remote-code, pickle model loading, hostPath and hostPort use, open Ray ports and missing ingress, egress or runtime guards. Each finding cites the verbatim text of the requirement of the profile that it supports evidence for: DORA (Regulation (EU) 2022/2554 and RTS (EU) 2024/1774) or NIS2 (Directive (EU) 2022/2555 and CIR (EU) 2024/2690). Reports come as text, JSON, HTML, PDF and SARIF, and can be packed into a signed evidence bundle. kshield remediate writes a kustomize bundle with workload patches and Cilium, Tetragon and Kyverno policies, and changes the cluster only when you add --apply.
kshield reports support evidence for the requirements they cite. They are not an audit and do not state compliance with any regulation.
- General Kubernetes scanners do not know AI serving stacks. They miss an open vLLM API, a Ray dashboard behind a LoadBalancer or a model loaded through pickle.
- Financial entities under DORA must show how ICT risks are found and handled. A scan result that cites the exact regulation text, in a signed and repeatable form, is easier to hand to a risk or audit team than a screenshot.
- A finding should come with a fix. kshield writes patches and policies, and marks what needs a human.
With Go 1.26 or newer:
go install github.com/sv222/kshield/cmd/kshield@latestBinaries for Linux, macOS and Windows (amd64 and arm64) with checksums.txt are attached to each release. To build from source:
git clone https://github.com/sv222/kshield.gitcd kshield && go build -o kshield ./cmd/kshieldScan the insecure sample stack from the test corpus:
kshield scan manifest -f test/corpus/baseline/toxic/input.yamlkshield dev | profile dora v1 | manifest scan | 5 objects, 5 AI workloads
[FAIL] DORA-CH2-001 KS-WL-001 Container may run as root (no runAsNonRoot: true, or UID 0)
FAIL Deployment/ai-inference/qdrant container=qdrant: container may run as root: runAsNonRoot is not true and runAsUser is not set
FAIL Deployment/ai-inference/vllm container=vllm: container may run as root: runAsNonRoot is not true and runAsUser is not set
...
fix: workload patch (kshield remediate) | supports evidence for: DORA Art. 9(4)(c)
[PASS] DORA-CH2-004 KS-WL-004 hostIPC, hostPID or hostNetwork true
[FAIL] DORA-CH2-005 KS-WL-005 /dev/shm from hostPath (or hostPath /dev)
FAIL Deployment/ai-inference/vllm: volume "shm" mounts hostPath /dev/shm
fix: workload patch (kshield remediate) | supports evidence for: DORA Art. 9(3)(c)
...
Summary: 17 FAIL, 5 WARN, 13 PASS, 0 INFO, 5 N/A
The exit code is 1 because there are findings. The hardened version of the same stack is clean:
kshield scan manifest -f test/corpus/baseline/hardened/input.yamlSummary: 0 FAIL, 0 WARN, 35 PASS, 0 INFO, 5 N/A
Scan your own cluster. Scans are read-only:
kshield scan cluster -n ai-inference --format html --out report.htmlAn organisation that falls under NIS2 scans with the nis2 profile and gets NIS2 display IDs and NIS2 references:
kshield scan manifest -f app.yaml --profile nis2| id | regulation | who it applies to | checks |
|---|---|---|---|
dora |
Regulation (EU) 2022/2554 Chapter II and RTS (EU) 2024/1774 | financial entities under DORA | 40 |
nis2 |
Article 21 of Directive (EU) 2022/2555 and CIR (EU) 2024/2690 | essential and important entities under NIS2 | 38 |
NIS2 applies to essential and important entities; for financial entities DORA is lex specialis (Art. 4 of the Directive). The default profile is dora; runs without --profile do not change. KS-WL-006 and KS-WL-013 stay out of the nis2 profile because no point of NIS2 Art. 21 or of the Annex of CIR (EU) 2024/2690 fits them. The check by check mappings are in docs/MAPPING-REVIEW.md and docs/MAPPING-REVIEW-nis2.md.
List the checks of a profile with kshield checks list --profile dora (or --profile nis2) and read one with kshield checks explain KS-AI-002.
| Group | Checks | Examples |
|---|---|---|
| Workload hardening | KS-WL-001..016 | root containers, privilege escalation, capabilities, host namespaces, /dev/shm hostPath, any other hostPath, hostPort, seccomp, token automount, secrets in env, images not pinned by digest, GPU access through hostPath |
| AI serving | KS-AI-001..013 | vLLM without API key, --trust-remote-code, pickle model load, inference API exposed without auth, Ray GCS, client or dashboard exposed, Ray TLS off, Ollama exposed, Qdrant without API key or TLS, Milvus authorization off, other engines without API key, debug and insecure flags, unsafe model sources and formats, Gateway API HTTPRoute exposure without auth |
| Network | KS-NET-001..004 | no default-deny egress, egress to the whole internet, pod-to-pod encryption off, no ingress isolation |
| Runtime guards | KS-RT-001..003 | no Tetragon shell-exec guard, no Tetragon egress-connect guard, no Kyverno admission guard |
| Cluster prerequisites | KS-PRE-001..004 | Tetragon, Cilium and Kyverno present and healthy, BPF LSM on the nodes |
Supported workloads: Pod, Deployment, StatefulSet, DaemonSet, ReplicaSet, ReplicationController and Job, CronJob, Argo Rollout, KubeRay RayCluster, RayService and RayJob, KServe InferenceService, ServingRuntime and ClusterServingRuntime. A cluster scan does not read ReplicationControllers or Rollouts yet; their pods are scanned as owned pods. Helm users can pipe helm template output into kshield scan manifest -f -.
How kshield decides that a container is an AI engine:
- Image or command names it: vLLM, Ollama, Triton (
tritonserver), Text Generation Inference (text-generation-inference,tgi,text-generation-launcher), Text Embeddings Inference (text-embeddings-router), LocalAI (local-ai), SGLang, llama.cpp (llama-server), lmdeploy, TensorRT-LLM (trtllm-serve), Qdrant, Milvus, Ray images and Ray Serve commands. The workload name is not used. - An Ollama container is also found by port 11434, an
OLLAMA_env var or a mount path that contains.ollama. - A custom image can opt in with the label or annotation
kshield.io/ai: "true"on the workload or its pod template, or with--workload-selector <label selector>onscan manifestandscan cluster. The engine of an opted-in workload is a guess, so the engine checks report WARN, not FAIL. - If a gateway that kshield cannot see already authenticates the traffic, set
kshield.io/gateway-auth: "true"on the workload. KS-AI-001, KS-AI-004, KS-AI-007, KS-AI-010 and KS-AI-013 then report INFO and name the annotation. kshield does not verify the gateway.
Auth evidence in front of a workload:
- The engine key (
--api-keyor the engine env var), an Ingress annotation (auth-url,auth-type,auth-signin,auth-secret,oauth2) andkshield.io/gateway-authcount, as before. - Istio: an
AuthorizationPolicythat allows only requests with a principal (principalsorrequestPrincipals), denies requests without one, or delegates to an external provider. It must select the workload, its Service or the ingress Gateway. A policy that relies on JWT principals counts only with aRequestAuthenticationthat selects the same target. - Kong: a
KongPluginorKongClusterPluginwith an auth plugin (key-auth,jwt,oidcand the other Kong auth plugins, not disabled and without ananonymousconsumer), named in thekonghq.com/pluginsannotation of the Ingress, Service or HTTPRoute, or in anExtensionReffilter of an HTTPRoute. - Envoy Gateway: a
SecurityPolicywithjwt,oidc,basicAuth,apiKeyAuthorextAuththat targets the HTTPRoute or its Gateway. - A protected exposure is reported as INFO with the name of the policy or plugin, never skipped without a trace (an Ingress with an auth annotation is the one exception, as before). kshield reads the objects. It does not check that the mesh or gateway enforces them.
- KS-AI-013 checks every HTTPRoute that has a Gateway parent and reaches an AI engine Service. It reports WARN, not FAIL, when it cannot read what decides the case: a Kong plugin that is not in the input, or a parent Gateway outside the scanned namespaces.
The hardened Ollama and vLLM examples and what the engines need to run as non-root are in docs/hardened-engines.md.
kshield scan manifest -f app.yaml --format text|json|html|pdf|sarif [--out <path>] [--fail-on fail|warn|never] [--deterministic] [--waivers <file>] [--baseline <scan.json>]text(default) for the terminal.jsonis the stable report contract (kshield.report/v1).htmlis one self-contained page with no scripts and no network requests.pdffor people who want a document (needs--out).sarifis SARIF 2.1.0 for GitHub code scanning and other SARIF tools. A waived result carriessuppressions(kindexternal, statusaccepted, the waiver reason as justification) and keeps its level. With--baseline, each result carriesbaselineState(neworunchanged). GitHub does not listsuppressionsorbaselineStateamong the SARIF properties that code scanning supports, so expect waived findings to show there as open alerts.--deterministicgives byte-identical output for the same input.- The text, HTML and PDF reports show waived findings with the waiver owner and the expiry date, and a
Waiverssection lists every entry with its status (applied, expired, unused, broad).
kshield scan cluster [--kubeconfig <file>] [--context <name>] [-n <ns> ...] [--node-probe]- Read-only: only
get,listand discovery requests. Secret values are never printed or written. - RBAC:
deploy/rbac/kshield-scan.yaml(read-only ClusterRole) and, for--node-probe,deploy/rbac/kshield-node-probe.yaml. - Istio, Kong, Gateway API and Envoy Gateway objects are read only when their CRDs exist. If the CRDs exist and the role cannot read them, KS-AI-004, KS-AI-007 and KS-AI-013 get UNKNOWN. Update the role from
deploy/rbac/kshield-scan.yamlwhen you upgrade. --node-probestarts one short-lived pod per Linux node (default namespacekube-system) to read the LSM list and kernel config. The pods are deleted at the end, also after Ctrl-C.- A resource that kshield cannot read is never reported as missing. The checks that need it get UNKNOWN and the scan exits 3.
kshield evidence keygen --out signkshield scan manifest -f app.yaml --evidence pack --sign-key sign.keykshield evidence verify pack --pub-key sign.pubsignature: valid
evidence: OK
The pack holds all five reports, manifest.json (sha256 and size of each file) and manifest.sig (Ed25519). verify exits 1 when a file is missing, changed or extra, or the signature fails.
kshield scan manifest -f app.yaml --format json --deterministic --out scan.jsonkshield remediate --from scan.json -f app.yaml --mode audit --out fixThe fix directory is a kustomize bundle: base/, workload-patch.yaml, workload-patch-6902/, infrastructure-policies.yaml (Cilium, Tetragon and Kyverno), MANUAL.md and remediation.json. --mode audit blocks nothing. --mode enforce switches the policies to deny and kill. The policies and their limits are described in policies/README.md.
- For an Ollama container with a volume mounted under
/rootat a path containing.ollama, the workload patch moves that mount to/ollamaand pointsHOMEandOLLAMA_MODELSthere before applying the non-root uid. A mount under/rootat any other path stays a manual item. MANUAL.mdlists which non-AI workloads of a policy namespace break the Pod Security Standardsrestrictedprofile and which conform, andremediation.jsoncarries the same list aspssNonAI.- The Ray API server egress policy is one per autoscaling RayCluster and selects on both
ray.io/node-type: headandray.io/cluster.
remediate writes a bundle and changes nothing in the cluster. Add --apply to also send the policies to the cluster with server-side apply (field manager kshield):
kshield remediate --from scan.json -f app.yaml --out fix --apply --dry-runkshield remediate --from scan.json -f app.yaml --out fix --apply- Off by default. The bundle is written first, then applied. It uses the kubeconfig context from
--kubeconfigand--context(for a clusterscan.json, the context of the scan). - Before it changes anything, kshield prints the context, the server and the objects (kind, namespace, name), and asks
Apply N objects to context X? [y/N].--yesskips the question. Without a terminal and without--yesit refuses (exit 2). --dry-runruns a server-side dry run, prints the result and changes nothing.- A real apply first dry-runs every object on the server. If the server rejects one, nothing is applied (exit 4). Server-side apply cannot remove a field that another manager owns, so a patch that swaps a volume type (the
/dev/shmhostPath fix of KS-WL-005) is rejected on an object that was created by another tool. Apply that patch with the kustomize bundle by hand. - By default only the policies are applied. The workload patches restart pods, so they are applied only with
--apply-patches, and only for the workloads that the bundle patches. - It refuses when the cluster does not serve a kind of the bundle (Kyverno
Policy, CiliumCiliumNetworkPolicy, TetragonTracingPolicyNamespaced).--skip-missing-crdsskips those objects. - A field that another field manager owns is a conflict and stops the apply (exit 4).
--force-conflictstakes the field over. Review who owns it first. - RBAC:
deploy/rbac/kshield-apply.yamlholds two ClusterRoles,kshield-apply(create and patch on the three policy kinds) andkshield-apply-patches(patch on the workload kinds, only for--apply-patches).
A waivers file records accepted risks: which finding, why, who owns it, until when. A waived finding no longer fails the build. It stays visible in every report and in the evidence bundle with its original status. For DORA and NIS2 work, a documented risk acceptance with an owner and an expiry is itself audit evidence.
kshield scan manifest -f k8s/ --waivers waivers.yamlversion: 1
waivers:
- check: KS-WL-001
namespace: ai-inference
kind: Deployment
name: qdrant
container: qdrant
reason: qdrant image runs as root, the new base image is scheduled
owner: platform-team
created: 2026-11-01
expires: 2027-06-01
ticket: SEC-42checktakes the check id (KS-WL-001) or the display id of the profile (DORA-CH2-001,NIS2-K8S-001).namespace,kind,nameandcontainernarrow the waiver;*and shell globs are allowed. Withoutnamespace,kindandnamethe waiver covers every object of that check, and the report flags it as broad.reasonneeds at least 10 characters,owneris required,expiresis aYYYY-MM-DDdate fromcreatedto 365 days after it, andcreatedis at most one day after today (UTC). An unknown field or check id, a missing or blank field, a bad date, acreateddate in the future or an expiry outside that range is an input error (exit 2).- Only FAIL and WARN findings can be waived. PASS, INFO and UNKNOWN findings are never waived; UNKNOWN stays visible because it means the scan is incomplete.
- An expired waiver does not apply and the report lists it under expired waivers. A later entry that is still valid applies instead. When several valid entries match, the first one applies. A waiver that matches nothing is listed under unused waivers. Neither changes the exit code.
--strict-waiversturns both into exit 2. - Without
--waivers, scan reads.kshield-waivers.yamlfrom the current directory when it exists and prints one line about it.--no-waiversturns that off. A sample is inexamples/waivers/. kshield waivers check <file>validates a file and prints each entry with the days left before expiry. Exit 0 when valid, 2 when not. Use it as a pre-commit hook.- The JSON report gives each waived finding a
waiverblock (entry index, reason, owner, expiry, ticket,original_status) and a top levelwaiversblock (file, sha256, applied, expired, unused, broad). - The evidence bundle copies the waivers file and records its sha256, so the signature covers the accepted risks.
evidence verifyfails when the copy was changed.
A baseline marks each finding as new or unchanged against an earlier scan.json, and --fail-on-new fails the build only on new findings:
kshield scan manifest -f k8s/ --baseline scan.json --fail-on-new- Each finding gets
baseline: neworunchanged. Findings of the baseline that are gone are listed asabsent(fixed since the baseline). SARIF results carryneworunchangedinbaselineState. Absent findings stay out of SARIF: they have no file location, and a fixed finding must not appear as a result. - A baseline from another profile or with an incompatible
scan.jsonschema version is an input error (exit 2).--fail-on-newneeds--baseline, otherwise exit 2. - Waived findings never count for
--fail-on-new.
To fail a pull request only on what it adds, scan the base branch and the pull request in the same job. The baseline is a scan.json, so write it with --format json:
name: kshield-new-findings
on: [pull_request]
permissions:
contents: read
jobs:
scan:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: "1.27.4"
- run: go install github.com/sv222/kshield/cmd/kshield@latest
- run: git worktree add "$RUNNER_TEMP/base" "origin/$GITHUB_BASE_REF"
- run: kshield scan manifest -f "$RUNNER_TEMP/base/k8s/" --format json --out "$RUNNER_TEMP/baseline.json" --fail-on never
- run: kshield scan manifest -f k8s/ --baseline "$RUNNER_TEMP/baseline.json" --fail-on-newBaselines are not in v0.4.0, so this example needs the next release; pin that version once it is out. Both scans must use the same --profile. The base branch needs the k8s/ directory too.
| Code | Meaning |
|---|---|
| 0 | nothing at or above --fail-on |
| 1 | findings at or above --fail-on |
| 2 | usage or input error |
| 3 | scan incomplete (a read was denied or failed) |
| 4 | remediate --apply failed while applying (a conflict, a denied write or an API error) |
remediate --apply returns 2 when it refuses: a missing CRD without --skip-missing-crds, no terminal without --yes, or an answer other than yes.
With --baseline and --fail-on-new, exit 1 means only findings that are new since the baseline at or above --fail-on. --strict-waivers returns 2 when the waivers file holds an expired or an unused entry. waivers check returns 2 for an invalid waivers file.
Each check of the dora profile maps to articles of DORA Chapter II (ICT risk management, Regulation (EU) 2022/2554) and of RTS (EU) 2024/1774. The nis2 profile maps to Article 21 of Directive (EU) 2022/2555 and to the Annex of Commission Implementing Regulation (EU) 2024/2690, with the same article choices as k8s-remediate-nis2 for the same controls. The report quotes the regulation text verbatim from excerpts committed in internal/regtext. The full mapping, check by check, is in docs/MAPPING-REVIEW.md and docs/MAPPING-REVIEW-nis2.md.
What this means and what it does not:
- A PASS or FAIL is a technical fact about your manifests or cluster, linked to the requirement it is relevant to.
- kshield supports evidence for those requirements. It is not an audit, a certification or legal advice, and it does not state that you are compliant with DORA or any other regulation.
- DORA asks for much more than any scanner can see: governance, testing programs, incident reporting, third-party risk. kshield covers a narrow technical part.
Upload SARIF to GitHub code scanning:
name: kshield
on: [push, pull_request]
permissions:
contents: read
security-events: write
jobs:
scan:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: "1.27.4"
- run: go install github.com/sv222/kshield/cmd/kshield@v0.4.0
- run: kshield scan manifest -f k8s/ --format sarif --out kshield.sarif --fail-on never
- uses: github/codeql-action/upload-sarif@1fc58d04a4d4374f921bdac573c3811c240f9c26 # v4.39.2
with:
sarif_file: kshield.sarifTo fail the build on findings, drop --fail-on never (or use --fail-on warn).
- Load: read YAML from files, directories, stdin or the Kubernetes API. In a cluster, live Pods are linked to their top-level owner through
ownerReferences. - Model: detect the AI stack of each workload (vLLM, Ollama, Triton, TGI, TEI, LocalAI, SGLang, llama.cpp, lmdeploy, TensorRT-LLM, Ray, KServe, Qdrant, Milvus) from images, commands, args, CRD kinds and the opt-in label.
- Check: run the checks of the profile. Each gives PASS, FAIL, WARN, INFO, N/A or UNKNOWN with one finding per object and container.
- Report: render the result with the regulation excerpts the profile cites.
- Remediate (optional): turn findings into patches, policies and manual steps.
The scanner has no network access other than the Kubernetes API, no telemetry and no cloud service.
- Manifest-tier checks (secrets in env, digest pins, memory limits, engine flags, model sources and API key evidence) need the manifests. A cluster scan does not run them.
- Cluster-tier checks (pod-to-pod encryption, Tetragon, Cilium and Kyverno health, BPF LSM) need a cluster.
- KS-PRE-004 cannot pass on Kind nodes, which do not expose
/sys/kernel/security/lsm. - The enforce-mode shell guard still kills exec probes and lifecycle hooks that run a shell, and a bare
ray startpod without the KubeRayray.io/clusterlabel. The pods of a KubeRay RayCluster (head, worker, driver) are exempt. - The overhead of the runtime guards is not measured.
- The Ollama root-mount move is unit-tested and corpus-verified, but it has not been verified on a cluster running the stock
ollama/ollamaimage. - Only the
doraandnis2profiles exist today.
kshield replaces ai-guard-k8s. The checks of ai-guard-k8s are ported, with these IDs:
| ai-guard-k8s | kshield |
|---|---|
| AIG-001 no auth on the engine | KS-AI-001 (vLLM), KS-AI-010 (other engines) |
| AIG-002 debug and insecure flags | KS-AI-011 |
| AIG-003 host namespaces | KS-WL-004 |
| AIG-004 hostPath | KS-WL-005 (/dev, /dev/shm), KS-WL-014 (GPU devices), KS-WL-015 (any other path) |
| AIG-005 root, privileged, privilege escalation | KS-WL-001, KS-WL-002 |
| AIG-006 seccomp | KS-WL-009 |
| AIG-007 requests and limits | KS-WL-013 (memory limit only) |
| AIG-008 unsafe model loading | KS-AI-002, KS-AI-003, KS-AI-012 |
| AIG-009 no ingress isolation | KS-NET-004 |
| AIG-010 exposed without auth | KS-AI-004 (Ollama: KS-AI-007), with Istio and Kong evidence |
| AIG-011 hostPort | KS-WL-016 |
| AIG-012 dangerous capabilities | KS-WL-003 |
| AIG-013 HTTPRoute exposed without auth | KS-AI-013 |
The flags and names change like this:
| ai-guard-k8s | kshield |
|---|---|
scan --path <dir> |
scan manifest -f <dir> |
scan (live cluster) |
scan cluster |
--fail-on low|medium|high |
--fail-on fail|warn|never. High is FAIL, Medium and Low are WARN |
--json, --sarif |
--format json (kshield.report/v1), --format sarif |
--workload-selector |
--workload-selector |
label ai.infra.guard/enabled |
label or annotation kshield.io/ai |
annotation ai.infra.guard/gateway-auth |
label or annotation kshield.io/gateway-auth |
enforce |
remediate (a kustomize bundle) |
enforce --apply |
remediate --apply. It is server-side apply without force, asks first, and applies policies only unless you add --apply-patches |
--helm |
pipe helm template into kshield scan manifest -f - |
--kustomize |
pipe kustomize build into kshield scan manifest -f - |
For example, ai-guard scan --path dir --fail-on high becomes kshield scan manifest -f dir --fail-on fail.
What is different:
- The SARIF
ruleIdvalues change fromAIG-toKS-, so code scanning alerts of ai-guard-k8s close and new ones open. - kshield finds engines by image or command, not by workload name. Use the
kshield.io/ailabel for custom images. - kshield reads the Secret behind an
envFromkey. A Secret that is not in the input gives a WARN, not a guess from its name. - Istio, Kong, Gateway API and Envoy Gateway auth evidence is ported, with objects read as
unstructureddata. A protected exposure is INFO that names the policy, not a skipped finding. remediate --applydoes not force by default. Ai-guard-k8s forced the apply.- The CPU and memory requests of AIG-007 are not checked.
remediatewrites a namespaced Kyverno policy with the Pod Security Standardsrestrictedprofile, not the label-selected cluster policies of ai-guard-k8s.
- Signed release binaries.
- More AI serving stacks and checks.
- More profiles beyond DORA and NIS2.
Ideas and votes are welcome in issues.
See CONTRIBUTING.md. Report security issues as described in SECURITY.md.
Copyright 2026 Stanislav