Run cnspec from the Container Image
Run cnspec from the official mondoo/cnspec container image, pick an image tag and variant, and pass credentials and files to scan.
Mondoo publishes cnspec as a container image, mondoo/cnspec on Docker Hub. Use it to run cnspec without installing it on the host, or as the job image in a CI/CD pipeline.
The image's entrypoint is cnspec, so everything after the image name is passed to cnspec as arguments. Without arguments, the container prints cnspec's help.
docker run --rm mondoo/cnspec:14 versionChoose a tag
Every stable cnspec release is published under three tags:
| Tag | Example | Points to |
|---|---|---|
<version> | mondoo/cnspec:<version> | One specific release |
<major> | mondoo/cnspec:14 | The latest release of that major version |
latest | mondoo/cnspec:latest | The latest release |
Releases on the preview release channel are published only under their own version tag. The major version tag and latest always point to a stable release.
A major version tag moves to each new minor and patch release of that major version, but not to the next major version, which can include breaking changes. To learn more, read How cnspec versioning works.
Image variants
Every tag also comes in variants. To use one, add its suffix to the tag, for example mondoo/cnspec:14-rootless or mondoo/cnspec:latest-ubi-rootless.
| Suffix | Base image | Runs as | Architectures |
|---|---|---|---|
| None | Alpine Linux | root | amd64, arm64, arm/v6, arm/v7 |
-rootless | Alpine Linux | The unprivileged mondoo user | amd64, arm64, arm/v6, arm/v7 |
-ubi | Red Hat Universal Base Image (UBI) 8 minimal | root | amd64, arm64 |
-ubi-rootless | Red Hat UBI 8 minimal | UID 100, GID 101 | amd64, arm64 |
Use a rootless variant when the container must not run as root. Use a UBI variant when your organization requires images built on Red Hat's base image.
Scan files on the host
The container can only read files you mount into it. Mount the directory, and pass cnspec the path inside the container:
docker run --rm -v "$PWD:/work" mondoo/cnspec:14 scan terraform /workWith a rootless variant, the container's user must be able to read the mounted files.
Report results to Mondoo Platform
The image contains no cnspec configuration. Without one, cnspec scans against Mondoo's open source policies, and the results stay in the container's output.
To report results to Mondoo Platform, pass a service account's credentials, Base64 encoded, in the MONDOO_CONFIG_BASE64 environment variable:
export MONDOO_CONFIG_BASE64="<base64-encoded-credentials>"
docker run --rm -e MONDOO_CONFIG_BASE64 -v "$PWD:/work" mondoo/cnspec:14 scan terraform /work-e MONDOO_CONFIG_BASE64 without a value passes the variable from your shell into the container, so the credentials don't appear in the command. To learn how to create a service account and copy its Base64-encoded credentials, read Register cnspec Using a Credentials File.
Use the image in CI/CD
Most CI/CD systems can run a job in the mondoo/cnspec image. Systems that run the job's steps with a shell inside the image need the cnspec entrypoint cleared: in GitLab CI/CD, set entrypoint: [''] on the image, and in a Jenkins Docker agent, pass --entrypoint="" in args. Store the Base64-encoded credentials as a secret, and expose the secret to the job as MONDOO_CONFIG_BASE64.
For complete pipeline examples, read Integrate Mondoo with CI/CD platforms.
Avoid downloading providers on every run
The image includes only cnspec's built-in providers. Each fresh container downloads every other provider the scan needs, such as aws or terraform, before it scans. To skip that download, build your own image on top of mondoo/cnspec with the providers installed:
FROM mondoo/cnspec:14
RUN cnspec providers install terraformcnspec still checks for newer provider versions before it runs a command. To use only the
providers in the image, pass --auto-update=false. To learn more, read Manage cnspec
Providers.
Last updated on