Skip to content

Latest commit

 

History

History
755 lines (588 loc) · 28.4 KB

API.md

File metadata and controls

755 lines (588 loc) · 28.4 KB

Kubevuln API Reference

This document provides detailed documentation for the Kubevuln REST API.

Overview

Kubevuln exposes a REST API on port 8080 for vulnerability scanning operations. The API follows REST conventions and returns responses in the RFC 7807 Problem Details format, except for requests rejected by authentication.


Table of Contents


Base URL

http://<kubevuln-host>:8080

In-cluster, this is typically:

http://kubevuln.kubescape.svc.cluster.local:8080

Authentication

Every route except /v1/liveness, /v1/readiness and /metrics requires a Kubernetes service-account token in an Authorization: Bearer header. Requests without a valid token, or from a caller that RBAC does not allow, are rejected before they reach the handlers below. See API authentication for the token audience, the RBAC it checks, and the environment it needs.

The curl examples in this document leave the header out. They work as written against a local instance started with KS_API_AUTH_DISABLED=true; against a cluster, add -H "Authorization: Bearer $TOKEN".

For scanning private container registries, credentials are passed in the request payload.


Health Endpoints

Liveness Probe

Check if the server is running.

GET /v1/liveness

Response

Status Description
200 OK Server is running

Example

curl http://localhost:8080/v1/liveness
{
  "status": 200,
  "title": "OK"
}

Readiness Probe

Check if the server is ready to process requests (vulnerability database is loaded).

GET /v1/readiness

Response

Status Description
200 OK Server is ready
503 Service Unavailable Vulnerability database not loaded

Example

curl http://localhost:8080/v1/readiness

Success response:

{
  "status": 200,
  "title": "OK"
}

Not ready response:

{
  "status": 503,
  "title": "Service Unavailable"
}

Metrics

Prometheus exposition-format metrics for the HTTP controller and its worker pool. Served on the same port as the health endpoints, with no auth or network guard -- fine for how kubevuln is deployed today (the Service isn't public and the metrics carry no tenant/image identifiers), but scraping it in a cluster requires a chart-side change (prometheus.io/scrape annotations or a ServiceMonitor) since the endpoint shipping here doesn't by itself get collected.

GET /metrics

Instruments

Name Type Labels Description
kubevuln_scans_completed_total counter endpoint, outcome (success/partial/error), reason Scans completed by the HTTP controller's worker pool
kubevuln_scan_duration_seconds histogram endpoint, outcome, reason Duration of a scan job, measured from when it starts running (not from when it was queued)
kubevuln_scan_rejections_total counter endpoint, reason (too_many_requests/invalid_request) Requests rejected at validation time, before being queued
kubevuln_worker_pool_queue_depth gauge - Number of scan jobs currently waiting in the worker pool
kubevuln_exceptions_degraded_total counter - Total number of times CVE exception fetching degraded (partially failed) during a scan
kubevuln_exceptions_matched_total counter sourceKind (SecurityException/ClusterSecurityException) Total number of CVE findings suppressed by a SecurityException/ClusterSecurityException
kubevuln_exceptions_expired_total counter sourceKind Total number of SecurityException/ClusterSecurityException CRDs skipped because their expiresAt has passed
kubevuln_exceptions_active gauge - Number of CVE exception policies (cloud + CRD-based) in force for the most recently evaluated scan
kubevuln_scan_fallbacks_total counter component (in_process/sidecar), category (registry_auth/platform/size_classification/pull_semaphore), strategy (anonymous/ecr/gcp_adc/image_too_large/incomplete/platform_mismatch/sbom_too_large), outcome (classified/failed/succeeded) Fallbacks taken while resolving or classifying a scan, such as retrying a 401 with cloud credentials or falling back to anonymous access. category="pull_semaphore" (in-process adapter only) means the scan gave up waiting to acquire the pull/cataloging semaphore because a previous scan is still holding it — distinct from an ordinary slow pull or cataloging pass (category="size_classification"), since it signals that some other, unrelated scan is stuck
kubevuln_scan_source_resolution_total counter component, outcome (first_pass_success/fallback_assisted_success/fallback_failed/first_pass_failure) Whether pulling the image succeeded outright or only after a fallback, which is what distinguishes a healthy registry from one that works only by retry
kubevuln_registry_auth_cache_total counter strategy (ecr/gcp_adc), result (hit/miss/coalesced) Registry auth credential lookups, by what each one cost: hit served from cache, coalesced served by another concurrent lookup's in-flight fetch, miss reached the cloud provider. miss is therefore the number of upstream credential fetches
kubevuln_singleflight_hits_total counter target (sbom_generation) Scan requests that arrived while the same work was already in flight and were served by it, so they did not generate an SBOM of their own. Counts the requests spared the work, not the one doing it
kubevuln_retry_attempts_total counter operation (source_resolution/sbom_generation), outcome (attempt/success/exhausted) Retry attempts executed during transient error backoff, distinguishing individual attempts, successes after retry, and exhausted retries
kubevuln_external_vex_sources_total counter format (openvex/csaf, or other for a format kubevuln does not support), result (ingested/failed) Configured external VEX sources, counted once per source each time the feeds are fetched, which happens once for every image a scan evaluates. failed covers a fetch, validation or staging failure; the source URL is never a label, since it can carry a token
kubevuln_external_vex_scans_total counter outcome (applied/no_documents/apply_failed/unsupported) Counts each actual SBOM evaluation while external VEX sources are configured. applied means Grype evaluated the SBOM with at least one ingested document (not that any statement matched). The other outcomes describe evaluations attempted without external VEX: every source failed (no_documents), Grype could not apply the documents (apply_failed), or the CVE scanner cannot apply VEX (unsupported). With storage enabled, each successful per-container path evaluates both the full SBOM and the relevant SBOM, normally producing two counts. When a fallback ScanSBOM call fails, the counter may still be incremented even though the caller skips the scan and produces no findings. Neither external VEX instrument emits a series when no sources are configured

reason is "none" for a success/partial outcome, and otherwise one of the bounded scanfailure.Reason* constants from armoapi-go/scanfailure -- the same classification already sent to the backend via ReportScanFailure (see scan-failure-reporting.md) -- falling back to "unexpected_error" for an error outcome that carries no specific classification. Required local vulnerability manifest or summary persistence failures use the local reason result_storage_failed, including when cloud upload succeeds. This lets an operator watching only /metrics distinguish, for example, a registry auth failure from an oversized image without needing access to the backend's failure-report stream or pod logs.

Example

curl http://localhost:8080/metrics

Diagnostics

Reports the scanner configuration actually in effect, which is not always the configuration that was requested: if SBOM_SCANNER_SOCKET is set but the sidecar never becomes ready within scannerReadinessTimeout, kubevuln logs the failure and falls back to the in-process Syft adapter. scanMode is how you tell which one is running.

Endpoint: GET /v1/diagnostics

Response: 200 OK

{
  "scanMode": "sidecar",
  "sbomCreatorVersion": "v1.55.0",
  "cveScannerVersion": "v0.121.0-matching-adaptive",
  "cveDBVersion": "5e8b0e2c9f",
  "scanTimeout": "5m0s",
  "scannerReadinessTimeout": "1m0s",
  "storageEnabled": true,
  "riskAcceptanceEnabled": true,
  "queueDepth": 0,
  "scanConcurrency": 1,
  "maxQueueDepth": 0,
  "vexGenerationEnabled": true,
  "externalVEXSources": 1
}
Field Type Description
scanMode string sidecar when SBOMs are generated by the sbom-scanner container, in-process when Syft runs inside kubevuln
sbomCreatorVersion string Syft version in use
cveScannerVersion string Grype version, suffixed with the active cveMatchingMode
cveDBVersion string Checksum of the loaded Grype vulnerability database; empty until the first load completes
scanTimeout duration Effective scanTimeout
scannerReadinessTimeout duration Effective scannerReadinessTimeout
storageEnabled bool Whether SBOMs and CVE manifests are persisted as CRDs
riskAcceptanceEnabled bool Whether SecurityException / ClusterSecurityException CRDs are applied
queueDepth int Scan jobs currently waiting for a worker, the same value as the kubevuln_worker_pool_queue_depth metric
scanConcurrency int Scans run at once, from scanConcurrency
maxQueueDepth int Scans accepted but not yet finished (queued or running) before new requests are rejected with 503, from maxQueueDepth; 0 means unbounded, which is also how a negative configured value is reported
vexGenerationEnabled bool Whether VEX documents are published. Requires both vexGeneration and storage, so it is false when only the flag is set (see VEX.md)
externalVEXSources int Number of external VEX feeds configured through vexSources / VEXSOURCES. Only the count is reported, since a feed URL may carry a token in its query string

Always returns 200 once the request is authorized. queueDepth, scanConcurrency and maxQueueDepth come from the HTTP controller itself; everything else comes from the diagnostics provider set up at startup. When the controller was built without that provider, those other fields keep their zero values, so empty versions and scan mode mean "not wired up" rather than "nothing configured".

curl -s http://localhost:8080/v1/diagnostics | jq

Scan Endpoints

All scan endpoints accept a JSON payload and return immediately with a 200 OK status. The actual scanning is performed asynchronously in a worker pool.

Get Scan Status

Look up the current lifecycle state for a previously submitted jobID.

GET /v1/scanStatus/:jobID

Response Body

Field Type Description
jobID string Submitted job identifier
endpoint string Async scan endpoint handling this job
state string One of queued, running, succeeded, failed, or abandoned
phase string Current service phase. Reported values include queued, running, relevancy_lookup, cve_lookup, sbom_generation, sbom_storage, cve_matching, result_storage, result_upload, completed, and abandoned
reason string Machine readable terminal reason for failed or abandoned jobs
acceptedAt string RFC3339 timestamp when the request was accepted
startedAt string RFC3339 timestamp when execution began. Omitted while the job is still queued
finishedAt string RFC3339 timestamp when the job reached a terminal state. Omitted until the job succeeds, fails, or is abandoned
updatedAt string RFC3339 timestamp of the latest lifecycle transition

Response

Status Description
200 OK Job status found
404 Not Found Unknown jobID

Example

curl http://localhost:8080/v1/scanStatus/sbom-gen-001
{
  "jobID": "sbom-gen-001",
  "endpoint": "generateSBOM",
  "state": "running",
  "phase": "sbom_generation",
  "acceptedAt": "2026-08-12T12:00:00Z",
  "startedAt": "2026-08-12T12:00:01Z",
  "updatedAt": "2026-08-12T12:00:01Z"
}

Generate SBOM

Generate a Software Bill of Materials (SBOM) for a container image.

POST /v1/sbomCreation

Request Body

Field Type Required Description
imageTag string Yes Full image reference (e.g., nginx:1.24)
imageHash string No Image digest (e.g., sha256:abc123...)
wlid string No Workload ID
jobID string No Unique job identifier
containerName string No Container name
parentJobID string No Parent job ID for tracking
credentialslist array No Registry credentials
args object No Additional arguments
instanceID string No Instance identifier

Response

Status Description
200 OK Request accepted, SBOM generation started
400 Bad Request Invalid request payload or validation failed
429 Too Many Requests Registry rate limit hit on a previous pull for this image
503 Service Unavailable Scan admission capacity is full (positive maxQueueDepth reached; unset or non-positive means unbounded admission); retry later. Unrelated to /v1/readiness
409 Conflict jobID already belongs to a scan that is still queued or running; retry with a fresh jobID, or wait for the existing one to finish

Example

curl -X POST http://localhost:8080/v1/sbomCreation \
  -H "Content-Type: application/json" \
  -d '{
    "imageTag": "nginx:1.24",
    "imageHash": "sha256:0463a96ac74b84a8a1b23c1810d89d03f0eb2a3b5a1c41fb5d4e1da4f5c9c7c0",
    "jobID": "sbom-gen-001"
  }'
{
  "status": 200,
  "title": "OK",
  "detail": "ImageHash=nginx@sha256:0463a96ac74b84a8a1b23c1810d89d03f0eb2a3b5a1c41fb5d4e1da4f5c9c7c0"
}

Scan Image for CVEs

Scan a container image for known vulnerabilities.

POST /v1/scanImage

Request Body

Field Type Required Description
imageTag string Yes Full image reference
imageHash string Yes Image digest
wlid string Yes Workload ID
jobID string No Unique job identifier
containerName string No Container name
parentJobID string No Parent job ID
credentialslist array No Registry credentials
args object No Additional arguments
instanceID string No Instance identifier
lastAction int No Last action indicator

Response

Status Description
200 OK Request accepted, CVE scan started
400 Bad Request Invalid request payload or validation failed
429 Too Many Requests Registry rate limit hit on a previous pull for this image
503 Service Unavailable Scan admission capacity is full (positive maxQueueDepth reached; unset or non-positive means unbounded admission); retry later. Unrelated to /v1/readiness
409 Conflict jobID already belongs to a scan that is still queued or running; retry with a fresh jobID, or wait for the existing one to finish

Example

curl -X POST http://localhost:8080/v1/scanImage \
  -H "Content-Type: application/json" \
  -d '{
    "imageTag": "nginx:1.24",
    "imageHash": "sha256:0463a96ac74b84a8a1b23c1810d89d03f0eb2a3b5a1c41fb5d4e1da4f5c9c7c0",
    "wlid": "wlid://cluster-prod/namespace-default/deployment-nginx",
    "jobID": "cve-scan-001",
    "containerName": "nginx"
  }'
{
  "status": 200,
  "title": "OK",
  "detail": "Wlid=wlid://cluster-prod/namespace-default/deployment-nginx, ImageHash=nginx@sha256:0463a96ac74b84a8a1b23c1810d89d03f0eb2a3b5a1c41fb5d4e1da4f5c9c7c0"
}

Scan Registry Image

Scan an image directly from a container registry (without workload context).

POST /v1/scanRegistryImage

Request Body

Field Type Required Description
imageTag string Yes Full image reference
jobID string No Unique job identifier
parentJobID string No Parent job ID
credentialslist array No Registry credentials
args object No Additional arguments

Response

Status Description
200 OK Request accepted, registry scan started
400 Bad Request Invalid request payload or validation failed
429 Too Many Requests Registry rate limit hit on a previous pull for this image
503 Service Unavailable Scan admission capacity is full (positive maxQueueDepth reached; unset or non-positive means unbounded admission); retry later. Unrelated to /v1/readiness
409 Conflict jobID already belongs to a scan that is still queued or running; retry with a fresh jobID, or wait for the existing one to finish

Example

curl -X POST http://localhost:8080/v1/scanRegistryImage \
  -H "Content-Type: application/json" \
  -d '{
    "imageTag": "ghcr.io/kubescape/kubevuln:latest",
    "jobID": "registry-scan-001",
    "credentialslist": [
      {
        "username": "token",
        "password": "ghp_xxxxxxxxxxxx",
        "serveraddress": "ghcr.io"
      }
    ]
  }'
{
  "status": 200,
  "title": "OK",
  "detail": "ImageTag=ghcr.io/kubescape/kubevuln:latest"
}

Application Profile Scan

Scan based on a container's application profile for relevancy-filtered vulnerabilities.

POST /v1/applicationProfileScan

Request Body

Field Type Required Description
wlid string Yes Workload ID
args.name string Yes Profile name
args.namespace string Yes Profile namespace
jobID string No Unique job identifier
parentJobID string No Parent job ID
credentialslist array No Registry credentials

Response

Status Description
200 OK Request accepted, profile scan started
400 Bad Request Invalid request payload or validation failed
503 Service Unavailable Scan admission capacity is full (positive maxQueueDepth reached; unset or non-positive means unbounded admission); retry later. Unrelated to /v1/readiness
409 Conflict jobID already belongs to a scan that is still queued or running; retry with a fresh jobID, or wait for the existing one to finish

Example

curl -X POST http://localhost:8080/v1/applicationProfileScan \
  -H "Content-Type: application/json" \
  -d '{
    "wlid": "wlid://cluster-prod/namespace-default/deployment-nginx",
    "jobID": "profile-scan-001",
    "args": {
      "name": "nginx-profile",
      "namespace": "default"
    }
  }'
{
  "status": 200,
  "title": "OK",
  "detail": "Wlid=wlid://cluster-prod/namespace-default/deployment-nginx, Name=nginx-profile, Namespace=default"
}

Data Models

WebsocketScanCommand

The main request payload for scan operations.

{
  "imageTag": "string",
  "imageHash": "string",
  "wlid": "string",
  "jobID": "string",
  "containerName": "string",
  "parentJobID": "string",
  "lastAction": 0,
  "instanceID": "string",
  "credentialslist": [
    {
      "username": "string",
      "password": "string",
      "serveraddress": "string",
      "identitytoken": "string"
    }
  ],
  "args": {
    "key": "value"
  },
  "session": {
    "jobIDs": ["string"]
  }
}

RegistryCredentials

Credentials for accessing private container registries.

Field Type Description
username string Registry username
password string Registry password or token
serveraddress string Registry server address
identitytoken string Identity token (alternative to password)

Problem Details Response

All responses follow RFC 7807, except the authentication rejections described under HTTP Status Codes.

{
  "status": 200,
  "title": "OK",
  "detail": "Additional information about the response"
}
Field Type Description
status int HTTP status code
title string Short, human-readable summary
detail string Detailed explanation (optional)

Error Handling

HTTP Status Codes

Code Meaning When
200 OK Request accepted
400 Bad Request Invalid JSON, missing required fields, or validation failed
401 Unauthorized Missing, malformed, or rejected bearer token (API authentication)
403 Forbidden The token is valid but RBAC does not allow the request (API authentication)
409 Conflict A scan endpoint's jobID already belongs to a scan that is still queued or running
429 Too Many Requests Registry rate limit hit on a previous pull for this image
500 Internal Server Error Internal error
503 Service Unavailable Three distinct causes, unrelated to each other: /v1/readiness reports it when the vulnerability DB isn't loaded, a scan endpoint reports it when scan admission capacity is full (positive maxQueueDepth reached), and any authenticated route reports it when the token could not be checked because the Kubernetes API server was unreachable or returned an error

The 401, 403, and authentication 503 responses come from the authentication middleware, so their body is {"error": "...", "reason": "..."} rather than the Problem Details format above.

Common Errors

Invalid JSON

{
  "status": 400,
  "title": "Bad Request"
}

Validation Error

{
  "status": 400,
  "title": "Bad Request",
  "detail": "ImageHash=..."
}

Examples

Complete Scan Workflow

  1. Check service readiness:
curl http://localhost:8080/v1/readiness
  1. Generate SBOM:
curl -X POST http://localhost:8080/v1/sbomCreation \
  -H "Content-Type: application/json" \
  -d '{
    "imageTag": "nginx:1.24",
    "imageHash": "sha256:0463a96ac74b84a8a1b23c1810d89d03f0eb2a3b5a1c41fb5d4e1da4f5c9c7c0",
    "jobID": "workflow-sbom-001"
  }'
  1. Scan for CVEs:
curl -X POST http://localhost:8080/v1/scanImage \
  -H "Content-Type: application/json" \
  -d '{
    "imageTag": "nginx:1.24",
    "imageHash": "sha256:0463a96ac74b84a8a1b23c1810d89d03f0eb2a3b5a1c41fb5d4e1da4f5c9c7c0",
    "wlid": "wlid://cluster-prod/namespace-default/deployment-nginx",
    "jobID": "workflow-cve-001"
  }'

Scanning Private Registry Images

curl -X POST http://localhost:8080/v1/scanRegistryImage \
  -H "Content-Type: application/json" \
  -d '{
    "imageTag": "private.registry.com/myapp:v1.0.0",
    "jobID": "private-scan-001",
    "credentialslist": [
      {
        "username": "myuser",
        "password": "mypassword",
        "serveraddress": "private.registry.com"
      }
    ]
  }'

Scanning with HTTP Registry (Insecure)

For development registries using HTTP:

curl -X POST http://localhost:8080/v1/scanRegistryImage \
  -H "Content-Type: application/json" \
  -d '{
    "imageTag": "localhost:5000/myapp:latest",
    "jobID": "insecure-scan-001",
    "args": {
      "useHTTP": true,
      "skipTLSVerify": true
    }
  }'

Requesting a Specific Image Platform

For multi-arch images, request a specific OS/architecture (OCI format os/arch[/variant], or a bare arch such as arm64) via the platform arg. An operator can populate this from the scanned Pod's node architecture. Do not rely on leaving this unset for a multi-arch image: kubevuln then silently resolves whichever platform variant matches its own scanning process's architecture, not the target workload's. Requesting the platform explicitly makes fresh multi-arch image resolution deterministic and correct; leaving it unset is safe only for a single-arch image, where there is nothing to choose between. When storage is enabled, an existing SBOM may be reused instead of resolving fresh; inspect its kubescape.io/resolved-platform annotation to confirm the stored result's architecture:

curl -X POST http://localhost:8080/v1/sbomCreation \
  -H "Content-Type: application/json" \
  -d '{
    "imageTag": "myapp:latest",
    "jobID": "multi-arch-scan-001",
    "args": {
      "platform": "linux/arm64"
    }
  }'

The platform actually resolved (which may differ from the request if none was given) is recorded on the resulting SBOM's kubescape.io/resolved-platform annotation. Requesting a platform absent from the image's manifest fails the scan with a distinguishable "platform not found" reason instead of a generic error.


Rate Limiting

Kubevuln implements internal concurrency control via a worker pool. The number of concurrent scans is controlled by the scanConcurrency configuration option.

Whether an accepted-but-unfinished scan past that concurrency is queued or rejected depends on maxQueueDepth (see CONFIGURATION.md):

  • Unset, or 0/negative (the default): unbounded. Every request that passes validation is accepted and queued for processing, however large the backlog grows.
  • A positive value: bounded. Once that many scans are accepted but not yet finished (queued or running), each of the four scan endpoints (sbomCreation, scanImage, scanRegistryImage, applicationProfileScan) rejects further requests with 503 Service Unavailable instead of queuing them — see each endpoint's Response table above. Callers should treat this as a signal to retry later, not as an error with the request itself.

OpenTelemetry Integration

When OTEL_COLLECTOR_SVC is set, all API endpoints are instrumented with OpenTelemetry tracing.

Traces include:

  • Request handling duration
  • SBOM generation time
  • CVE scanning time
  • Image download time

API authentication

Every route except the probes and /metrics requires Authorization: Bearer <Kubernetes service-account token> with audience kubescape.io. The token is validated with a TokenReview and the caller is authorized by RBAC (SubjectAccessReview) on kubescape.io resources: create on vulnerabilityscans for the scan POSTs, get on vulnerabilityscans for /v1/scanStatus/* and /v1/diagnostics.

  • The service account running this component needs a ClusterRoleBinding to system:auth-delegator.
  • KS_API_AUDIENCE: expected token audience (default kubescape.io).
  • POD_NAMESPACE: required; the process exits at startup if it is unset. It also exits when it has no kube config (the in-cluster one, or KUBECONFIG/~/.kube/config elsewhere) or when its startup check that it may create TokenReviews fails.
  • KS_API_AUTH_DISABLED=true: turns the check off, along with the startup requirements above. Use it only for local development, since every client that can reach the port is then allowed. See Running locally.

To call the API by hand, mint a token for a service account that holds the matching Role:

TOKEN=$(kubectl create token <sa> -n <ns> --audience kubescape.io)
curl -H "Authorization: Bearer $TOKEN" ...

Design: in-cluster API authn/authz.


See Also