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
AWS
...
Services
IAM

IAM User

14min

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 IAM User

GraphQL
query {
  queryawsIamUser {
    id
    arn
    accountId
    path
    name
    creationTime
    passwordLastUsed
    accessKeyData {
      accessKeyId
    }
    groups
    tags {
      id
      key
      value
    }
    iamGroups {
      arn
    }
  }
}


Filtering

Get data for a single AWS IAM User that you know the ID for:

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


Get data for all of the IAM Users in a certain AWS account:

GraphQL
query {
  queryawsIamUser(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
# path
# name
# creationTime
# passwordLastUsed

# 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 IAM Users that are NOT in a certain AWS account:

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


Advanced Filtering

Get data for all of the IAM Users that are members of a group:

GraphQL
query {
  queryawsIamUser(filter: { has: iamGroups }) {
    arn
    # Other fields and connections here...
  }
}

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

# id
# arn
# accountId
# path
# name
# creationTime
# passwordLastUsed
# accessKeyData
# groups
# tags
# iamGroups


Use multiple filter selectors, (i.e. has, and, not, or) to get data for all of the IAM Users that are part of Groups AND have Access Key data OR that do not have Tags. Note that you can use has, and, not, or completely independently of each other:

GraphQL
query {
  queryawsIamUser(
    filter: {
      has: iamGroups
      and: { has: accessKeyData }
      or: { not: { has: tags } }
    }
  ) {
    arn
    # Other fields and connections here...
  }
}


You may also filter using a regex when filtering on a string field like, name if you want to look for a value that contains the word, production (case insensitive):

GraphQL
query {
  queryawsIamUser(filter: { name: { regexp: "/.*production.*/i" } }) {
    arn
    name
    # Other fields and connections here...
  }
}


Ordering

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

GraphQL
query {
  queryawsIamUser(order: { desc: creationTime }) {
    creationTime
    # Other fields and connections here...
  }
}

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

# id
# arn
# accountId
# path
# name
# passwordLastUsed


Only select and return the first two IAM Users that are found:

GraphQL
query {
  queryawsIamUser(first: 2, order: { desc: creationTime }) {
    creationTime
    # Other fields and connections here...
  }
}


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

GraphQL
query {
  queryawsIamUser(first: 2, order: { desc: creationTime }, offset: 1) {
    creationTime
    # Other fields and connections here...
  }
}


Aggregation

Count the number of IAM Users across all scanned AWS accounts:

GraphQL
query {
  aggregateawsIamUser {
    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 IAM Users:

# idMin
# idMax
# arnMin
# arnMax
# accountIdMin
# accountIdMax
# pathMin
# pathMax
# nameMin
# nameMax
# creationTimeMin
# creationTimeMax
# passwordLastUsedMin
# passwordLastUsedMax


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

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


Examples

Find all the IAM Users that for your dev env:

GraphQL
query {
  queryawsIamUser(filter: { name: { regexp: "/.*dev.*/i" } }) {
    arn
    name
    # Other fields and connections here...
  }
}


Find all the IAM Users in account 12345:

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


Find all of the IAM Users that have a tag of Environment:Production for a single AWS Account:

GraphQL
query {
  queryawsTag(
    filter: { key: { eq: "Environment" }, value: { eq: "Production" } }
  ) {
    iamUsers(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 {
  queryawsIamUser(filter: { accountId: { eq: "12345" } }) {
    arn
    # Other fields and connections here...
  }
  queryawsTag(
    filter: { key: { eq: "Environment" }, value: { eq: "Production" } }
  ) {
    iamUsers(filter: { accountId: { eq: "12345" } }) {
      arn
      # Other fields and connections here...
    }
  }
}


Kitchen Sink

Putting it all together; get all data for all IAM Users 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 IAM Users but if you want to it's easy to go from say, an IAM User -> IAM Group -> All IAM Users for that Group etc:

GraphQL
query {
  queryawsIamUser {
    id
    arn
    accountId
    path
    name
    creationTime
    passwordLastUsed
    accessKeyData {
      accessKeyId
    }
    groups
    tags {
      id
      key
      value
    }
    iamGroups {
      id
      arn
      accountId
      path
      name
      inlinePolicies
      iamAttachedPolicies {
        arn
        # Other fields and connections here...
      }
      iamUsers {
        arn
        # Other fields and connections here...
      }
    }
  }
}


References

Dgraph documentation on querying

AWS IAM User documentation

Updated 03 Mar 2023
Did this page help you?
PREVIOUS
IAM Access Analyzer
NEXT
IAM Instance Profile
Docs powered by Archbee
TABLE OF CONTENTS
Overview
Filtering
Advanced Filtering
Ordering
Aggregation
Examples
Kitchen Sink
References
Docs powered by Archbee