Query Filters
Query Filters help you refine search results by specifying the conditions InsightCloudSec searches for when identifying matching resources.
Query filters contribute to other functionality that helps you understand your risk and automate your actions:
- Insights combine Query Filters, scope, and reporting.
- Bots take action based on the output of Query Filters, scope, and Insights.
Go to Security > Query Filters to get started.
Refining query filters
Because we are continually updating the filtering toolset in response to cloud providers' newly released capabilities as well as customer requests, the list of filters is long. It is recommended that you refine your view by identifying the filters relevant to your needs and focusing on higher priority resources. You can narrow your view of using the search bar to find a specific Query Filter with keywords or terms, by scoping by supporting clouds or resource type, or by looking through specific versions of InsightCloudSec. Custom Query Filters are also included in the full listing. You can find them by sorting on the Owner column.
Inspecting Your Query Filters
To inspect the Query Filters in the results, click the Query Filter Name to view the internal Python code associated with this Query Filter. For example, the code associated with the Access List Contains Public IPs
Query Filter:
python
1@QueryRegistry.register(2query_id="divvy.query.access_list_contains_public_addresses",3name="Access List Contains Public IPs",4description="Match access lists which have at least one address that is neither RFC 1918, nor belongs to the "5"Unique Local Address range.",6supported_clouds=[7CloudType.ALICLOUD,8CloudType.AMAZON_WEB_SERVICES,9CloudType.AMAZON_WEB_SERVICES_GOV,10CloudType.AMAZON_WEB_SERVICES_CHINA,11CloudType.GOOGLE_CLOUD_PLATFORM,12CloudType.MICROSOFT_AZURE_ARM,13CloudType.MICROSOFT_AZURE_GOV,14CloudType.MICROSOFT_AZURE_CHINA,15CloudType.ORACLE_CLOUD,16],17supported_resources=[ResourceType.RESOURCE_ACCESS_LIST],18settings_config=[19BooleanField(20name="only_sgs",21display_name="Only Security Groups",22description="When enabled, only match rules associated with Security Groups",23),24],25version="18.1",26categories=[27Category.NETWORK,28],29)30def access_list_contains_public_addresses(query, db_cls, settings_config):31resource_ids = set()32session = query.session33subq = (34session.query(ResourceAccessListRule.parent_resource_id)35.filter(36ResourceAccessListRule.rule_action == "allow",37ResourceAccessListRule.direction == "ingress",38ResourceAccessListRule.source_network.isnot(None),39~ResourceAccessListRule.source_network.like("%sg-%"),40)41.filter(or_(and_(*REMOVE_PRIVATE_NETWORKS), ResourceAccessListRule.source_network == "Internet"))42)4344changeset_resource_ids = QueryRegistry.get_resource_ids_from_changeset(45settings_config, [ResourceType.RESOURCE_ACCESS_LIST]46)47if changeset_resource_ids:48subq = subq.filter(ResourceAccessListRule.parent_resource_id.in_(changeset_resource_ids))4950subq = subq.distinct()5152if settings_config.get("only_sgs"):53subq = subq.filter(~ResourceAccessListRule.parent_resource_id.like("%acl-%"))5455# Discount rules pending deletion56subq = filter_pending_deletion(query=subq, db_cls=ResourceAccessListRule, session=session)57for row in subq:58resource_ids.add(row.parent_resource_id)5960return query.filter(db_cls.resource_id.in_(resource_ids))
Using Query Filters with Bots
Query Filters are also used in the creation of Bots. For detailed step by step instructions check out Creating Bots. You can also view Working with Bots (Best Practices & Examples) if you want to work with some examples.
Using Query Filters With Resources
Query Filters are also found on the Resource Inventory. Review Resources for more information.