# Scan running images for vulnerabilities

URL: https://stack.logicaltech.it/docs/operations/vulnerability-scanning/

See which services run images with known CVEs, with the package, installed version and fixed version, and get notified when a new critical one appears.

LogiStack checks the image each service runs against public vulnerability databases. Every service gets a security badge, and its **Security** tab lists each known vulnerability with the affected package, the version installed and the version that fixes it. Use it to find out which services need a rebuild or an image update after a new CVE is published.

Scans run in the background and never delay a deployment.

## When images are scanned [#when-images-are-scanned]

- **After each deployment.** A few seconds after a deployment succeeds, the image it runs is scanned. A redeploy of an image already scanned in the last 12 hours reuses that result.
- **Once a day.** Every image a service runs is scanned again, so a vulnerability published after you deployed still shows up.
- **On demand.** Select **Scan now** on the **Security** tab.

Results are stored per image digest. Services that run the same image share one scan and one result.

## Read the badge [#read-the-badge]

The service header shows the result of the last scan next to the service status. Select it to open the **Security** tab.

| Badge | Meaning |
| --- | --- |
| **N critical** (red) | At least one critical vulnerability. |
| **N high** (orange) | No critical, at least one high. |
| **Low risk** | Only medium, low or unknown severity findings. |
| **No known vulnerabilities** | The scan found nothing. |

A service with no badge has not been scanned yet: deploy it, or wait for the daily scan.

## Review the findings [#review-the-findings]

<Steps>
<Step>
### Open the Security tab [#open-the-security-tab]

Open the service and select **Security**.

![The Security tab of a service: the image ghcr.io/acme/storefront scanned 3 hours ago, one critical, one high, one medium and one low finding, and a table of findings with package, installed version and fixed version](/screens/service-security.webp)
</Step>
<Step>
### Check the image scan [#check-the-image-scan]

**Image scan** shows the image and its digest, when it was scanned, and how many findings there are of each severity.
</Step>
<Step>
### Go through the findings [#go-through-the-findings]

**Findings** lists each vulnerability, worst first: its severity, its ID and title, the package and installed version, and **Fixed in**, the first version without it. Select an ID to open its advisory. Select **Fixable** to show only the findings that already have a fix.
</Step>
</Steps>

To fix a finding, update the package or the base image to the version in **Fixed in** and deploy again. For an image you don't build, such as `postgres:17` or `nginx:1.27`, move to a newer tag. The scan after the deployment updates the badge.

A finding that says **No fix yet** has no fixed version upstream. Watch it, or replace the package if it matters to you.

## Get notified [#get-notified]

When a scan finds a critical vulnerability that the image did not have at its previous scan, LogiStack sends an `image.vulnerable` event for every service that runs that image. The event names the service, the image and the new vulnerability IDs. Add **Critical vulnerability found** to a notification rule to receive it in Slack, email or another channel. See [Alerts and notifications](./alerts-and-notifications.mdx).

A rescan that finds the same critical vulnerabilities sends nothing.

## How scanning works [#how-scanning-works]

The worker runs [Trivy](https://trivy.dev) in a short-lived container on its node, reads the JSON report and removes the container. The vulnerability database is cached in the `ls-trivy-cache` volume, so only the first scan downloads it in full; later scans fetch updates. The worker needs internet access to download it.

- **Images from a registry** are read from the registry at their exact digest. For a private image on your organization's default registry, the scan uses that registry's credentials, passed to Trivy as environment variables.
- **Images built on the server and never pushed** are read from the local Docker engine.

The scan covers operating system packages and language dependencies that Trivy recognizes in the image, such as npm, pip, Go modules and Maven. It does not look at the running container's filesystem, configuration or secrets.

## Use the API [#use-the-api]

- `GET /api/services/{id}/vulnerabilities` returns the image, digest, scan status, badge, counts per severity and the findings. Over MCP this is the `get_services_by_id_vulnerabilities` tool.
- `POST /api/services/{id}/vulnerabilities/scan` queues a scan now, even if the image was scanned recently. It needs the deploy permission on the service. Over MCP this is the `service_scan` tool.

```json title="GET /api/services/svc_.../vulnerabilities"
{
  "image": "ghcr.io/acme/storefront",
  "digest": "sha256:9f3c1e0b7a24…",
  "status": "succeeded",
  "badge": "critical",
  "counts": { "critical": 1, "high": 1, "medium": 1, "low": 1, "unknown": 0 },
  "scannedAt": "2026-11-07T09:12:44.000Z",
  "error": null,
  "findings": [
    {
      "id": "CVE-2025-49794",
      "severity": "critical",
      "pkgName": "libxml2",
      "installedVersion": "2.13.4-r5",
      "fixedVersion": "2.13.9-r0",
      "title": "libxml2: heap use after free leads to denial of service",
      "url": "https://avd.aquasec.com/nvd/cve-2025-49794"
    }
  ]
}
```

While a scan runs, `status` is `running`. Poll until it changes.

## Common problems [#common-problems]

- **Not scanned yet**: the service has not been deployed since scanning was added. Deploy it, or wait for the daily scan.
- **Last scan failed**: the message under the image says why. Usually the worker could not reach the registry or download the vulnerability database. The findings of the previous successful scan stay on screen until a scan succeeds.
- **A private image from another registry fails**: the scan only has the credentials of your organization's default registry. Images from other private registries can't be scanned.
