Skip to main content

bundle-scanner

When a new bundle version is published, bundle-scanner pulls it from the Massdriver OCI registry and scans its IaC with Trivy (trivy config) and Checkov. It posts a summary of the findings to Slack.

The repo.published event names the bundle but not the version. The automation scans the newest version of the bundle that was published at or before the time of the event.

A version fails when a finding has the severity in fail_severity or higher. Checkov reports no severity without a Prisma Cloud API key, so its findings count as unrated and do not fail a version. The Slack message has the count for each severity and lists the first 10 findings that cause a failure.

Scans run one at a time, after the automation responds to Massdriver. Each bundle version is scanned once.

A .checkov.yml at the root of the bundle applies to the Checkov scan. Trivy uses the checks built into its pinned version.

Settings​

The config file is YAML, at CONFIG_FILE (default /etc/massdriver-automations/config.yaml). Every key is optional. An unknown key stops the automation at start. config.example.yaml has every key, with comments.

KeyDefault
scanners[trivy, checkov]The scanners to run.
fail_severityHIGHUNKNOWN, LOW, MEDIUM, HIGH, or CRITICAL. A version fails at this severity or above.
result_attributeThe repo custom attribute that records the result. Empty sets no attribute.
timeout10mThe longest time for one bundle version: the pull and every scanner.
slack.channelThe channel for results, with SLACK_BOT_TOKEN. Ignored with only SLACK_WEBHOOK_URL. Without a channel or a webhook, results go to the logs only.
yaml
scanners: [trivy, checkov]
fail_severity: HIGH
result_attribute: iac_scan
timeout: 10m
slack:
channel: "#bundles"

The bundle's Settings params have the keys of the config file. Event attributes adds an attribute filter to the destination, such as md-repo = aws-aurora.

Result attribute​

With result_attribute, the automation records the result on the bundle's repo as <key>=passed or <key>=failed. It keeps the repo's other attributes. A scan that cannot finish does not change the attribute. The key must be a custom attribute of your organization for repos.

The attribute is on the repo, not on the bundle version, so it shows the result of the newest scanned version only. Bundle versions do not carry attributes of their own. Repo attributes do not cascade to instances, so a policy on instance:deploy cannot use the attribute to block a deploy of a failed version. Use the attribute to find failed bundles, and the Slack message to act.

Secrets​

Variable
SLACK_BOT_TOKENThe xoxb- token of the Slack app. Posts go to slack.channel.
SLACK_WEBHOOK_URLA Slack incoming webhook, for a workspace without the app. Every post goes to its one channel. Ignored when the bot token is set.
OTEL_EXPORTER_OTLP_HEADERSHeaders for the OTLP endpoint of Tracing, such as authorization=Bearer abc123.

MASSDRIVER_SIGNING_SECRET, MASSDRIVER_ORGANIZATION_ID, MASSDRIVER_API_KEY, and MASSDRIVER_URL are common settings. All are required. The registry is at MASSDRIVER_URL.

Permissions​

The service account needs:

  • repo:view and repo:pull on the bundle repos
  • repo:update on the bundle repos, with result_attribute
  • organization:manageEventDestinations, when deployed with the bundle

Host​

The bundle serves the automation at Ingress > Host, such as bundle-scanner.automations.acme.com. Only /hooks/massdriver must be public. On ECS, an empty host uses bundle-scanner.<domain of the cluster's hosted zone>. Refer to Deploy.

The bundle runs the <tag>-scanner image, with more CPU and memory than the other automations: 250m CPU and 512Mi memory, up to 2 CPUs and 2Gi, on Kubernetes, and 1 vCPU and 2 GiB on ECS.

Event destination​

The bundle creates a destination for repo.published events with the condition .data.entity.artifact_type == "application/vnd.massdriver.bundle.v1+json", plus the attributes of Event attributes.

To create it yourself, with mass 2.6.0 or later:

shell
mass event destination create \
--name bundle-scanner \
--url https://bundle-scanner.example.com/hooks/massdriver \
--event-type repo.published \
--condition '.data.entity.artifact_type == "application/vnd.massdriver.bundle.v1+json"'

To scan one bundle only, add --attribute md-repo=aws-aurora.

Copy the signing secret that the command prints into MASSDRIVER_SIGNING_SECRET.

Run​

The scanners are in the -scanner image, not in the massdriver-automations image. It runs bundle-scanner by default.

shell
docker run -p 8080:8080 \
-v "$PWD/config.yaml:/etc/massdriver-automations/config.yaml:ro" \
-e MASSDRIVER_ORGANIZATION_ID=acme \
-e MASSDRIVER_API_KEY=md_... \
-e MASSDRIVER_SIGNING_SECRET=whsec_... \
-e SLACK_BOT_TOKEN=xoxb-... \
ghcr.io/massdriver-cloud/massdriver-automations:0.3-scanner

The image pins Trivy 0.76.2 and Checkov 3.4.6. To change the versions, edit automations/bundle-scanner/Dockerfile and build from the root of the repository:

shell
docker build -f automations/bundle-scanner/Dockerfile -t bundle-scanner .

Limits​

  • The queue holds 100 bundle versions, in memory. When it is full, the automation responds 500, and Massdriver sends the event again later. A restart loses the queue.
  • Duplicate events are dropped by id for one hour, and each version is scanned once per process. Run one replica.
  • A failed pull or scanner is posted to Slack and logged. Massdriver does not send the event again.
  • A bundle larger than 512 MiB is not scanned.