{"slug": "testing-kubernetes-vulnerability-scanning-with-ai-what-we-built-and-what-we", "title": "Testing Kubernetes Vulnerability Scanning with AI: What We Built and What We Found", "summary": "A two-person team working with an AI coding agent built vulnbench, a FastAPI/SQLite web console that runs repeatable memory and vulnerability-scan benchmarks against the Uptycs osquery agent on Kubernetes and OpenShift clusters. Over four weeks the console went through 179 gated releases (v0.1 to v0.106.17) and 52 benchmark runs across two clusters, with humans approving every change to test conditions, agent binaries or cloud queries. The work traced the agent's OOM loop to root causes, including the process_envs query as a memory trigger, by aligning per-second memory probes, query timings and log lines on a shared UTC timeline.", "body_md": "In four weeks, two of us and an AI coding agent built a test console, ran 52 benchmark runs on two Kubernetes clusters, and turned an unexplained agent OOM loop into a list of root causes with evidence.\n\nThe question sounded simple: why does the Uptycs osquery agent on our OpenShift lab cluster keep hitting its memory limit? The agent scans every container on a node for vulnerabilities. A scan parses hundreds of thousands of CVE templates, uploads results to the cloud, and shares one pod memory limit with everything else the agent does.\n\nAnswering that by hand means watching memory second by second, matching it to agent log lines, and repeating under different loads and limits. That is slow and error-prone for people, and easy to get subtly wrong. So we made AI do the repetitive engineering, and kept people on the decisions.\n\nvulnbench is a single web console that runs a test, records everything the agent and the node do, and builds the report. It is one FastAPI process with SQLite and a plain-JavaScript UI, running on a lab VM.\n\nA run is one test definition: which clusters and nodes, how long, which load, which Uptycs queries to fire, and the agent's memory limit. The console enforces one run at a time and refuses a second with the running test's details.\n\nThe console talks to both clusters through kubectl and SSH, to the Uptycs cloud through read-only queries, and to the LLM through an AI gateway.\n\nAI worked at three levels. It built the tool, it ran and read the tests, and it sits inside the console for anyone who uses it.\n\nPeople kept the decisions. Changing a test's conditions, swapping an agent binary, or firing a query at the cloud needed an explicit OK each time.\n\nThe console went from v0.1 on 2026-11-06 to v0.106.17 on 2026-11-30: 179 logged releases, each through a test gate.\n\n| Tool or feature | What it does | Why we needed it | \n|---|---|---|\n| Test config + runner | Versioned test definitions; one run slot; live log, ETA and ticker | Repeatable runs that anyone can start and compare | \n| fdload | Multi-arch load generator: file descriptors, sockets, processes, env vars, CPU, per node | Real nodes are busy; an idle-node benchmark hides costs | \n| Memory-limit sweep and soak | Holds or steps the agent's memory limit for hours, then restores it | Find the smallest limit that survives a full scan | \n| qbench | Runs query variants side by side | Prove a cheaper SQL returns the same rows | \n| Query monitor | Every scheduled and live query: start, end, CPU, memory before, peak, kept | Tie each memory jump to the query that caused it | \n| Vulnerability report | Per scan: type (full, high, incremental), phases, download, scan and upload time, CVE counts | See where a scan spends time and memory | \n| Flow | The queries and log lines around any error, on one timeline | Answer \"what was the agent doing when this broke?\" | \n| Processes and Environment pages | Per-node process and env-var load, and what the agent saw | process_envs turned out to be an OOM trigger | \n| Agent-pod config | Memory and CPU limits and requests per test, restored after the run | Test 350Mi, 512Mi and 1000Mi without hand edits | \n| Upgrade | Lists agent versions from the Uptycs API, downloads and applies them | Retest each new build the same way | \n| Multi-cluster | One test across clusters and nodes, one combined report, per-cluster tabs | Compare x86 OpenShift with ppc64le | \n| Reports | Test report, classic report, vulnerability report, resource trends; doc export | Share results without opening the console | \n| Chat agent | LLM with console tools, confirm-before-change, token count per answer | Ask questions of the data in plain language | \n\nEvery signal carries a UTC timestamp and a node, so a memory spike, a query and a log line can be laid on the same axis. That alignment is what made root causes visible.\n\n| Source | Recorded | Interval | \n|---|---|---|\n| Probe | osqueryd worker and uptycs-protect memory (RSS, anon) and CPU, worker PID | 1 s | \n| Pod stats | Pod memory total vs anon vs page cache, restarts, OOM kills, osquery.db size | 5 min and per event | \n| Query monitor | Each query's run time, CPU, memory before, peak and kept; overlap with live queries | Per query run | \n| Agent log | Scan phases per OS, template downloads, result batches, upload errors, watchdog kills | Continuous | \n| Watcher | Worker restarts with old and new PID | Continuous | \n| Node and load | Node CPU, load average, file opens, TCP connects, process starts from fdload | Per run | \n| Kubernetes events | Pod replaced, OOMKilled, node not ready | Per event | \n| Uptycs cloud | Scan results: rows, CVE counts per system, scan type; read-only queries | Per scan | \n\nAt run end the console captures every node's agent logs and diagnostics into the run folder. The reports, alerts and AI notes are built from that folder, so a run can be re-analysed after the cluster has moved on.\n\nThe biggest single cost is a full vulnerability scan: one CentOS 7 container took the agent's worker from 125 MB to 418 MB in 36 seconds. Below are the issues we raised, each with the evidence the telemetry gave us.\n\n| Issue | Evidence | Impact | \n|---|---|---|\n| Scan filtered to one container also scans the host | Reported 684 packages; the container has 148, the host 496; host OS templates were downloaded too | Per-container scans cost a host scan each | \n| Agent's own memory figure understates the peak | Agent \"max watermark\" +144 MB vs measured +293 MB | Internal metrics can't be trusted for sizing | \n| Scan phases peak high | CentOS 9 phase +235 MiB; CentOS template set is 35.7 MB of JSON, about 495,000 templates | OOM at 512Mi during full scans | \n| process_envs under process load | A worker OOM-killed every 15 min with 50 load processes | Busy nodes OOM on a routine query | \n| Result batches exceed the cloud's body limit | 4 × \"body limit exceeded\" in the RHEL 7.9 phase, 8,192 vulns in batches of 2,048 | Some scan results may never reach the cloud | \n| Watchdog never acts | Auto-sized to 1,440 MB, above the 1000Mi pod limit; the memory-limit flag ignored | The kernel kills the pod before the agent protects itself | \n| Full scan on ppc64le under CPU load | Unloaded: 542 s, 8,286 packages, 66,329 vulns. At 50% CPU it passed 30 min and the watchdog killed it | No full scan completes on a busy Power node | \n| ppc chart default too small | 500Mi / 1 CPU was OOM-killed hourly; raised to 1000Mi / 4 CPU | Default install fails on Power | \n\n| Issue | Evidence | Impact | \n|---|---|---|\n| serial-getty restarting every ~10 s on every node | wtmp 36 MB, 93k rows, +8.4k rows a day; hourly `last` query averages 44 MB | Agent cost grows every day with no change | \n| Incremental scans refused before a full scan | \"Issued an incremental scan prior to a complete scan\" until one full scan completes | A node can go hours with no vulnerability data | \n| Cloud sync query times out during a full scan | Times out while the agent keeps scanning | The cloud's view lags the agent's | \n| Silent death after OOM | Container \"Running\" with no osqueryd for 3 days | No alert; looks healthy | \n\nThe AI found and fixed most of these, but several reached a run before they were caught.\n\nAI turned a months-long investigation into a four-week one, mainly by removing the wait between asking a question and having the tool to answer it.\n\n`last` query growing every day. Not one of those steps was in the original question.\nAI is fast and thorough, but it checks what it is told to check.\n\nThe agent built into the console earned its place when it stopped waiting to be asked. It watches the cluster, investigates incidents on its own, and reports what it finds.\n\nThe AI works only from evidence cut to the incident window. Its result is an alert, and any change it suggests waits for a person.\n\n| Capability | How it works | What it gave us | \n|---|---|---|\n| Incident investigation | A watcher checks for agent OOM kills, restarts and NotReady nodes; on each it collects pod status, agent logs from 15 min before, events, memory history and the node journal, then asks the AI for cause and next step | An OOM at 3 a.m. arrives with its evidence and a likely cause, not just a restart count | \n| Findings as alerts | Each AI finding becomes an alert on the ticker and Alerts page; a failed AI call retries 3 times and raises its own alert | Nothing the AI found is lost silently. We added this after an OOM had been investigated but nobody was told | \n| Read-only tools | About two dozen tools: runs, compare, query monitor, agent log, flow, threat-indicator downloads and scans | Answers cite real rows and log lines instead of guesses | \n| Confirm before change | Any write (config, test, kubectl, helm) stops at a Confirm / Decline card | Anyone can use the chat on a shared lab without risk | \n| Run comparison | The AI explains the difference between two runs: memory, scan times, alerts | Faster \"did this build help?\" answers | \n| UI sweep and self-fix | A sweep finds browser errors, failed API calls and server tracebacks; a fixer works in a separate git worktree, runs the tests, and proposes the change | Small UI bugs got fixed without a person opening the code | \n| Token frugality | Plain commands bypass the LLM; answer and tool caches; prompt caching; rolling history; per-chat budget; tokens shown on every message | Cost stays visible and low; repeated questions cost 0 tokens | \n\n| Measure | Value | \n|---|---|\n| Calendar time | 2026-11-03 to 2026-11-30 | \n| Benchmark runs | 52, up to 24 h each | \n| Clusters | 2: OpenShift on x86 (5 nodes), kubeadm on ppc64le (1 node) | \n| Console releases | 179, v0.1 to v0.106.17 | \n| Requirements logged | About 170 | \n| Automated tests per change | 444 API, 62 browser, plus Go tests for the load tool | \n| Agent issues raised | 8 in the agent, 4 in the cluster and cloud |", "url": "https://wpnews.pro/news/testing-kubernetes-vulnerability-scanning-with-ai-what-we-built-and-what-we", "canonical_source": "https://dev.to/daya_sankar_199320fda6882/testing-kubernetes-vulnerability-scanning-with-ai-what-we-built-and-what-we-found-pj4", "published_at": "2026-12-01 05:09:21+00:00", "updated_at": "2026-12-01 05:14:43.514722+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "mlops", "developer-tools"], "entities": ["Uptycs", "Kubernetes", "OpenShift", "vulnbench", "osquery", "FastAPI", "SQLite"], "also_reported_by": [], "takeaway": "Aligning per-second agent memory probes, query start/peak/end metrics and log lines on one UTC timeline exposed that the process_envs query was an OOM trigger and let the team find the smallest memory limit that survives a full scan.", "recommendation": {"advice": "When an agent OOMs, timestamp memory probes, query metrics and logs on one axis and sweep memory limits to find the smallest that survives a full scan.", "playbook": "production-ops", "playbook_url": "https://wpnews.pro/playbooks/production-ops"}, "alternates": {"html": "https://wpnews.pro/news/testing-kubernetes-vulnerability-scanning-with-ai-what-we-built-and-what-we", "markdown": "https://wpnews.pro/news/testing-kubernetes-vulnerability-scanning-with-ai-what-we-built-and-what-we.md", "text": "https://wpnews.pro/news/testing-kubernetes-vulnerability-scanning-with-ai-what-we-built-and-what-we.txt", "jsonld": "https://wpnews.pro/news/testing-kubernetes-vulnerability-scanning-with-ai-what-we-built-and-what-we.jsonld"}}