How to run AWS CIS Benchmark with CloudQuery

Walkthrough on how to automate, validate and monitor AWS IAM Security best practices with CloudQuery
Yevgeny Pats
15 Feb · 8 min read


The AWS CIS benchmarks are a set of well-known configuration best-practices that helps companies improve their AWS security posture and comply with various compliance framework like (SOC2, etc...).

The guide is in PDF format, some instructions require going through the UI and others require running long set of commands. Doing this manually is a tedious and error prone work not talking about doing this continuously.

There are some open-source tools like prowler that runs all those commands in one large shell script. The dis-advantage with this kind of approach is that it is hard to customized and for example exclude resource that you know they are not compliant to get a clean report.

This blog will show you how to run AWS CIS benchmark with CloudQuery using out-of-the-box SQL statements that you can customized to your environment.

Running CloudQuery


CloudQuery is an open-source framework that transforms your cloud infrastructure into SQL or Graph database for easy monitoring, governance and security. It's written in Go so it's just a single Binary!

You can download the precompiled binary from releases, or using CLI:

export OS=Darwin # Possible values: Linux,Windows,Darwin curl -L${OS}_x86_64 -o cloudquery chmod a+x cloudquery

For mac you can use homebrew:

brew install cloudquery/tap/cloudquery # After initial install you can upgrade the version via: brew upgrade cloudquery

Choosing database

CloudQuery currently supports two types of databases: Relational - SQLite, MySQL, PostgreSQL, SQL Server and graph - Neo4j. In this post we will use the default SQLite which is great for local development and testing (see here on how to use others).

Authenticating with AWS

CloudQuery uses AWS SDK under-the-hood so authentication works the same way. To sum up you can use the following environment variables or files:

  • ~/.aws/credentials created via aws configure

Fetching the data

To fetch the data you first need to specify which resources you want to fetch. We will use the default that spceifies all the resources that are currently supported (you can customize it and comment out things you don't want).

To generate the default config.yml run cloudquery gen config aws which will output a config.yml ready to use in the current directory.

Now the money time! run cloudquery fetch . This will fetch all specified resources in all regions and in all accessible accounts (or specific accounts if specified).

Running AWS CIS benchmark test

We've created CloudQuery policy pack That runs all CIS checks with SQL statements so you know SQL you can easily customized it to your needs.

You can either download the above file or generate it via cloudquery gen policy aws_cis.

Now run cloudquery query to see results!

Here is a snippet of the report:

2021-01-14T14:52:30.061+0200 INFO Executing query {"name": "AWS CIS check 1.4. Ensure access keys are rotated every 90 days or less"} 2021-01-14T14:52:30.061+0200 INFO Check passed. Query returned no results. {"name": "AWS CIS check 1.4. Ensure access keys are rotated every 90 days or less"} 2021-01-14T14:52:30.061+0200 INFO Executing query {"name": "AWS CIS check 1.5. Ensure IAM password policy requires at least one uppercase letter"} 2021-01-14T14:52:30.061+0200 INFO Check failed. Query returned results. {"name": "AWS CIS check 1.5. Ensure IAM password policy requires at least one uppercase letter", "count": 1} +--------------+------------------------------+ | account_id | require_uppercase_characters | +--------------+------------------------------+ | REDACTED | 0 | +--------------+------------------------------+

You can also specify --output if you want also to store the results in JSON format so you can forward it to some logging system.

Running CloudQuery continuously

In the next blog we will show how to set-up CloudQuery in a lambda function to run periodically so you can continuously monitor your rules.

Subscribe for monthly updates.

Open-source, product updates, blog-posts, news and more.


All Rights Reserved.