βQuery Search
Last updated
Last updated
This page describes how P0's IAM-Assessment query searches work.
Query searches are controlled using two parts:
show - controls which kind of data are displayed
where - controls which data to show
Currently, you can choose to "show" credentials (access keys or short-term authentication), principals (users, groups, machine identities, and so forth), grants (in Google Cloud, a role binding; in AWS, a policy attachment), or resources (projects, accounts, services, and individual resources such as storage buckets).
The "where" control is a free-form search box. You can enter any term here, and P0 will find the principals or grants that relate to your search term.
Example:
Searching for a permission (in this case compute.instances.create
in a Google Cloud assessment) will show you all grants that provide that permission:
To see why a search result matches your query, you can click on that result's "view" link. The details page will show an "Explanation" section at the bottom, describing how that result satisfies your query:
You can be more specific in your queries by writing query expressions. This section explains each type of query expression
Here's a summary of query expressions:
Cypher equivalents
Each detailed explanation below also describes the equivalent statement in the Cypher query language (replace {show}
with the corresponding label of the "show" control).
When displaying data as a table, the displayed data are the nodes matching the "show" type (represented by s
in the equivalent queries); when displaying data as a graph visualization, the displayed data are the returned paths (represented by p
in the equivalent queries).
In it's simplest usage, P0 matches IAM data as long as it includes your search keyword. In the above example, searching for compute
will show you grants that allow access to any compute resource, provide any privileges with "compute" in their name, grant a permission set with "compute" in its name, or grant access to compute service principals.
"Contains" matches are case insensitive; use Exact matches to find data with exact casing.
Cypher equivalent:
To match data exactly, enclose your keyword in double quotes. E.g., searching for compute.instances.get
in GCP will match additional permissions, such as compute.instances.getEffectiveFirewalls
. Searching for"compute.instances.get"
will limit results to only those grants that have that specific permission.
When using exact matches with type and attribute matches, the quotes surround the keyword only: type:attribute:"keyword"
.
You can also use quotes to search for data where the data includes a colon without triggering a type or attribute match. E.g., risk:"exfiltration:data"
will return all results that yield a data exfiltration risk.
Cypher equivalent:
You can search for grants and principals that are connected to data that don't match a keyword by typing a !
in front of your search keyword.
Note that using an inverted match on its own usually won't do much, as grants and principals are connected to many data, and some of these data are likely to not match your keyword. Instead, inverted matches are usually best when combined with type or attribute matches, or with exclusion matches. For example, principal:mfa:!enabled
will show you all users that have either disabled or unknown MFA status.
When using inverted matches with type and attribute matches, the !
comes after the type and attribute: type:attribute:!keyword
.
Cypher equivalent:
You can search for items that are not connected to data that match a term by typing a ^
in front of your entire search term.
For example, searching for ^usage:type:"unused"
will show all grants that have only used or unknown permission usage. Searching for ^usage:type:!"unused"
will show all grants where all permissions are unused.
When using exclusion matches, the ^
comes before the type and attribute: ^type:attribute:keyterm
.
Cypher equivalent:
You can use a type match without a keyword to search for the presence of data.
For example, condition:
will show you all conditional grants.
Cypher equivalent:
Data may be connected to a chain of items of the same type. For instance, a grant on a resource will give access to all that resource's children, and all those child resources' children, and so forth. Or, grants may be made to directory groups with nested group membership.
To restrict your search to only the first item in such a chain, use a first match. For example, principal=alice@my.co
will show only the alice@my.co
user, and not the groups to which that user belongs.
Cypher equivalent:
First and attribute matches may be combined using the syntax {type}={attribute}:{keyterm}
.
Cypher equivalent:
Return items that are connected to multiple data by separating search terms using whitespace.
For instance, resource:one resource:two
will show you grants that provide access to both resources "one" and "two".
Cypher equivalent:
Your IAM data are modeled as a directed graph. You can require data to be connected to your search results according to multiple search terms using a via match.
To use a via match, connect two or more terms using ->
.
For example, to find all grants that have unused permissions that create a data exfiltration risk, you can search for usage:type:"unused"->risk:"exfiltration:data"
.
You can chain multiple terms together using additional ->
. For example usage:type:"unused"->action:s3->risk:"exfiltration:data"
.
Exclusion matches combined with via matches will return results where one or more of the via conditions do not match.
Cypher equivalent:
One of the best resources for constructing queries is to view the search queries for P0's built-in assessment monitors.
For instance, here's the query for detecting unused service account keys:
show = credential
This returns all service-account keys that have not been used in the last 40 days.
You can also construct queries using tooltips in the displayed data. To do this, hover over an item you want to either include or exclude from your search:
Select the corresponding "show" or "hide" link to either include or exclude that item in your search results.
Expression | See | |
---|---|---|
Limit your search to a specific type of IAM data using a type prefix. For example, adding risk:CRITICAL
in front of your search will limit your search to only showing grants that allow a critical IAM risk (as defined by the IAM Privilege Catalog). See for a list of all possible types.
Attribute expressions allow you to make even more specific searches. For example, searching for credential:last90:unused
will limit displayed principals to those with at least one credential that has not been used in the previous 90 days. See for a list of all possible attributes.
You can reference how data are connected in this graph using .
Key terms
{keyword}
Match data substring
"{keyword}"
Match data exactly
!{keyword}
Invert keyword matches
Path terms
{type}:{keyterm}
Match data types
{type}={keyterm}
Match first datum only
{type}:{attribute}:{keyterm}
Match data attributes
{pathterm}->{pathterm}
Place multiple conditions on a data connection
Exclusion term
^{pathterm}
Remove matches from results
Compound expression
{expression} {term}
Require multiple data connections