Sample GraphQL Queries
© 2026 Sonrai Security. All rights reserved.
Overview
These samples show visibility (read-only) queries for the Sonrai GraphQL API. Every filter value is written directly into the query, so you can copy/paste a call and run it as-is — then edit the values in the where clause for your environment.
All account numbers, OUs, scopes, regions, emails, and other identifiers used in the samples on this page are placeholders — be sure to replace them for your environment before running your own queries or mutations.
Account & Hierarchy Discovery
List All Account Resource IDs & Scopes
query getCloudHierarchyList {
CloudHierarchyList(
where: {
entryType: { op: NEQ, value: "managementAccount" }
active: { op: EQ, value: true }
}
) {
count
items {
resourceId # Account number
scope # Scope string, used for other queries/mutations
rootScope
parentScope
scopeFriendlyName
name
cloudType
entryType
approvalType
metadata
reconcileMessage
owners {
id
name
email
sonraiUserId
}
createdAt
}
}
}
Count the Total Number of Cloud Accounts
CloudHierarchyList returns a count alongside items, so you can get an account total without retrieving every record. Each cloud names its account level differently — use IN_LIST across all three entryType values for a cross-cloud total, or a single value for a per-cloud count.
query getCloudAccountCount {
CloudHierarchyList(
where: {
entryType: {
op: IN_LIST
values: ["account", "subscription", "project"]
}
active: { op: EQ, value: true }
}
) {
count
}
}
account is the AWS account level, subscription is Azure, and project is GCP. Omitting the entryType filter returns a count of every node in the hierarchy — organizational units, management groups, folders, and resource groups included — not just accounts.
Sonrai Platform Specific APIs
List All Sonrai Platform Users, Roles & Last Login
query getSonraiUsers {
SonraiUsers {
items {
name
email
isActive
lastLogin
roleAssignments {
items { scope role { items { name } } }
}
}
}
}
List Global Settings and Retention Thresholds
CPFConfigs returns the organization-wide settings shown on the Global Settings page, including the dormancy and retention thresholds that several other queries on this page depend on. Each item reports the configured value alongside the Sonrai defaultValue, so you can see which settings have been changed from their defaults.
query getCPFConfigs {
CPFConfigs(
where: {
key: {
op: IN_LIST
values: [
"zombie_threshold_days"
"excessive_privilege_threshold_days"
"unused_service_threshold_days"
]
}
}
) {
count
items {
key
value # Currently configured value
defaultValue # Sonrai default
}
}
}
Omit the where argument entirely to return every setting. The keys below are the ones most often read alongside the other queries on this page:
| Key | Controls |
|---|---|
zombie_threshold_days | Days of inactivity before an identity is counted as a zombie by UnusedIdentities |
excessive_privilege_threshold_days | Lookback window used to decide whether a permission is unused when calculating excessive privilege |
unused_service_threshold_days | Days of inactivity before a service is reported by UnusedServices |
pond_request_ttl_in_sec | How long a Permissions on Demand (PoD) request stays open before it expires |
pond_escalation_interval_in_sec | How long CPF waits before escalating an unactioned PoD request to the next approver |
pond_deny_silence_time_in_sec | Quiet period after a denial during which repeat requests for the same permission are suppressed |
max_jit_session_grant_period_hrs | Longest duration that can be granted for a single Just-In-Time (JIT) Access session |
service_block_notify_interval_in_sec | Minimum interval between repeat service-block notifications |
session_idle_grace_period_in_sec | Idle time allowed before a JIT session is eligible for termination |
Read zombie_threshold_days first and pass its value as daysSinceLastLogin when querying UnusedIdentities. That keeps your API results consistent with the Zombie Identities count shown in the Cloud Permissions Firewall (CPF) interface.
Cloud Identity, Privilege & Usage Visibility Additional Filters
ListResourceSummaries queries can return millions of results depending on the size of your cloud deployment. In some scenarios, this may cause a timeout or an error in the results from the GraphQL endpoint. In that case, you should display results in a similar manner to this example.
query getResourceSummaries {
ListResourceSummaries(
where: {
label: { op: IN_LIST, values: ["User", "Role", "Group"] }
active: { op: EQ, value: true }
}
) {
totalCount
items(limit: 100, offset: 0) {
srn
label
account
cloudType
tags
accountName
name
usageLabel
identityLabels
effectiveaccessSrns
effectiveaccessNames
accesskeyNames
accesskeySrns
typeFriendlyName
type
__typename
}
__typename
}
}
Additional Filters
To filter the listresourcesummaries endpoint for specific types of resources, add a type clause to the where argument. Available types when filtering include:
- AWS IAM Users:
"User" - AWS Identity Center Users:
"SAML" - AWS Identity Center Groups:
"SAMLGroup" - AWS IAM Roles:
"Role" - AWS Account Root Users:
"Root" - AWS IAM Groups:
"Group" - Azure AD Users:
"ActiveDirectoryUser" - Azure AD Groups:
"ActiveDirectoryGroup" - Azure AD Enterprise Apps:
"ActiveDirectoryApp" - Azure System Assigned Managed Identity:
"AzureSystemAssignedManagedIdentity" - Azure User Assigned Managed Identity:
"AzureUserAssignedManagedIdentity" - GCP Workspace Groups:
"GCPGoogleGroup" - GCP Workspace Users:
"GCPUser" - GCP Cloud Service Accounts:
"GCPServiceAccount"
For example, the where clause below returns only resources of the type AWS IAM Roles.
query getRoles {
ListResourceSummaries(
where: {
active: { op: EQ, value: true }
type: { op: IN_LIST, values: ["Role"] }
}
) {
totalCount
items(limit: 100, offset: 0) {
srn
name
type
account
accountName
}
}
}
Get a count of all identities (User and Roles + Access Keys)
query IdentityTotal {
ListResourceSummaries(
where: {
serviceType: { op: EQ, value: "iam" }
type: { op: IN_LIST, values: ["Role", "User", "AWSAccessKey"] }
}
) {
Identities: totalCount
}
}
Get all IAM Users that have at least one access key
query getIAMUsersWithAccessKeys {
ListResourceSummaries(
where: {
type: { op: IN_LIST, values: ["User"] }
accesskeySrns: { op: ARRAY_NOT_EMPTY }
}
) {
items {
srn
name
type
account
accesskeyNames
accesskeySrns
}
}
}
Look Up CloudTrail Config
query IdentityTotal {
ListResourceSummaries(
where: { serviceType: { op: EQ, value: "cloudtrail" } }
) {
items {
srn
name
properties
}
}
}
Look Up SCPs and RCPs
{
AWSDirectPolicies(
where: { policySrn: { op: STARTS_WITH, value: "srn:aws:organizations" } }
) {
totalCount
items(
orderBy: {
policySrn: { order: ASC, precedence: 1 }
policyName: { order: ASC, precedence: 2 }
}
) {
# Policy Fields
policyName
policySrn
orgAccount: account
scpAttachmentPoint: resource {
srn
}
policyType: policySrn @regex(match: ".*/Policy/(\\w+)/.*", replace: "$1")
policy: properties @jsonPath(path: "$.policy")
}
}
}
Getting Cloud Actions (Only Queries the Last 24 Hours)
query getCloudActions {
ListCloudActions(
where: {
timestamp: { op: GT, function: { dateTimeNow: { offsetDays: -1 } } }
eventName: { value: "Microsoft.Storage/storageAccounts/listKeys/action" }
succeeded: { op: EQ, value: true }
resourceSrns: {
op: ARRAY_CONTAINS
replacer: {
key: "values"
graphqlQuery: "{ ListResourceSummaries( where: { serviceType: { value: \"Microsoft.Storage\" }, label: { value: \"DataStore\" }, properties: { op: NOT_CONTAINS, key: { value: \"storageAccount.properties.allowSharedKeyAccess\" }, booleanValue: { op: EQ, value: false } } } ) { items { srn } } }"
jsonPath: ".srn"
}
}
}
) {
count
items {
eventName
# timestamp
actionClassifications
succeeded
srcIp
userAgent
account
type
serviceType
resourceSrns
actorSrns
}
}
}
Get all Actions for a Specific Identity (Only Queries the Last 24 Hours)
query getActionsForIdentity {
ListCloudActions(
where: {
timestamp: { op: GT, function: { dateTimeNow: { offsetDays: -1 } } }
succeeded: { op: EQ, value: true }
actorSrns: {
op: ARRAY_CONTAINS
values: ["srn:aws:iam::123456789012/Role/my_role"]
}
}
) {
count
items {
eventName
# timestamp
actionClassifications
succeeded
srcIp
userAgent
account
type
serviceType
resourceSrns
actorSrns
}
}
}
List Identities That Have Used a Specific Permission
This example returns a list of identities that have used the sts:GetCallerIdentity permission.
query getCallerIdentityRollup {
CloudActionRollup(
where: {
cloudType: { value: "aws" }
permission: { op: ILIKE, value: "sts:getCallerIdentity" }
}
) {
items {
actorName
account
actorId
ssoActorId
permission
lastused: timestamp
count
succeeded
userAgent
}
}
}
All API Actions Called by a specific role, how many times, and the last time used
query getCallerIdentityRollup {
CloudActionRollup(
where: {
cloudType: { value: "aws" }
actorId: { op: ILIKE, value: "arn:aws:iam::730335488484:role/sonrai-collector-stage16438869" }
}
) {
items {
actorName
account
actorId
permission
lastused: timestamp
count
succeeded
userAgent
}
}
}
All API Actions Called by a specific SSO User, how many times, and the last time used
query getCallerIdentityRollup {
CloudActionRollup(
where: {
cloudType: { value: "aws" }
ssoActorId: { op: ILIKE, value: "my.user@domain.com" }
}
) {
items {
actorName
account
ssoActorId
permission
lastused: timestamp
count
succeeded
userAgent
}
}
}
List Identities With Excessive Privileges in a Scope
query getExcessivePrivilegeIdentitiesCount {
ExcessiveIAMPrivilege(where: { scope: { value: "aws/r-xxxxx", op: STARTS_WITH } }) {
count # Identities holding more privilege than they use
protectedCount # How many of those CPF already protects
identityLabels {
label # Comma-delimited label set, for example "ADMIN,NON PERSON,PRIVILEGED"
count
}
}
}
List Unused (Dormant) Identities in an Account
Unused identities are the same population the Cloud Permissions Firewall (CPF) interface labels zombie identities: identities that have not been used within the dormancy window. Set daysSinceLastLogin to the value of the zombie_threshold_days global setting so your results match the interface — see List Global Settings and Retention Thresholds.
query getUnusedIdentities {
UnusedIdentities(
where: {
scope: {
value: "aws/r-xxxxx/ou-xxxx-yyyyy/123456789012"
op: EQ
}
daysSinceLastLogin: { op: EQ, value: "90" }
}
) {
count # Total dormant identities matching the filter
items {
account
count
identities {
actorId
actorName
scope
timestamp # Last used; null when the identity has never been used
identityLabels
}
}
}
}
UnusedIdentitiesFilter has no account field. To scope results to a single account, filter on that account's full scope string as shown above.
Additional filters available on UnusedIdentitiesFilter:
| Filter | Purpose |
|---|---|
neverUsed | Return only identities that have never been used, rather than ones that have gone dormant |
identityType | Restrict to a specific identity type, for example Role or User |
identityLabels | Restrict to identities carrying specific labels, for example AI-AGENT or PRIVILEGED |
actorId | Look up a single identity by its cloud identifier |
createdDate | Filter on when the identity was created |
lastUsedDate | Filter on an absolute last-used date instead of a relative day count |
identitySearch | Free-text match against identity names |
To get per-account totals instead of the identity detail — the roll-up the Zombie Identities card shows — swap identities for the identityLabels aggregate and widen the scope filter to STARTS_WITH:
query getUnusedIdentities {
UnusedIdentities(
where: {
scope: { op: STARTS_WITH, value: "aws/r-xxxxx" }
daysSinceLastLogin: { op: EQ, value: "90" }
identitySearch: ""
}
) {
count # Total across every account in scope
identityLabels {
label
count
}
items {
account
count
identityLabels {
label
count
}
}
}
}
List the number of identities that can use an Identities Center PermissionSet Role
query getPermissionSets {
PermissionSets(where: { scope: { op: EQ, value: "aws/r-xxxxx/ou-xxxxx-yyyyy/123456789012" } }) {
items {
name
identityLabels
userCount
}
}
}
List Excessive Privilege Accounts & Identity Counts
query getExcessivePrivilegeAccounts {
ExcessiveIAMPrivilege(
where: {
scope: { op: STARTS_WITH, value: "aws/r-xxxxx" }
identitySearch: ""
}
) {
items {
account
accountName
scope
identityCount
protectedIdentityCount
identityLabels {
label
count
}
}
}
}
List Quarantined Identities
Returns the identities currently held in quarantine, matching the Quarantine List in the Cloud Permissions Firewall (CPF) interface. IdentitiesInQuarantine also returns a count, so you can retrieve the total on its own by omitting items.
query getQuarantinedIdentities {
IdentitiesInQuarantine(where: { scope: { op: STARTS_WITH, value: "aws/r-xxxxx" } }) {
count
items {
srn
resourceId
name
account
scope
quarantinedOn # Epoch milliseconds
quarantinedBy
quarantinedByFriendlyName
lastUsed # Epoch milliseconds
inTransaction # True while a quarantine change is still being applied
}
}
}
IdentitiesInQuarantineFilter also accepts account, name, srn, resourceId, and quarantinedOn for narrowing the result set.
quarantinedOn and lastUsed are returned as epoch milliseconds, not ISO timestamps.
Policy & Service Visibility
Get Sensitive Permissions in a Service at Scope
Returns every service CPF knows about at a scope, ordered by how many sensitive permissions each one carries. This is the data behind the Services page.
query getCloudServices {
CloudServices(where: { scope: { op: EQ, value: "aws/r-xxxxx" } }) {
items(orderBy: { sensitivePermissionCount: { order: DESC } }) {
service: name # "Amazon EC2"
serviceType: type # Category, such as "Compute Services"
controlKey # Short service key, such as "ec2"
description
sensitivePermissionCount
inUse # Accounts where the service is in use
protectedInUse # Of those, how many are protected
accounts # Accounts in scope
pending # Accounts with a change still being applied
usage # "USED" or "UNUSED"
criticalService
unmonitored
availableControls # Controls the service supports, such as "Permissions" or "ServiceBlock"
availableActions # Actions you can take now, such as "protect" or "disable"
suggestedAction
createdDate
status {
status # "Protected", "Partially Protected", "Unprotected", "Disabled"
isStatusPending: isPending
}
}
}
}
The schema fields are name, type, and status.isPending. There is no service, serviceType, or status.isStatusPending field — selecting those names directly returns a validation error. Alias them as shown if you want the friendlier names in your response.
List Unused Services
UnusedServices returns the services that have gone unused across a scope — the population behind the Unused Services card and its one-click service block. A service is reported here once it has been unused for unused_service_threshold_days.
query getUnusedServices {
UnusedServices(where: { scope: { op: STARTS_WITH, value: "aws/r-xxxxx" } }) {
count
items {
controlKey
serviceFriendlyName
serviceType
fullyUnused # True when the service is unused in every account in scope
unusedScopes {
scope
friendlyScope
}
}
}
}
When fullyUnused is false, unusedScopes lists only the accounts where the service is unused — the service is still in use elsewhere in the scope.
Describe an AWS Resource Policy
query fetchResourcePolicy {
DescribeAWSDirectPolicy(where: { srn: { op: EQ, value: "srn:aws:s3::123456789012/DataContainer/example-bucket" } }) {
items {
policyJson
}
}
}
List IAM Policies for a Role
query getIamPolicy {
AWSDirectPolicies(where: { srn: { op: EQ, value: "srn:aws:iam::123456789012/Role/ExampleRole" } }) {
totalCount
items {
policySrn
policyName
}
}
}
List Policy JSONs for a Role
query getPolicyJsons {
DescribeAWSDirectPolicy(
where: {
srn: { op: EQ, value: "srn:aws:iam::123456789012/Role/ExampleRole" }
account: { op: EQ, value: "123456789012" }
}
) {
items {
policyName
type
policySrn
policyJson
}
}
}
Permissions On Demand & JIT
List All Permissions on Demand (PoD) Requests
Returns the request history behind the Requests page. The type field distinguishes what was asked for, so a single query covers every request category — filter on it to narrow the results.
query getPONDRequestList {
PONDRequests(
where: {
rootScope: { op: EQ, value: "aws/r-xxxxx" }
status: { op: NEQ, value: "UNMANAGED" }
firstRequested: { op: GTE, value: "2026-01-01T00:00:00.000+00:00" }
type: { op: NEQ, value: "SERVICE_BLOCK" }
}
) {
count
items(orderBy: { lastRequested: { order: DESC } }) {
pondRequestId
type # "ACCESS", "JIT", "REANIMATE", or "SERVICE_BLOCK"
status
identity
identityFriendlyName
isSSO
account
accountFriendlyName
scope
scopeFriendlyName
cloudType
serviceFriendlyName
serviceType
requestCount
firstRequested
lastRequested
expireAt
nextEscalation
requestedDuration # Hours of access requested
approvalType # "ASSIGNED_APPROVERS" or "EVERYONE_AT_SCOPE"
actionedBy
actionedByFriendlyName
actionedAt
requesterEmail
requesterComment
comment
hasEntitlement
jitLevel
jitLevelName
jitSessionId # Set once an approved JIT request opens a session
quarantinedOn
approvers {
name
email
}
permissions {
permission
description
}
}
}
}
status reports where a request sits in its lifecycle: PENDING, DENIED, REVOKED, EXPIRED, ABANDONED, or ABANDONED_EXPIRED. Requests for identities CPF does not manage are returned as UNMANAGED — the example above filters those out.
Count Active Just-In-Time (JIT) Access Sessions
JitSessions returns the JIT sessions opened across a scope. Select count on its own for a total, or include items for the session detail.
query getJitSessions {
JitSessions(where: { scope: { op: STARTS_WITH, value: "aws/r-xxxxx" } }) {
count
items {
id
identity
identityFriendlyName
scope
friendlyScope
permissionSet {
id
name
}
isFullAccess
jitLevel
jitLevelName
dateAccessed
expiry
approvedAt
approvedBy
approvedByFriendlyName
pondRequestId # The PoD request this session was opened from
}
}
}
A session whose expiry is in the past has already ended. To count only the sessions that are currently live, compare expiry against the current time in your own code — the API returns completed sessions alongside active ones.
List Just-In-Time (JIT) Access Enrolled Accounts
JitConfiguration returns one item per scope that has JIT configuration, with the permission sets enrolled at that scope and whether deny-first is in effect. An account is enrolled when it has at least one permission set with a status.status of ENROLLED.
query getJitConfiguration {
JitConfiguration(where: { scope: { op: STARTS_WITH, value: "aws/r-xxxxx" } }) {
count
items {
scope
friendlyScope
autoPod
denyFirst {
isEnabled
isInherited
isPending
}
permissionSets {
name
isFullAccess
isInherited
status {
status # "ENROLLED" when the permission set is under JIT control
isPending
}
}
}
}
}
JitConfigurationFilter also accepts active and purpleEnabled for narrowing the result set.
Third Party & Region Visibility
Fetch All Third Parties With Access
query getThirdParties {
ThirdParties(where: { scope: { value: "aws/r-xxxxx", op: EQ } }) {
count
items {
thirdPartyId
thirdPartyFriendlyName
source # How the third party was identified
displayOnly # True when the third party is reported but not controllable
createdDate
lastAccessed # Epoch milliseconds
accountCount
thirdPartyAccounts
status {
state
pending # True while a block or allow change is still being applied
}
labels {
name
severity
}
resources {
service
resourceType
resourceTypeFriendlyName
count
}
thirdPartyAccountList {
account
hasAccessTo
source
}
iamAccess {
roleCount
}
identityLabels {
label
count
}
}
}
}
List Third Party IAM Access by Account
query getThirdPartyIamAccess {
ThirdPartyAccessByAccount(
where: {
scope: { op: EQ, value: "aws/r-xxxxx" }
thirdPartyId: { op: EQ, value: "third-party-uuid-1234" }
}
) {
count
items {
scope
scopeFriendlyName
labels {
name
severity
}
status {
state
}
roles {
roleName
lastAccessed
}
}
}
}
List Third Party Access by Resource
query getThirdPartyResources {
ThirdPartyAccessByResource(
where: {
scope: { op: EQ, value: "aws/r-xxxxx" }
thirdPartyId: { op: EQ, value: "third-party-uuid-1234" }
}
) {
items {
resourceName
resourceType
serviceFriendlyName
service
account
scope
labels {
name
severity
}
}
}
}
List All Regions for a Scope
query getRegions {
RegionsControls(where: { Scope: { op: STARTS_WITH, value: "aws/r-xxxxx" } }) {
items {
regionId
regionName
status {
status
pending
}
coordinates {
lat
long
}
criticalRegion
cloudType
}
}
}