Container Image Scanning
How AsPeekIt inventories the packages inside running container images with Trivy, on Docker hosts with an agent (enabled with install.sh --image-scan) and on Kubernetes nodes reached only by a relay, how the trivy-server service keeps its vulnerability database (also in air-gapped installs), how image packages become components and findings, and how to choose between the matcher and Trivy as the source of image findings.
How It Works
A trivy-server service holds the Trivy vulnerability database. Agents and relays run the external trivy binary in client mode (trivy image --server), so no scanner library is embedded and the database is downloaded only once. The reduced Trivy report reaches the backend, which stores every package of the image as a component with origin trivy, linked to the host (agent) or to the Kubernetes node (relay).
- Each image is scanned at most once every image_scan_interval_hours (default 24); only images of running containers are scanned, never init, ephemeral or stopped containers
- Component path: image:<image_id> for an agent and image:<digest> for a relay; language packages append /<file path inside the image>, so the same package in two images of the same host stays two components
- Component details: image_ref, image_digest (empty when the image has no registry digest), image_id (agent only) and the vulnerabilities reported by Trivy (at most 200 per component)
- Trivy types are mapped to AsPeekIt ecosystems: OS packages become deb, apk or rpm with the distro of the image (for example debian-12.5); python-pkg, pip, pipenv and poetry become pypi; node-pkg, npm, yarn and pnpm become npm; gemspec and bundler become gem; composer, cargo (and rust-binary), gobinary and gomod become composer, cargo and golang. Unmapped types (for example jar) are discarded and counted
- OS package versions are rebuilt as epoch:version-release (for example 1:2.36-9+deb12u4); apk versions are kept as they are
- Older agents and relays that do not send image_scans never touch the trivy components
Enabling the Scan on a Host (install.sh --image-scan)
The image scan needs the Trivy client on the host, so it is off by default and installed only where it is asked for. The Linux installer does it with the opt-in --image-scan flag; the Trivy server token (TRIVY_SERVER_TOKEN of the platform) is read from IDP_TRIVY_TOKEN or asked on the terminal.
- Linux amd64 or arm64 with Docker only: the installer refuses other systems, other architectures and hosts without a docker group
- trivy comes from the same release as the agent (trivy-linux-<arch>, checked against SHA256SUMS, same version as the platform trivy-server) and is installed outside PATH, in /usr/local/lib/idp-agent/trivy: a Trivy the host already has is not touched
- The settings are written to /etc/idp-agent/image-scan.env (mode 0640, root:idp-agent, it holds the token) as IDP_IMAGE_SCAN=true, IDP_TRIVY_PATH, IDP_TRIVY_SERVER_URL (the platform URL) and IDP_TRIVY_TOKEN, loaded by the systemd drop-in idp-agent.service.d/image-scan.conf: agent.yaml is never edited
- Trivy runs in client mode against the platform (https://<host>/twirp/...): the host downloads no vulnerability database and contacts nothing else
- Upgrades keep the image scan and update trivy together with the agent; a failed upgrade restores the previous trivy and settings
- --no-image-scan removes trivy, the settings file and the drop-in, which switches the scan off
export IDP_TRIVY_TOKEN=... # TRIVY_SERVER_TOKEN of the platform (or typed at the prompt)
curl -fsSL https://<host>/agent/install.sh | sudo -E bash -s -- --image-scan
# Switch it off again
curl -fsSL https://<host>/agent/install.sh | sudo bash -s -- --no-image-scanAgent Configuration
Image scanning on an agent is off by default. install.sh --image-scan sets everything through environment variables; otherwise enable it in agent.yaml (or with IDP_IMAGE_SCAN=true, which overrides features.image_scan) and point the agent at the Trivy binary and at the trivy-server URL. The agent container image ships the trivy binary at /usr/local/bin/trivy.
- features.image_scan: enable the scan (default false)
- features.image_scan_interval_hours: minimum hours between two scans of the same image (default 24)
- features.image_scan_timeout_seconds: timeout of one trivy run (default 300)
- features.image_scan_cpu_limit: GOMAXPROCS of the trivy process (default 1)
- trivy.path, trivy.server_url and trivy.token, or the environment variables IDP_TRIVY_PATH, IDP_TRIVY_SERVER_URL and IDP_TRIVY_TOKEN
- The agent makes no Internet calls: trivy reads the image from the local Docker daemon (--image-src docker) and talks only to the configured server (--offline-scan, --skip-java-db-update; the version check is disabled with TRIVY_SKIP_VERSION_CHECK)
- trivy runs in its own process group with the lowest priority (started through nice -n 19 on Linux), a per-image timeout and a capped output; the token is passed in the TRIVY_TOKEN environment variable, never on the command line
- Scans run in a background worker and never block the collection cycle: every report resends the last result of each running image
- Coverage scope images:trivy: skipped (disabled by configuration) when the feature is off, failed when the binary or server_url is missing, ok when every running image has a result, partial otherwise. A failure on one image never fails the cycle
Note: The scan cache lives in memory: after an agent restart every running image is scanned again.
features:
image_scan: true
image_scan_interval_hours: 24
image_scan_timeout_seconds: 300
image_scan_cpu_limit: 1
trivy:
path: /usr/local/bin/trivy
server_url: http://idp.internal.example:4954
token: "" # or IDP_TRIVY_TOKENComponent Lifecycle on a Host
The backend applies the coverage of images:trivy before touching the trivy components of a host.
- No image_scans key and no images:trivy coverage (older agent): components unchanged
- Coverage skipped: every trivy component of the host is removed
- Coverage failed: every trivy component is kept and marked as stale evidence
- Otherwise the components of every image scanned with status ok are replaced; images still running without an ok result keep their components as stale evidence; components of images no longer running are removed, unless the report contains container collector errors
Relay Configuration (Kubernetes)
Kubernetes nodes without an agent are scanned by the relay after each discovery job of the zone. Set trivy_path in relay.yaml (default trivy; the relay image ships the binary) and add an image_scan block to the connection configuration of the Kubernetes zone.
- Only digests of running pods on nodes that are not in agent_nodes are scanned; agent_nodes is computed by the backend from the active agents that already report Trivy components for the node
- Images are pulled from the registry (--image-src remote); registry credentials are passed in TRIVY_USERNAME/TRIVY_PASSWORD only for the matching registry host, otherwise the pull is attempted without authentication
- time_budget_seconds (default 900) caps the time spent scanning in one job; the cache per digest honours interval_hours
- Every image is sent with its own POST to /api/v1/relay/image-scans/, so large reports never hit the upload size limit of the results endpoint; a failed scan or POST is logged and does not stop the others
- Components are stored on the node/<name> assets of the zone with path image:<digest>; they are removed when a complete Kubernetes result no longer shows the digest running on the node
Warning: Tokens and registry passwords never appear in logs, command lines or asset attributes, and are masked in the API responses of the UI.
{
"image_scan": {
"enabled": true,
"trivy_server_url": "http://idp.internal.example:4954",
"trivy_token": "",
"interval_hours": 24,
"timeout_seconds": 300,
"time_budget_seconds": 900,
"registries": [
{ "registry": "registry.example.com", "username": "scanner", "password": "..." }
]
}
}trivy-server and the Trivy DB
docker-compose.yml runs aquasec/trivy:0.57.1 as trivy-server on port 4954 with the database in the trivy-cache volume, which is also mounted on the backend and Celery worker. In production (docker-compose.prod.yml) the same image runs as trivy-server behind Traefik: agents and relays reach it at https://<IDP_HOSTNAME>/twirp/, its token TRIVY_SERVER_TOKEN is mandatory (the stack does not start without it), and its trivy_cache volume is shared with the backend, worker and beat for the feed status and offline bundles. By default the server updates the database by itself from TRIVY_DB_REPOSITORY (default mirror.gcr.io/aquasec/trivy-db:2).
- TRIVY_SERVER_TOKEN: token required from clients (in development an empty value disables it; mandatory in production, where the route is reachable by every agent host)
- TRIVY_DB_REPOSITORY: OCI repository of the database, for example an internal mirror
- TRIVY_SKIP_DB_UPDATE: true for air-gapped installs, where the database comes from a bundle
- The task sync_trivy_db_status (beat sync-trivy-db-status, every 6 hours) reads <SECURITY_TRIVY_CACHE_DIR>/db/metadata.json (default /trivy-cache) and records the result in the feed status entry trivy/db, with UpdatedAt as cursor; a missing database is recorded as "Trivy DB not found"
Air-gapped Import
Without Internet access, download the database on a connected machine, pack it in a tar.gz with only trivy.db and metadata.json (optionally under db/) and import it with the management command. The bundle is extracted to a temporary directory and moved into the shared volume atomically.
- Bundles with symlinks, path traversal, other files or larger than SECURITY_TRIVY_BUNDLE_MAX_BYTES (default 2 GiB) are refused
- The import updates the feed status entry trivy/db with its license and attribution
- Restart trivy-server after the import (docker compose restart trivy-server): with TRIVY_SKIP_DB_UPDATE=true it keeps serving the database it opened at startup
# On a machine with Internet access
trivy image --download-db-only --cache-dir ./trivy-cache
tar -C ./trivy-cache -czf trivy-db.tar.gz db/trivy.db db/metadata.json
# On the AsPeekIt server
docker compose exec backend python manage.py import_feed trivy --bundle /tmp/trivy-db.tar.gzMatcher or Trivy Findings
SECURITY_IMAGE_FINDINGS_SOURCE chooses where the findings of image components come from. With the default matcher, image packages are evaluated by the component matcher v2 against the same OSV advisories as host packages, so an image and a host are judged by the same rules and nothing is counted twice. With trivy, the matcher skips components with origin trivy and the vulnerabilities reported by Trivy become findings with source trivy. Any other value means matcher.
- Findings have the same format as host findings, plus image_ref and image_digest in their details (shown as Image and Digest in the finding evidence)
- Findings belong to the asset of the component: the host for an agent, the node/<name> asset for a relay
- A component is never evaluated by both sources
- Switching mode takes effect at the next full match_cves_to_assets run, which resolves the open findings of the other source
SECURITY_IMAGE_FINDINGS_SOURCE=matcher # default
SECURITY_TRIVY_CACHE_DIR=/trivy-cache
SECURITY_TRIVY_BUNDLE_MAX_BYTES=2147483648
License and Attribution
Trivy is distributed under the Apache License 2.0. The feed status entry trivy/db records the license "Apache-2.0 (Trivy and trivy-db); advisories are aggregated from upstream sources under their own licenses; https://github.com/aquasecurity/trivy-db" and the attribution "Trivy vulnerability database by Aqua Security (https://github.com/aquasecurity/trivy-db), aggregating upstream advisory databases under their own licenses."
Warning: The Trivy DB aggregates advisories from distribution and language ecosystem sources, each under its own terms. Check the current terms of each source before redistributing advisory data.