website logo
HomeGithubSlack
⌘K
Overview
Quick Start
Supported Services
Running CloudGraph in EKS
Compliance
Rules Engine
AWS
Querying AWS Data
AWS Policy Packs
Billing Data
Services
Azure
Querying Azure Data
Azure Policy Packs
Services
GCP
Querying GCP Data
GCP Policy Packs
Services
K8s
Querying Kubernetes Data
Services
Docs powered by archbee 

KMS

18min

Note: if you are running CloudGraph locally you can view the interactive, automatically generated documentation in either GraphQL Playground or Altair by clicking the docs button on the right-hand side of the screen. After reading the below information we highly suggest you use one of these tools to test your queries as they will autocomplete fields for you and let you know if your queries are valid before you even submit them.

Overview

You can currently query the following attributes and connections on an AWS KMS

GraphQL
|
query {
  queryawsKms {
    id
    accountId
    arn
    region
    description
    keyRotationEnabled
    usage
    policy {
      id
      # Other fields and connections here...
    }
    enabled
    keyState
    customerMasterKeySpec
    creationDate
    keyManager
    origin
    deletionDate
    validTo
    tags {
      id
      key
      value
    }
    lambda {
      arn
      # Other fields and connections here...
    }
    cloudtrail {
      arn
      # Other fields and connections here...
    }
    redshiftCluster {
      arn
      # Other fields and connections here...
    }
    sns {
      arn
      # Other fields and connections here...
    }
    eksCluster {
      arn
      # Other fields and connections here...
    }
  }
}


Filtering

Get data for a single AWS KMS key that you know the ID or arn for:

GraphQL
|
query {
  getawsKms(id: "12345") {
    arn
    # Other fields and connections here...
  }
}

GraphQL
|
query {
  getawsKms(
    arn: "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"
  ) {
    arn
    # Other fields and connections here...
  }
}


Get data for all of the KMS keys in a certain AWS account:

GraphQL
|
query {
  queryawsKms(filter: { accountId: { eq: "12345" } }) {
    arn
    # Other fields and connections here...
  }
}

# Note that in addition to "accountId" you can
# Filter based on any of the following attributes:

# id
# arn
# region
# description // can use fulltext filters
# keyRotationEnabled
# usage
# enabled
# keyState
# customMasterKeySpec
# creationDate
# keyManager
# origin
# deletionDate
# validTo

# And the following Dgraph filters can also be applied:

# has
# and
# or
# not
# regexp (regular expressions)

# fulltext filters

# alloftext
# anyoftext


Get data for all of the KMS keys that are NOT in a certain AWS account:

GraphQL
|
query {
  queryawsKms(filter: { not: { accountId: { eq: "12345" } } }) {
    arn
    # Other fields and connections here...
  }
}


Advanced Filtering

Get data for all of the KMS keys that have a connected cloudtrail:

GraphQL
|
query {
  queryawsKms(filter: { has: cloudtrail }) {
    arn
    # Other fields and connections here...
  }
}

# Note that in addition to "cloudtrail" you can filter
# Using "has" based on any of the following attributes:

# description
# keyRotationEnabled
# usage
# policy
# enabled
# keyState
# customMasterKeySpec
# tags
# creationDate
# keyManager
# origin
# deletionDate
# validTo
# lambda
# redshiftCluster
# sns
# eksCluster


Use multiple filter selectors, (i.e. has, and, not, or) to get data for all of the KMS keys that have cloudtrail instances AND lambda instances connected to them OR that do not have sns instances connected to them. Note that you can use has, and, not, or completely independently of each other:

GraphQL
|
query {
  queryawsKms(
    filter: { has: cloudtrail, and: { has: lambda }, or: { not: { has: sns } } }
  ) {
    arn
    # Other fields and connections here...
  }
}


You may also filter using a regex when filtering on a string field like, description if you want to look for a value that matches say, important:

GraphQL
|
query {
  queryawsKms(filter: { description: { regexp: "/.*important*/" } }) {
    arn
    # Other fields and connections here...
  }
}


Ordering

You can order the results you get back either asc or desc depending on your preference:

GraphQL
|
query {
  queryawsKms(order: { desc: creationDate }) {
    arn
    # Other fields and connections here...
  }
}

# Note that in addition to "creationDate" you can filter
# Using "asc" or "desc" based on any of the following attributes:

# id
# accountId
# arn
# region
# description
# keyRotationEnabled
# usage
# policy
# enabled
# keyState
# customMasterKeySpec
# keyManager
# origin
# deletionDate
# validTo


Only select and return the first two KMS keys that are found:

GraphQL
|
query {
  queryawsKms(first: 2, order: { desc: creationDate }) {
    arn
    # Other fields and connections here...
  }
}


Only select and return the first two KMS keys that are found, but offset by one so keys two & three are returned:

GraphQL
|
query {
  queryawsKms(first: 2, order: { desc: creationDate }, offset: 1) {
    arn
    # Other fields and connections here...
  }
}


Aggregation

Count the number KMS keys across all scanned AWS accounts:

GraphQL
|
query {
  aggregateawsKms {
    count
    # Other fields and connections here...
  }
}

# Note that in addition to "count" you can request the
# Following min and max values based on attributes of your KMS keys:

# idMin
# idMax
# accountIdMin
# accountIdMax
# arnMin
# arnMax
# regionMin
# regionMax
# descriptionMin
# descriptionMax
# keyRotationEnabledMin
# keyRotationEnabledMax
# usageMin
# usageMax
# policyMin
# policyMax
# enabledMin
# enabledMax
# keyStateMin
# keyStateMax
# customMasterKeySpecMin
# customMasterKeySpecMax
# creationDateMin
# creationDateMax
# keyManagerMin
# keyManagerMax
# originMin
# originMax
# deletionDateMin
# deletionDateMax
# validToMin
# validToMax


Count the number of KMS keys in a single account. Note that you can apply all of the same filters that are listed above to aggregate queries:

GraphQL
|
query {
  aggregateawsKms(filter: { accountId: { eq: "12345" } }) {
    count
    # Other fields and connections here...
  }
}


Examples

Find all of the KMS keys that are in the us-east-1 region across all your accounts:

GraphQL
|
query {
  queryawsKms(filter: { region: { eq: "us-east-1" } }) {
    arn
    # Other fields and connections here...
  }
}


Find all of the KMS keys that have a tag of Environment:Production for a single AWS Account:

GraphQL
|
query {
  queryawsTag(
    filter: { key: { eq: "Environment" }, value: { eq: "Production" } }
  ) {
    kms(filter: { accountId: { eq: "12345" } }) {
      arn
      # Other fields and connections here...
    }
  }
}


With CloudGraph you can run multiple queries at the same time so you can combine the above two queries if you like:

GraphQL
|
query {
  queryawsKms(filter: { region: { eq: "us-east-1" } }) {
    arn
    # Other fields and connections here...
  }
  queryawsTag(
    filter: { key: { eq: "Environment" }, value: { eq: "Production" } }
  ) {
    kms(filter: { accountId: { eq: "12345" } }) {
      arn
      # Other fields and connections here...
    }
  }
}


Kitchen Sink

Putting it all together; get all data for all KMS keys across all regions for all scanned AWS accounts in a single query. For the purposes of this example we will only get direct children of the keys but if you want to it's easy to go from say, kms -> lambda -> vpc ...etc:

GraphQL
|
query {
  queryawsKms {
    id
    accountId
    arn
    region
    description
    keyRotationEnabled
    usage
    policy{
      id
    }
    enabled
    keyState
    customerMasterKeySpec
    tags {
      id
      key
      value
    }
    creationDate
    keyManager
    origin
    deletionDate
    validTo
    cloudtrail {
      id
      cgId # Special id CloudGraph uses to make multi-region/multi-account cloudtrails unique
      accountId
      arn
      name
      region
      s3BucketName
      s3KeyPrefix
      includeGlobalServiceEvents
      isMultiRegionTrail
      homeRegion
      logFileValidationEnabled
      cloudWatchLogsLogGroupArn
      cloudWatchLogsRoleArn
      kmsKeyId
      hasCustomEventSelectors
      hasInsightSelectors
      isOrganizationTrail
      tags {
        id
        key
        value
      }
      s3 {
        arn
        # Other fields and connections here...
      }
      sns {
        arn
        # Other fields and connections here...
      }
      kms {
        arn
        # Other fields and connections here...
      }
    }
    redshiftCluster {
      id
      accountId
      arn
      allowVersionUpgrade
      automatedSnapshotRetentionPeriod
      availabilityZone
      clusterAvailabilityStatus
      clusterCreateTime
      clusterRevisionNumber
      clusterStatus
      clusterSubnetGroupName
      clusterVersion
      dBName
      encrypted
      enhancedVpcRouting
      manualSnapshotRetentionPeriod
      masterUsername
      modifyStatus
      nodeType
      numberOfNodes
      preferredMaintenanceWindow
      publiclyAccessible
      tags {
        id
        key
        value
      }
      kms {
        arn
        # Other fields and connections here...
      }
      vpc {
        arn
        # Other fields and connections here...
      }
    }
    sns {
      id
      accountId
      arn
      policy{
        id
      }
      displayName
      deliveryPolicy
      subscriptions {
        id
        arn
        endpoint
        protocol
      }
      tags {
        id
        key
        value
      }
      cloudtrail {
        arn
        # Other fields and connections here...
      }
      kms {
        arn
        # Other fields and connections here...
      }
    }
    lambda {
      id
      accountId
      arn
      region
      description
      handler
      kmsKeyArn
      lastModified
      memorySize
      reservedConcurrentExecutions
      role
      runtime
      sourceCodeSize
      timeout
      tracingConfig
      version
      environmentVariables {
        id
        key
        value
      }
      tags {
        id
        key
        value
      }
      kms {
        arn
        # Other fields and connections here...
      }
      securityGroups {
        arn
        # Other fields and connections here...
      }
      subnet {
        arn
        # Other fields and connections here...
      }
      vpc {
        arn
        # Other fields and connections here...
      }
      cognitoUserPool {
        arn
        # Other fields and connections here...
      }
    }
    eksCluster {
      id
      accountId
      arn
      name
      createdAt
      version
      endpoint
      status
      clientRequestToken
      platformVersion
      encryptionConfig {
        id
        resources
        provider {
          keyArn
        }
      }
      certificateAuthority {
        data
      }
      logging {
        clusterLogging {
          id
          types
          enabled
        }
      }
      identity {
        oidc {
          issuer
        }
      }
      resourcesVpcConfig {
        subnetIds
        securityGroupIds
        clusterSecurityGroupId
        vpcId
        endpointPublicAccess
        endpointPrivateAccess
        publicAccessCidrs
      }
      kubernetesNetworkConfig {
        serviceIpv4Cidr
      }
      tags {
        id
        key
        value
      }
      iamRoles {
        arn
        # Other fields and connections here...
      }
      kms {
        arn
        # Other fields and connections here...
      }
      securityGroups {
        arn
        # Other fields and connections here...
      }
      subnet {
        arn
        # Other fields and connections here...
      }
      vpc {
        arn
        # Other fields and connections here...
      }
    }
  }
}


References

Dgraph documentation on querying

AWS KMS documentation

Updated 03 Mar 2023
Did this page help you?
Yes
No
PREVIOUS
ElastiCache Cluster
NEXT
Lambda
Docs powered by archbee 
TABLE OF CONTENTS
Overview
Filtering
Advanced Filtering
Ordering
Aggregation
Examples
Kitchen Sink
References