Friday, September 25, 2026

Policy-as-code posture checks from build to runtime: inside cnspec

Policy-as-code posture checks from build to runtime: inside cnspec

cnspec is an open source, cloud-native policy engine that audits misconfigurations and vulnerabilities across clouds, Kubernetes, containers, and endpoints for authorized security teams.

Toolmondoohq/cnspec — open source, cloud-native security and policy engine for infrastructure assessment
CategorySecurity posture management / policy-as-code scanner
Primary UseScanning owned infrastructure — clouds, Kubernetes, container images, servers, SaaS, and IaC — for misconfigurations and vulnerabilities via cnspec scan
Safe UseDesigned for defensive use: auditing your own environments in authorized assessments, CI/CD pipelines, labs, and continuous compliance programs
Telemetry NotePurely defensive telemetry: cnspec is read-only against targets and reports findings to STDOUT or to Mondoo Platform when registered with cnspec login --token

cnspec, published by Mondoo at mondoohq/cnspec, positions itself as an open source, cloud-native security and policy project that assesses an entire estate — public and private clouds, Kubernetes clusters, containers and their registries, servers and endpoints, SaaS products, infrastructure-as-code templates, and APIs — for vulnerabilities and misconfigurations. It is written in Go, carries roughly 441 stars, and its topic tags (policy-as-code, security-as-code, compliance, declarative) make the design philosophy explicit: security controls are expressed as code, versioned like code, and executed by a deterministic engine rather than by hand-rolled audit scripts. For operators used to stitching together terraform validate, CIS benchmarks, and image scanners, cnspec is an attempt to collapse those into one declarative layer.

The core abstraction is the policy. A cnspec policy is a plain YAML file expressing security rules and best practices, and the repository ships with default security policies that run out of the box for every supported target, stored in the content directory of the repo. The README is candid that the client is built on top of Mondoo's security data fabric; the open source CLI is fully usable standalone for scanning and evaluation, while vulnerability scanning and fleet-wide risk prioritization require logging into Mondoo Platform. That split matters when you're deciding where the open source tool ends and the commercial plane begins.

Installation is deliberately frictionless. On Linux and macOS the vendor's script handles it, after which cnspec scan local evaluates the security posture of the machine you're sitting on. Windows gets a PowerShell bootstrap via Install-Mondoo, and manual packages are published in the GitHub releases for anyone who prefers pinning versions in a pipeline. The two-line quick start — install, then cnspec scan local — reflects the project's opinion that a scanner which takes an hour to first value is a scanner nobody runs.

Remote scanning is where the breadth shows. The cnspec scan subcommand accepts target URIs: cnspec scan docker image ubuntu:22.04 inspects a container image without running it, cnspec scan aws sweeps an AWS account using the local aws CLI credential chain, cnspec scan k8s reads a cluster from your local kubectl context, and cnspec scan k8s manifest.yaml evaluates a manifest file before anything is deployed. The cnspec scan github repo <org/repo> form, authenticated via GITHUB_TOKEN, extends the same idea to source repositories. Because evaluation happens client-side against read-only APIs, this is reconnaissance of a defensive kind — inventorying your own attack surface rather than someone else's.

The vulnerability side is a separate subcommand, cnspec vuln, and the README is specific that it is not container-only: it works for build-time artifacts and runtime hosts alike. cnspec vuln docker debian:12 checks an image, cnspec vuln ssh user@host and cnspec vuln winrm user@host --ask-pass cover remote Windows and Linux machines, cnspec vuln vsphere reaches VMware ESXi hypervisors, and cnspec vuln local sweeps the local host. The supported-platform matrix is unusually current — Debian through 13, RHEL/Rocky/AlmaLinux 10, Ubuntu 26.04, Windows 11 and Windows Server 2025, and ESXi 9 — which tells you the project is actively tracking enterprise release cycles rather than maintaining a stale list. Note the caveat in the README: vulnerability scanning requires the client to be logged into Mondoo Platform, so plan for that dependency.

One of the more underappreciated features is the interactive shell. cnspec shell local drops you into a REPL with tab-completion where you can explore the resource model that powers assertions — help lists every resource, and help ports shows, for instance, that ports.listening returns the TCP/IP ports in a listening state. You can then evaluate ad-hoc MQL expressions such as checking that no listening port is 23 (telnet), which is exactly the workflow you want before committing a rule to a policy file. The shell also attaches to remote targets, making it a usable interactive audit console, not just a debugging aid.

Custom policies are where teams will get durable value. Examples live in the examples folder and run with cnspec scan local -f examples/example.mql.yaml; authoring guidance is maintained in Mondoo's Policy Authoring Guide. Because policies are YAML, they diff cleanly in pull requests, which is the whole point of security-as-code: a proposed infrastructure change and its compliance impact can be reviewed in the same place. Once registered with cnspec login --token TOKEN, you can push custom bundles upstream with cnspec bundle upload mypolicy.mql.yaml so the whole fleet evaluates against the same ruleset.

The supported-target table in the README is long enough to read as a competitive statement. Beyond the obvious cloud and OS targets, cnspec reaches Active Directory domains, Alibaba Cloud, Arista and Cisco Catalyst network gear, Check Point management servers, Apache Cassandra clusters, Auth0 tenants, Atlassian orgs, Bitwarden organizations, CloudFormation templates, and Bicep/ARM files — the last two meaning misconfigured Azure IaC can be caught pre-deploy. Claude AI platform accounts appearing in the provider list is a sign of how quickly the project is chasing the SaaS surface area that traditional scanners ignore.

Architecturally, a few observations for operators: first, the wide provider surface means credential handling deserves attention — the CLI consumes cloud keys, SSH passwords, admin tokens, and API keys, so treat the CI runner or workstation holding them as a sensitive host and scope credentials read-only. Second, the NOASSERTION license flag in the repo metadata means you should verify licensing terms before redistributing or embedding cnspec in a product. Third, results go to STDOUT by default and to Mondoo Platform when authenticated, so teams wanting to stay fully local can build their own aggregation from CLI output or bundles in a private registry of YAML files.

Where this fits in an authorized workflow is straightforward: cnspec is a continuous audit layer. Run cnspec scan k8s manifest.yaml in CI on every pull request to shift misconfiguration detection left, gate image promotion with cnspec vuln docker <image>, and schedule cnspec scan aws and host-level scans for runtime drift. The identical policy engine running at build and runtime eliminates the classic gap where a hardened pipeline ships an image that then drifts in the cluster. For defenders, it's also worth remembering that a tool this broad is itself observable: scanning AWS accounts enumerates resources via normal API calls, so expect the corresponding CloudTrail entries — useful for detecting rogue or mis-scoped scanner credentials in your environment.

The honest critique is the platform coupling. Misconfiguration scanning and the interactive shell work standalone and are genuinely open source, but vulnerability data and risk prioritization sit behind Mondoo Platform, and the README's closing pitch is explicitly commercial. That doesn't diminish the tool — the default policies, the breadth of providers, and the MQL shell are substantial on their own — but teams evaluating cnspec should decide up front whether standalone posture checks suffice or whether they're comfortable with the SaaS dependency, and structure their deployment accordingly. Either way, as a policy-as-code engine that speaks cloud, container, Kubernetes, IaC, and endpoint in one grammar, cnspec earns a look from any team serious about continuous compliance.

Official project repository for mondoohq/cnspec.
Download Tool

Educational analysis for authorized security professionals. Use only in controlled, authorized environments.

Share articleFacebookXLinkedIn

Continue exploring

Browse all articles →

0 comentários:

Post a Comment

Note: Only a member of this blog may post a comment.