Draft
- David Collom
This RFC proposes a Kubernetes-native watcher that detects container images used by workloads in a cluster, resolves those images to immutable digests where possible, scans or queries vulnerability information using pluggable scanner drivers, normalises the results, and publishes actionable security events to Komodor.
The watcher is designed to be deployed into an individual Kubernetes cluster and configured using standard Kubernetes primitives such as ConfigMaps, Secrets, ServiceAccounts, and Helm values. It intentionally avoids CRDs for the initial implementation.
A key goal is to provide a strong and reviewable security model suitable for platform and security teams.
The watcher must never require hostPath mounts, runtime sockets, or privileged container access.
Kubernetes clusters commonly run workloads built from container images stored in private registries. Vulnerability scanners such as Snyk, Wiz, Trivy, and others may already identify risks in those images, but the findings are often disconnected from the operational context of the running workload.
Komodor provides a useful operational event timeline. Publishing image vulnerability findings into Komodor allows teams to correlate image risk with deployments, incidents, rollouts, and service health.
The goal is not to build another vulnerability scanner. The goal is to build a secure, low-noise bridge between running Kubernetes workloads, scanner findings, and Komodor events.
- Watch Kubernetes workloads in a single cluster.
- Extract container image references from supported workload types.
- Resolve mutable image tags to immutable digests where possible.
- Use scanner drivers to scan or query vulnerability findings.
- Support scanner implementations backed by CLIs or APIs.
- Require structured scanner output such as JSON or YAML.
- Normalise scanner-specific results into a common internal model.
- Publish meaningful vulnerability events to Komodor.
- Deduplicate scan results to avoid noisy repeat events.
- Use ConfigMaps and Secrets for configuration and credentials.
- Avoid CRDs for the initial implementation.
- Avoid Kubernetes Secret read RBAC.
- Avoid impersonation.
- Avoid workload mutation.
- Avoid admission webhooks.
- Avoid host-level access.
- Building a new vulnerability scanner.
- Replacing Snyk, Wiz, Trivy, or other scanner platforms.
- Mutating Kubernetes workloads.
- Blocking deployments.
- Acting as an admission controller.
- Reading application image pull secrets from namespaces.
- Impersonating workload ServiceAccounts.
- Mounting Docker, containerd, CRI-O, or Kubernetes node runtime sockets.
- Mounting node-local image stores.
- Requiring privileged containers.
- Requiring hostPath mounts.
- Introducing CRDs in the first version.
The watcher should be acceptable to platform and security teams as a security tool with a constrained runtime model.
The watcher must never require:
hostPathmounts- Docker socket access
- containerd socket access
- CRI-O socket access
- Kubernetes node filesystem access
- privileged containers
- host PID namespace access
- host network namespace access
- host IPC namespace access
- runtime socket access of any kind
All image inspection must happen through one of the following safe paths:
- registry access using the watcher Pod's own runtime identity
- scanner APIs
- scanner processes running inside the watcher Pod
- structured scanner output returned from a non-privileged process
The watcher should only require read-only access to workload metadata.
It must not require Kubernetes API permissions to:
- read Secrets
- impersonate users or ServiceAccounts
- create Pods
- update workloads
- delete workloads
- exec into Pods
- read Pod logs
- create admission webhooks
- mutate cluster state outside of its own optional state storage
The watcher should rely on the ServiceAccount and Pod context it runs under.
Registry access should be configured using standard Kubernetes mechanisms, for example:
- ServiceAccount
imagePullSecrets - externally managed Secrets using ESO
- Kyverno or OPA/Gatekeeper policies that inject or validate image pull configuration
- cloud-native workload identity where scanner tooling supports it
The watcher should not discover or read application imagePullSecrets.
The watcher should not require Kubernetes Secret read RBAC.
A scanner driver is acceptable only if it can operate without requiring:
- host mounts
- runtime sockets
- privileged mode
- Kubernetes Secret API access
- workload impersonation
- node-local image cache access
Scanner CLI drivers must:
- execute a known binary path
- pass arguments directly without shell interpolation
- enforce a context timeout
- cap stdout and stderr size
- require JSON, YAML, or another deterministic structured output format
- parse scanner output into the internal
ScanResultmodel - never require privileged container access
Kubernetes Workload Watcher
↓
Image Extractor
↓
Digest Resolver
↓
Scanner Registry
↓
Finding Normaliser
↓
Policy Evaluator
↓
Komodor Event Publisher
↓
State / Dedupe Store
The watcher observes supported workload resources and detects image references from their Pod templates.
Initial supported workload kinds:
- Deployment
- StatefulSet
- DaemonSet
- Job
- CronJob
Possible future workload kinds:
- Argo Rollout
- Knative Service
- OpenShift DeploymentConfig
The image extractor reads images from:
containersinitContainers- optionally
ephemeralContainers, if useful later
It should retain workload context:
- cluster name
- namespace
- workload kind
- workload name
- container name
- image string
- labels
- annotations
The digest resolver attempts to resolve image tags to immutable digests.
Example:
ghcr.io/acme/checkout-api:1.4.2
becomes:
ghcr.io/acme/checkout-api@sha256:abc123...
Digest-first tracking reduces noise and avoids treating mutable tags as stable identifiers.
The resolver should use go-containerregistry and Kubernetes-aware keychain behaviour where possible.
The resolver must use the watcher Pod's own runtime identity and must not read workload image pull Secrets.
The scanner registry loads configured scanner drivers and invokes them for resolved images.
The controller-facing scanner interface should be intentionally simple.
type Scanner interface {
Name() string
Scan(ctx context.Context, image ImageRef) (*ScanResult, error)
}The controller should not need to know whether a scanner uses:
- a vendor API
- a CLI process
- existing scanner findings
- registry-sourced image analysis
- an uploaded artefact
That is the responsibility of the scanner driver.
Initial candidate drivers:
- Trivy
- Snyk
- Wiz
The first implementation should prioritise one scanner driver to validate the abstraction.
Trivy is a strong candidate for early development because it can provide a self-contained registry-sourced scan flow suitable for local development and demos.
Snyk and Wiz drivers may initially be implemented as lookup or API-backed drivers, depending on the available API capabilities and organisational scanner configuration.
Scanner-specific results should be converted into a shared model.
Example internal structures:
type ImageRef struct {
Original string
Registry string
Repository string
Tag string
Digest string
Resolved string
}
type ScanResult struct {
Scanner string
Image ImageRef
ScannedAt time.Time
Summary VulnerabilitySummary
Findings []Finding
ReportURL string
SBOMURL string
}
type VulnerabilitySummary struct {
Critical int
High int
Medium int
Low int
Unknown int
}
type Finding struct {
ID string
CVE string
Package string
Installed string
Fixed string
Severity Severity
Title string
URL string
Exploitable bool
}The policy evaluator decides whether a result should be published.
Example policy options:
- minimum severity
- publish only on first seen
- publish only on severity increase
- publish when new critical findings appear
- optionally publish clean scans
- include top N findings
- dedupe TTL
The publisher sends normalised vulnerability events to Komodor.
Events should be scoped to the affected workload or service where possible.
Example event details:
{
"scanner": "trivy",
"image": "ghcr.io/acme/checkout-api@sha256:abc123",
"container": "checkout-api",
"critical": "2",
"high": "7",
"medium": "14",
"topFindings": "CVE-2026-1234,CVE-2025-9876,CVE-2024-1111",
"digest": "sha256:abc123",
"policy": "minimumSeverity=high"
}The watcher should avoid repeatedly publishing the same vulnerability event.
For v1, state should be stored without a CRD.
Possible options:
- ConfigMap state
- local file state with a mounted volume
- SQLite with a PVC
For the simplest Kubernetes-native MVP, use ConfigMap-backed state.
State should include:
- image digest
- scanner name
- workload reference
- last scanned timestamp
- last published timestamp
- vulnerability summary
- fingerprint
The fingerprint should be derived from stable result data such as:
- scanner name
- image digest
- severity counts
- top finding IDs
- relevant fix availability information
Configuration should be supplied through a ConfigMap.
Example:
clusterName: prod-eks-01
namespaces:
include:
- production
- platform
exclude:
- kube-system
- cert-manager
workloads:
kinds:
- Deployment
- StatefulSet
- DaemonSet
- Job
- CronJob
registry:
resolveDigest: true
scanners:
- name: trivy
type: trivy
enabled: true
command:
binary: /usr/local/bin/trivy
timeout: 5m
- name: snyk
type: snyk
enabled: false
command:
binary: /usr/local/bin/snyk
timeout: 5m
publishing:
minimumSeverity: high
includeTopFindings: 5
publishCleanScans: false
dedupeTTL: 24hCredentials should be provided through normal Pod runtime mechanisms.
Examples:
- environment variables sourced from Secrets
- mounted files sourced from Secrets
- projected ServiceAccount tokens
- cloud workload identity
- scanner-specific configuration files
The watcher application should not need Kubernetes API permissions to read Secrets.
Example environment variables:
env:
- name: KOMODOR_API_KEY
valueFrom:
secretKeyRef:
name: komodor-security-reporter-komodor
key: api-key
- name: SNYK_TOKEN
valueFrom:
secretKeyRef:
name: komodor-security-reporter-snyk
key: tokenThe watcher should use minimal read-only RBAC.
Example:
rules:
- apiGroups: [""]
resources:
- namespaces
verbs:
- get
- list
- watch
- apiGroups: ["apps"]
resources:
- deployments
- statefulsets
- daemonsets
- replicasets
verbs:
- get
- list
- watch
- apiGroups: ["batch"]
resources:
- jobs
- cronjobs
verbs:
- get
- list
- watchThe watcher should not require:
resources:
- secretsThe watcher should not require:
verbs:
- impersonateThe watcher should run with a restrictive security context.
Example:
securityContext:
runAsNonRoot: true
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false
capabilities:
drop:
- ALLIf scanner CLIs require cache directories, those should be backed by emptyDir or a PVC.
Example:
volumeMounts:
- name: tmp
mountPath: /tmp
- name: scanner-cache
mountPath: /var/cache/komodor-security-reporter
volumes:
- name: tmp
emptyDir: {}
- name: scanner-cache
emptyDir: {}No hostPath volumes should be used.
Scanner CLI drivers may execute scanner binaries when the scanner provides structured output.
Scanner commands must be executed without shell interpolation.
Acceptable:
exec.CommandContext(ctx, "trivy", "image", "--format", "json", image.Resolved)Not acceptable:
exec.CommandContext(ctx, "sh", "-c", "trivy image " + image.Resolved)Scanner execution should include:
- timeout enforcement
- stdout size limit
- stderr size limit
- structured output validation
- clear error wrapping
- scanner-specific parser tests
The watcher should publish only meaningful events.
Suggested defaults:
publishing:
minimumSeverity: high
publishCleanScans: false
includeTopFindings: 5
dedupeTTL: 24hEvents should be published when:
- an image is scanned for the first time and findings exceed policy
- severity increases
- new critical findings appear
- the result fingerprint changes meaningfully
Events should not be published when:
- the same result has already been published recently
- findings are below configured policy
- only noisy scanner metadata changes
2 critical vulnerabilities found in checkout-api
{
"cluster": "prod-eks-01",
"namespace": "production",
"workloadKind": "Deployment",
"workloadName": "checkout-api",
"container": "checkout-api",
"scanner": "trivy",
"image": "ghcr.io/acme/checkout-api@sha256:abc123",
"critical": "2",
"high": "7",
"medium": "14",
"low": "3",
"topFindings": "CVE-2026-1234,CVE-2025-9876,CVE-2024-1111",
"reportURL": "https://scanner.example/report/123",
"fingerprint": "sha256:deadbeef"
}The watcher should be deployed using Helm.
Initial chart resources:
- ServiceAccount
- ClusterRole or Role
- ClusterRoleBinding or RoleBinding
- ConfigMap
- Deployment
- optional Secret templates for development only
Production environments should normally manage Secrets externally.
Example Helm values:
serviceAccount:
create: true
name: komodor-security-reporter
imagePullSecrets:
- name: registry-readonly-auth
rbac:
create: true
scope: cluster
config:
clusterName: prod-eks-01
namespaces:
include:
- production
- platform
exclude:
- kube-system
- cert-manager
komodor:
apiKeySecret:
name: komodor-security-reporter-komodor
key: api-key
scanner:
trivy:
enabled: true
cache:
emptyDir: trueThe watcher should handle failures gracefully.
Examples:
- registry digest resolution failure
- scanner unavailable
- scanner timeout
- scanner output parse failure
- Komodor API failure
- state persistence failure
Failures should be logged with enough context to debug:
- scanner name
- image reference
- namespace
- workload kind
- workload name
- container name
Retries should use bounded exponential backoff.
The watcher should avoid publishing scanner failure events by default unless explicitly configured, to avoid noise.
The watcher should expose Prometheus metrics.
Suggested metrics:
image_vuln_watcher_images_observed_total
image_vuln_watcher_images_resolved_total
image_vuln_watcher_image_resolution_errors_total
image_vuln_watcher_scans_total
image_vuln_watcher_scan_errors_total
image_vuln_watcher_scan_duration_seconds
image_vuln_watcher_events_published_total
image_vuln_watcher_event_publish_errors_total
image_vuln_watcher_dedupe_hits_total
Structured logs should include:
- cluster
- namespace
- workload kind
- workload name
- container
- image
- digest
- scanner
- correlation ID where applicable
- Create Go project structure.
- Add Kubernetes workload watchers.
- Extract images from workload Pod templates.
- Add namespace include/exclude filtering.
- Add basic config loading from ConfigMap-mounted YAML.
- Add
go-containerregistry. - Resolve image tags to digests.
- Use watcher runtime identity/keychain where possible.
- Add tests for image reference parsing and digest resolution logic.
- Add
Scannerinterface. - Add normalised
ScanResultmodel. - Add scanner registry.
- Add command runner abstraction for CLI-backed scanners.
- Add stdout/stderr limits and timeout handling.
- Implement Trivy driver.
- Parse Trivy JSON output.
- Add parser fixtures.
- Add table-driven tests.
- Implement Komodor event client.
- Add event mapping.
- Add severity mapping.
- Add retry/backoff.
- Add unit tests around event payloads.
- Add fingerprinting.
- Add ConfigMap-backed state store.
- Add dedupe policy.
- Add tests for publish/no-publish decisions.
- Add ServiceAccount.
- Add minimal RBAC.
- Add Deployment.
- Add ConfigMap.
- Add restrictive security context.
- Add optional cache volumes.
- Add README security model.
- Should state initially be ConfigMap-backed or file-backed with an
emptyDir/PVC? - Should the first scanner driver be Trivy, Snyk, or Wiz?
- Should scanner failures optionally publish Komodor warning events?
- How should Komodor service mapping be derived from Kubernetes workload metadata?
- Should Rollouts be included in v1 or deferred?
- Should scan concurrency be global, per namespace, or per scanner?
- Should clean scans ever be published by default?
- How long should dedupe state be retained?
Use ConfigMaps, Secrets, ServiceAccounts, and Helm values for the first version.
Rationale:
- simpler deployment
- lower operational complexity
- easier to review
- sufficient for single-cluster deployment
The watcher should not request API permissions to read Secrets.
Rationale:
- stronger security posture
- easier security review
- avoids reading application Secrets
- aligns with platform-managed credential models
The watcher should not impersonate workload ServiceAccounts.
Rationale:
- impersonation can be difficult to reason about
- broad impersonation increases review complexity
- workload image pull access does not necessarily imply Secret read API access
The watcher must never require hostPath mounts, runtime sockets, or privileged container access.
Rationale:
- preserves strong security posture
- avoids node-level blast radius
- avoids container runtime coupling
- keeps scanner drivers constrained and reviewable
Scanner implementation details should remain internal to each scanner driver.
Rationale:
- keeps the controller simple
- avoids leaking vendor-specific behaviour
- keeps the scanner contract focused on input and normalised output
Options:
komodor-image-vulnerability-watcherkube-image-risk-publisherimage-vuln-event-watcherkomodor-image-risk-watcher
Recommended initial name:
komodor-image-vulnerability-watcher
cmd/komodor-security-reporter/
main.go
internal/config/
config.go
loader.go
internal/controller/
workload_controller.go
image_extractor.go
internal/registry/
resolver.go
image_ref.go
internal/scanners/
scanner.go
result.go
severity.go
internal/scanners/command/
runner.go
limited_buffer.go
internal/scanners/trivy/
scanner.go
parser.go
parser_test.go
testdata/
internal/komodor/
client.go
publisher.go
event.go
internal/policy/
evaluator.go
fingerprint.go
internal/state/
store.go
configmap_store.go
internal/metrics/
metrics.go
package scanners
import (
"context"
"time"
)
type Scanner interface {
Name() string
Scan(ctx context.Context, image ImageRef) (*ScanResult, error)
}
type ImageRef struct {
Original string
Registry string
Repository string
Tag string
Digest string
Resolved string
}
type ScanResult struct {
Scanner string
Image ImageRef
ScannedAt time.Time
Summary VulnerabilitySummary
Findings []Finding
ReportURL string
SBOMURL string
}
type VulnerabilitySummary struct {
Critical int
High int
Medium int
Low int
Unknown int
}
type Severity string
const (
SeverityCritical Severity = "critical"
SeverityHigh Severity = "high"
SeverityMedium Severity = "medium"
SeverityLow Severity = "low"
SeverityUnknown Severity = "unknown"
)
type Finding struct {
ID string
CVE string
Package string
Installed string
Fixed string
Severity Severity
Title string
URL string
Exploitable bool
}package command
import (
"bytes"
"context"
"fmt"
"io"
"os/exec"
)
type Runner struct {
StdoutLimitBytes int64
StderrLimitBytes int64
}
func (r Runner) Run(ctx context.Context, name string, args ...string) ([]byte, []byte, error) {
cmd := exec.CommandContext(ctx, name, args...)
var stdout bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &limitedWriter{
writer: &stdout,
limit: r.StdoutLimitBytes,
}
cmd.Stderr = &limitedWriter{
writer: &stderr,
limit: r.StderrLimitBytes,
}
if err := cmd.Run(); err != nil {
return stdout.Bytes(), stderr.Bytes(), fmt.Errorf("run command %q: %w", name, err)
}
return stdout.Bytes(), stderr.Bytes(), nil
}
type limitedWriter struct {
writer io.Writer
limit int64
seen int64
}
func (w *limitedWriter) Write(p []byte) (int, error) {
remaining := w.limit - w.seen
if remaining <= 0 {
return len(p), nil
}
if int64(len(p)) > remaining {
p = p[:remaining]
}
n, err := w.writer.Write(p)
w.seen += int64(n)
return len(p), err
}