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 

AD Service Principal

16min

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 Azure AD Service Principal

GraphQL
|
query {
  queryazureADServicePrincipal{
    id
    deletedDateTime
    accountEnabled
    alternativeNames
    appDescription
    appDisplayName
    appId
    applicationTemplateId
    appOwnerOrganizationId
    appRoleAssignmentRequired
    appRoles{
      id
      # Other fields and connections here...
    }
    description
    disabledByMicrosoftStatus
    displayName
    homepage
    loginUrl
    logoutUrl
    notes
    notificationEmailAddresses
    preferredSingleSignOnMode
    replyUrls
    servicePrincipalNames
    servicePrincipalType
    signInAudience
    tokenEncryptionKeyId
    appRoleAssignedTo{
      id
      # Other fields and connections here...
    }
    appRoleAssignments{
      id
      # Other fields and connections here...
    }
    endpoints{
      id
      deletedDateTime
      capability
      providerId
      providerName
      providerResourceId
      uri
    }
    tags{
      id
      key
      value
    }
    appOwnerOf{
      id
      # Other fields and connections here...
    }
    instanceOf{
      id
      # Other fields and connections here...
    }
    authRoleAssignments{
      id
      # Other fields and connections here...
    }
  }
}


Filtering

Get data for a single Azure AD Service Principal key that you know the ID for:

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


Get data for all of the AD Service Principals that instance a certain Azure AD Application:

GraphQL
|
query {
  queryazureADServicePrincipal(filter: { appId: { eq: "12345" } }) {
    id
    # Other fields and connections here...
  }
}

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

# id
# deletedDateTime
# accountEnabled
# alternativeNames
# appDescription
# appDisplayName
# applicationTemplateId
# appOwnerOrganizationId
# appRoleAssignmentRequired
# description
# disabledByMicrosoftStatus
# displayName
# homepage
# loginUrl
# logoutUrl
# notes
# notificationEmailAddresses
# preferredSingleSignOnMode
# replyUrls
# servicePrincipalNames
# servicePrincipalType
# signInAudience
# tokenEncryptionKeyId

# 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 AD Service Principals that are NOT in a certain Azure subscription:

GraphQL
|
query {
  queryazureADServicePrincipal(filter: { not: { region: { eq: "eastus" } } }) {
    id
    # Other fields and connections here...
  }
}


Advanced Filtering

Get data for all of the AD Service Principals that are connected to a authRoleAssignment:

GraphQL
|
query {
  queryazureADServicePrincipal(filter: { has: authRoleAssignments }) {
    id
    # Other fields and connections here...
  }
}

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

# tags
# appOwnerOf
# instanceOf
# authRoleAssignments


Ordering

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

GraphQL
|
query {
  queryazureADServicePrincipal(order: { desc: displayName }) {
    id
    # Other fields and connections here...
  }
}

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

# id
# deletedDateTime
# accountEnabled
# alternativeNames
# appDescription
# appDisplayName
# appId
# applicationTemplateId
# appOwnerOrganizationId
# appRoleAssignmentRequired
# description
# disabledByMicrosoftStatus
# homepage
# loginUrl
# logoutUrl
# notes
# notificationEmailAddresses
# preferredSingleSignOnMode
# replyUrls
# servicePrincipalNames
# servicePrincipalType
# signInAudience
# tokenEncryptionKeyId


Only select and return the first two AD Service Principals that are found:

GraphQL
|
query {
  queryazureADServicePrincipal(first: 2, order: { desc: displayName }) {
    id
    # Other fields and connections here...
  }
}


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

GraphQL
|
query {
  queryazureADServicePrincipal(first: 2, order: { desc: displayName }, offset: 1) {
    id
    # Other fields and connections here...
  }
}


Aggregation

Count the number of AD Service Principals across all scanned Azure subscriptions:

GraphQL
|
query {
  aggregateazureADServicePrincipal {
    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 AD Service Principals:

# idMin
# idMax
# deletedDateTimeMin
# deletedDateTimeMax
# appDescriptionMin
# appDescriptionMax
# appDisplayNameMin
# appDisplayNameMax
# appIdMin
# appIdMax
# applicationTemplateIdMin
# applicationTemplateIdMax
# appOwnerOrganizationIdMin
# appOwnerOrganizationIdMax
# descriptionMin
# descriptionMax
# disabledByMicrosoftStatusMin
# disabledByMicrosoftStatusMax
# displayNameMin
# displayNameMax
# homepageMin
# homepageMax
# loginUrlMin
# loginUrlMax
# logoutUrlMin
# logoutUrlMax
# notesMin
# notesMax
# preferredSingleSignOnModeMin
# preferredSingleSignOnModeMax
# servicePrincipalTypeMin
# servicePrincipalTypeMax
# signInAudienceMin
# signInAudienceMax
# tokenEncryptionKeyIdMin
# tokenEncryptionKeyIdMax


Count the number of AD Service Principals that instance an AD Application. Note that you can apply all of the same filters that are listed above to aggregate queries:

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


Examples

Find all of the AD Service Principals that are in the eastus region across all your accounts:

GraphQL
|
query {
  queryazureADServicePrincipal(filter: { region: { eq: "eastus" } }) {
    id
    # Other fields and connections here...
  }
}


Find all of the AD Service Principals that have a tag of Environment:Production for a single region:

GraphQL
|
query {
  queryazureTag(
    filter: { key: { eq: "Environment" }, value: { eq: "Production" } }
  ) {
    adServicePrincipals(filter: { region: { eq: "eastus" } }) {
      id
      # 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 {
  queryazureVirtualMachine(filter: { region: { eq: "eastus" } }) {
    id
    # Other fields and connections here...
  }
  queryazureTag(
    filter: { key: { eq: "Environment" }, value: { eq: "Production" } }
  ) {
    adServicePrincipals(filter: { region: { eq: "eastus" } }) {
      id
      # Other fields and connections here...
    }
  }
}


Kitchen Sink

Putting it all together; get all data for allAD Service Principals across all regions for all scanned Azure subscriptions 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, appOwnerOf -> authRoleAssignments -> authRoleDefinitin ...etc:

GraphQL
|
query {
  queryazureADServicePrincipal{
    id
    deletedDateTime
    accountEnabled
    alternativeNames
    appDescription
    appDisplayName
    appId
    applicationTemplateId
    appOwnerOrganizationId
    appRoleAssignmentRequired
    appRoles{
      id
      # Other fields and connections here...
    }
    description
    disabledByMicrosoftStatus
    displayName
    homepage
    loginUrl
    logoutUrl
    notes
    notificationEmailAddresses
    preferredSingleSignOnMode
    replyUrls
    servicePrincipalNames
    servicePrincipalType
    signInAudience
    tokenEncryptionKeyId
    appRoleAssignedTo{
      id
      # Other fields and connections here...
    }
    appRoleAssignments{
      id
      # Other fields and connections here...
    }
    endpoints{
      id
      deletedDateTime
      capability
      providerId
      providerName
      providerResourceId
      uri
    }
    tags{
      id
      key
      value
    }
    appOwnerOf{
      id
      region
      appId
      applicationTemplateId
      apiAcceptMappedClaims
      apiKnownClientApplications
      apiPreAuthorizedApplications
      appRoles{
        id
        allowedMemberTypes
        description
        displayName
        isEnabled
        origin
        value
      }
      createdDateTime
      description
      disabledByMicrosoftStatus
      displayName
      groupMembershipClaims
      identifierUris
      isDeviceOnlyAuthSupported
      isFallbackPublicClient
      notes
      oauth2RequirePostResponse
      publicClientRedirectUris
      publisherDomain
      signInAudience
      spaApplicationRedirectUris
      webAppHomePageUrl
      webAppRedirectUris
      tags{
        id
        key
        value
      }
      authRoleAssignments {
        id
        # Other fields and connections here...
      }
      instancedBy {
        id
        # Other fields and connections here...
      }
      ownerGroups {
        id
        # Other fields and connections here...
      }
      ownerServicePrincipals {
        id
        # Other fields and connections here...
      }
      ownerUsers {
        id
        # Other fields and connections here...
      }
    }
    instanceOf{
      id
      region
      appId
      applicationTemplateId
      apiAcceptMappedClaims
      apiKnownClientApplications
      apiPreAuthorizedApplications
      appRoles{
        id
        allowedMemberTypes
        description
        displayName
        isEnabled
        origin
        value
      }
      createdDateTime
      description
      disabledByMicrosoftStatus
      displayName
      groupMembershipClaims
      identifierUris
      isDeviceOnlyAuthSupported
      isFallbackPublicClient
      notes
      oauth2RequirePostResponse
      publicClientRedirectUris
      publisherDomain
      signInAudience
      spaApplicationRedirectUris
      webAppHomePageUrl
      webAppRedirectUris
      tags{
        id
        key
        value
      }
      authRoleAssignments {
        id
        # Other fields and connections here...
      }
      instancedBy {
        id
        # Other fields and connections here...
      }
      ownerGroups {
        id
        # Other fields and connections here...
      }
      ownerServicePrincipals {
        id
        # Other fields and connections here...
      }
      ownerUsers {
        id
        # Other fields and connections here...
      }
    }
    authRoleAssignments{
      id
      name
      type
      region
      subscriptionId
      scope
      roleDefinitionId
      principalId
      principalType
      canDelegate
      applications{
        id
        # Other fields and connections here...
      }
      groups{
        id
        # Other fields and connections here...
      }
      roleDefinition{
        id
        # Other fields and connections here...
      }
      servicePrincipals{
        id
        # Other fields and connections here...
      }
      users{
        id
        # Other fields and connections here...
      }
    }
  }
}


References

Dgraph documentation on querying

Azure AD Service Principal Documentation

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