Installation

The cnspec Configuration File

Reference for mondoo.yml, the cnspec configuration file, including where cnspec looks for it and every setting it accepts.

cnspec stores its settings in a YAML file named mondoo.yml. Registering cnspec creates the file and writes the credentials that connect the host to your Mondoo Platform space. You can then add settings of your own to control logging, proxies, asset metadata, provider updates, and how often the service scans.

Everything in this file is optional except the registration credentials. An unregistered cnspec runs happily without a configuration file, scanning against Mondoo's free, open source policies.

Where cnspec looks for the file

cnspec checks the current user's configuration first, then the system-wide configuration. It uses the first file it finds:

Operating systemScopePath
LinuxCurrent user~/.config/mondoo/mondoo.yml
LinuxAll users/etc/opt/mondoo/mondoo.yml
macOSCurrent user~/.config/mondoo/mondoo.yml
macOSAll users/Library/Mondoo/etc/mondoo.yml
WindowsCurrent userC:\Users\{username}\.config\mondoo\mondoo.yml
WindowsAll usersC:\ProgramData\Mondoo\mondoo.yml

Because the user file wins, a mondoo.yml in a user's home directory silently overrides the system-wide configuration for every command that user runs. If a scan reports to the wrong space, check for a stray user-level file first.

To see which file cnspec loaded, run cnspec status. The output names the file and the source that selected it:

→ loaded configuration from /etc/opt/mondoo/mondoo.yml using source default

Point cnspec at a different file

You can override the search with a flag or an environment variable. When more than one is present, cnspec uses the first match in this order:

  1. MONDOO_CONFIG_BASE64: the entire configuration file, base64 encoded. This is the usual choice for CI/CD, where you store the encoded file as a secret and never write it to disk.
  2. --config <path>: a path passed on the command line. Every cnspec command accepts it.
  3. MONDOO_CONFIG_PATH: a path from the environment, used only when --config is absent.
  4. The search paths in the table above.
Encode a configuration file for CI/CD
base64 < mondoo.yml | tr -d '\n'

cnspec can also read the file from AWS Systems Manager Parameter Store. Pass the region and parameter name with the aws-ssm-ps:// prefix, in the form aws-ssm-ps://region/<region>/parameter/<name>:

Load the configuration from Parameter Store
cnspec scan local --config aws-ssm-ps://region/us-east-1/parameter/mondoo-config

cnspec reads the parameter with the AWS credentials it finds in the environment, the same ones the AWS CLI uses.

How settings are resolved

Three sources feed each setting. Later sources win:

  1. The configuration file
  2. Environment variables
  3. Command line flags

Most settings also have an environment variable equivalent: prefix the key with MONDOO_, uppercase it, and replace hyphens and dots with underscores. So auto_update becomes MONDOO_AUTO_UPDATE and api_endpoint becomes MONDOO_API_ENDPOINT. The log.format and log.color settings are the exception, because cnspec reads them before it applies environment overrides. Set those two in the file.

cnspec reads keys literally and does not expand dotted keys into nested YAML. Write log.format and log.color exactly as shown in this reference, as single keys with a dot in the name. Nesting them under a log: block has no effect. The annotations, labels, auth, and scan_interval settings are the opposite: they are true YAML blocks with nested keys.

Platform connection

cnspec login writes these settings. Treat them as generated values: to change spaces or replace credentials, register again rather than editing them by hand.

SettingDescription
mrnMondoo resource name of the service account cnspec authenticates as
agent_mrnMondoo resource name that identifies this client
space_mrnMondoo resource name of the space the service account belongs to. This is the key cnspec login writes
scope_mrnMondoo resource name of the space or organization the service account is scoped to. When present, it takes precedence over space_mrn
certificatePEM encoded client certificate
private_keyPEM encoded client private key, used to sign requests to Mondoo Platform
tokenService account token, for accounts that authenticate by token instead of a certificate
api_endpointURL of Mondoo Platform, https://us.api.mondoo.com by default
api_proxyProxy URL for all traffic to Mondoo Platform

The configuration file contains a private key. On Linux and macOS, keep it readable only by the account that runs cnspec (chmod 0600). Never commit it to a repository.

cnspec resolves the scope from the first of these keys that is set: scope_mrn, then space_mrn, then parent_mrn. Registration writes space_mrn, so that is what you see in most files. parent_mrn is deprecated and remains only so that older files keep working.

Registration can also seed a few of the settings below. cnspec login accepts --annotation, --api-endpoint, --updates-url, --timer, and --splay, and writes each one to the file it creates.

To route traffic through a proxy, add:

mondoo.yml
api_proxy: http://10.0.0.1:8080

For more on proxies, read Register cnspec.

Asset metadata

These settings control the metadata cnspec attaches to what it scans from this host.

SettingDescription
annotationsKey/value pairs added to every asset this host scans. They display in the Mondoo Console and can drive policy filtering
labelsKey/value pairs sent with the client registration when cnspec logs in. They describe the client, not the assets it scans
categoryAsset category. Set it to cicd to record scans as CI/CD assets instead of fleet assets
detect-cicdWhether to detect CI/CD environments automatically and set the category to cicd. Default true
mondoo.yml
annotations:
  team: research
  owner: cosmo@lunalectric.com

To learn more about annotations and the other ways to set them, read Annotate assets.

Logging

SettingDescription
log-levelLog verbosity: error, warn, info, debug, or trace. Default info
log.formatSet to json for structured log output. Write the key exactly as shown, dot included
log.colorSet to true for compact, colorized console logs. Write the key exactly as shown
logging-configPath to a separate logging configuration file (YAML or JSON) that selects the log writer, level, and writer options. It takes precedence over log-level
mondoo.yml
log-level: debug
log.format: json

Updates

SettingDescription
auto_updateWhether cnspec updates itself and downloads the latest providers as needed. Default true
updates_urlBase URL for cnspec and provider downloads. Point it at an internal mirror for air-gapped fleets
Turn off automatic updates
auto_update: false

The configuration key uses an underscore (auto_update), while the command line flag uses a hyphen (--auto-update=false). Writing auto-update in the file has no effect.

providers_url sets the provider download URL on its own and is deprecated. Use updates_url instead, which covers both cnspec and providers. When you turn off automatic updates, check releases.mondoo.com/providers/ periodically and update providers manually, as described in Manage cnspec providers.

Scheduled scans

When cnspec runs as a service, these settings control the scan schedule:

SettingDescription
scan_interval.timerMinutes between scans. Default 60
scan_interval.splayMaximum random delay in minutes added to each scan, so a fleet doesn't scan in lockstep. Default 60
mondoo.yml
scan_interval:
  timer: 360
  splay: 30

The cnspec serve --timer and --splay flags override these values for a single run. cnspec login --timer and --splay write them into the file at registration.

The inventory file beside it

When cnspec loads a configuration file, it also looks for an inventory.yml in the same directory. If one is there and you did not pass --inventory-file, cnspec scans the assets that inventory defines:

/etc/opt/mondoo/
├── mondoo.yml
└── inventory.yml

cnspec serve always scans every asset the discovered file defines, on every cycle, with no extra flags. This is how a host running cnspec as a service extends its own scan: list the host itself (type: local) alongside another asset, such as the database service running on it, and each cycle produces a result for both instead of just the host.

cnspec serve reads mondoo.yml and this file once, at startup, and keeps that in memory for as long as it runs. It does not watch the file for changes. If you add or edit inventory.yml next to an already-running service, restart the service to pick up the change:

  • Linux: sudo systemctl restart cnspec
  • Windows: Restart-Service -Name mondoo

cnspec scan also auto-discovers this file, but only to enrich the target you give it, for example by copying id_detector settings. If you run cnspec scan local with an auto-discovered inventory.yml on disk, cnspec scans only local and drops the file's other assets. To scan every asset an inventory file defines with cnspec scan, pass it explicitly with --inventory-file instead of relying on auto-discovery.

To learn what belongs in that file, including a worked example of combining a host scan with a local database scan, read Remote scanning with inventory files.

Advanced

SettingDescription
featuresClient feature flags. Set these only when Mondoo Support asks you to
auth.methodAuthentication method. cnspec sets this itself when it detects a Workload Identity Federation configuration

A configuration file with type: external_account tells cnspec to authenticate with Workload Identity Federation rather than a certificate and private key. Such a file carries the federation keys audience, issuerUri, jwtToken, subjectTokenType, scopes, and universeDomain. These files are generated, not hand-authored.

A complete example

mondoo.yml
# service account mrn
mrn: //agents.api.mondoo.app/spaces/lunalectric/serviceaccounts/1utIs5XUQ8XayfB6yiQNTLOqPlD
# agent mrn
agent_mrn: //agents.api.mondoo.app/spaces/lunalectric/agents/1utIqsjg3YSAF8hMMIhg8tBsTPP
# space mrn
space_mrn: //captain.api.mondoo.app/spaces/lunalectric
# api endpoint
api_endpoint: https://us.api.mondoo.com
# pem-encoded certificate
certificate: |
  -----BEGIN CERTIFICATE-----
  ...
  -----END CERTIFICATE-----
# pem-encoded private key
private_key: |
  -----BEGIN PRIVATE KEY-----
  ...
  -----END PRIVATE KEY-----
# log level: error, warn, info, debug, trace
log-level: info
# annotations applied to every asset scanned from this host
annotations:
  team: research
  owner: cosmo@lunalectric.com
# scan every six hours, with up to 30 minutes of jitter
scan_interval:
  timer: 360
  splay: 30

Learn more

On this page