Announcing CloudQuery Policies
What’s inside? #
- HCL support: Policies can be written in HCL and/or JSON as the logical layer and SQL as the query layer.
- Native GitHub support: Policies can be downloaded and run directly from GitHub via the CQ CLI (
cloudquery policy download --help
) - Views: Users can create complex SQL views once and reference them in subsequent queries.
- Query and sub-policy execution: Users can execute specific queries or sub-policies via CQ CLI (
cloudquery policy run my-policy --sub-path=my-sub-policy
). - Inline policy functions: New inline policy functions are now available that allow users to define more dynamic policies. One example is the new file function that allows users to out-source query definitions to other files and to dynamically insert them during execution time.
Example Policies #
Basic #
policy "test-policy" {
description = "This is a test policy"
configuration {
provider "aws" {
version = ">= 1.0"
}
}
query "top-level-query" {
description = "Top Level Query"
query = "SELECT * FROM test_policy_table WHERE name LIKE 'peter'"
}
}
Views #
policy "test-policy" {
description = "This is a test policy"
configuration {
provider "aws" {
version = ">= 1.0"
}
}
view "myview" {
description = "My awesome view"
query "complex-query" {
query = "SELECT * FROM test_policy_table WHERE name LIKE 'john'"
}
}
query "top-level-query" {
description = "Top Level Query"
query = "SELECT * FROM myview"
}
}
Policy-In-Policy #
policy "test-policy" {
description = "Test Policy"
configuration {
provider "aws" {
version = ">= 1.0"
}
}
view "testview" {
description = "Test View"
query "testviewquery" {
query = "SELECT * FROM test_policy_table WHERE name LIKE 'john'"
}
}
query "top-level-query" {
description = "Top Level Query"
query = "SELECT * FROM test_policy_table WHERE name LIKE 'peter'"
}
policy "sub-policy-1" {
description = "Sub Policy 1"
query "sub-level-query" {
query = "SELECT * from testview"
expect_output = true
}
policy "sub-sub-policy-1" {
description = "Sub Sub Policy 1"
query "sub-sub-level-query" {
query = "SELECT * from test_policy_table WHERE name LIKE 'peter'"
}
}
}
policy "sub-policy-2" {
description = "Sub Policy 2"
query "sub-level-query" {
query = "SELECT * from test_policy_table WHERE name LIKE 'peter'"
}
}
}
Running #
cloudquery policy download cq-policy-core
cloudquery policy run cq-policy-core aws/cis-v1.20
cloudquery policy run cq-policy-core aws/[email protected]
cloudquery policy run cq-policy-core aws/cis-v1.20 --sub-path="aws-cis-section-1/1.1"
What’s Next? #
Written by Michel Vocks
Michel worked as a Senior Software Engineer at CloudQuery before going on to work at GitHub in the same role. During his time at CloudQuery, he helped to establish the foundations of the platform. Prior to joining the company, he held similar roles at a number of major companies in Germany. Michel is the founder of Gaia Pipeline.