You cannot rotate, scope or retire a machine identity you do not know exists, and most organisations hold their non-human identities in a dozen systems that never talk to each other. Service accounts live in Active Directory, roles and access keys in each cloud account, service principals in Entra ID, tokens in SaaS admin consoles, keys in CI/CD variables and secrets in code. This guide gives a practical discovery plan: what counts as an NHI for discovery purposes, the specific APIs, reports and commands that enumerate them on each major platform, how to find the credentials that no platform lists, and how to run discovery as a repeatable process rather than a one-off spreadsheet. It is for identity, cloud security and platform teams starting or rebuilding an NHI inventory.
Key takeaways
- Discover identities and credentials separately. An identity (a role, service principal or service account) and its credentials (keys, secrets, certificates, tokens) have different owners, lifetimes and risks, and many platforms list one without the other.
- Use the platform's own usage data. AWS credential reports and last accessed data, Entra service principal sign-in activity, Google Cloud service account insights and Kubernetes legacy token labels tell you not just what exists but whether it is used.
- Some NHIs only appear in code and logs. API keys for SaaS providers, webhook secrets and tokens pasted into pipelines are found by secret scanning and by reading authentication logs, not by asking an identity system.
- Discovery is continuous or it is wrong. New roles, apps and keys appear daily; schedule each source, record when it was last collected, and treat a source that stops reporting as an incident.
- Every finding needs an owner field, even if empty. The output of discovery is a work queue for ownership and reconciliation, not a finished inventory.
What to discover: identities, credentials and trust
A useful discovery programme collects three linked object types. Missing any one of them leaves blind spots that attackers use.
| Object | Examples | Why it matters |
|---|---|---|
| Identity | AWS IAM users and roles, Entra applications, service principals and managed identities, Google Cloud service accounts, Kubernetes ServiceAccounts, AD service accounts and gMSAs, SaaS integration users, GitHub Apps, AI agents | Holds the permissions; the unit you assign an owner to |
| Credential | Access keys, client secrets, certificates, service account keys, personal access tokens, API keys, SSH keys, Kerberos keytabs, OAuth refresh tokens | What leaks; has its own creation date, expiry and last-used date |
| Trust relationship | Role trust policies, federated credentials (OIDC), workload identity pools, OAuth consents, cross-account roles, impersonation rights | Lets an identity be used without any stored credential, so it is easy to miss |
Decide early whether personal tokens created by humans (GitHub personal access tokens, SaaS API tokens) count. They should: they are used by scripts and integrations, outlive their purpose and appear in breach after breach. The Non-Human Identity (NHI) Guide covers the full taxonomy.
Discovery sources by environment
Start with the authoritative API of each platform. The table lists the object to enumerate, a concrete way to do it, and the usage signal you can collect at the same time.
| Environment | Enumerate | How | Usage signal |
|---|---|---|---|
| AWS | IAM users, access keys, roles | aws iam generate-credential-report then get-credential-report; ListRoles, ListAccessKeys | access_key_1_last_used_date, last accessed data, IAM Access Analyzer unused access findings |
| Microsoft Entra ID | Applications, service principals, managed identities, their secrets and certificates | Microsoft Graph /applications and /servicePrincipals (credentials under passwordCredentials and keyCredentials) | reports/servicePrincipalSignInActivities and reports/appCredentialSignInActivities (beta) |
| Google Cloud | Service accounts and user-managed keys | gcloud iam service-accounts list, gcloud iam service-accounts keys list, Cloud Asset Inventory across the organisation | Service account insights google.iam.serviceAccount.Insight (no authentication in 90 days) |
| Kubernetes | ServiceAccounts, legacy token Secrets, RBAC bindings | kubectl get serviceaccounts -A; Secrets of type kubernetes.io/service-account-token | kubernetes.io/legacy-token-last-used label on legacy token Secrets |
| Active Directory | Service accounts, gMSAs and dMSAs, accounts with SPNs | Get-ADServiceAccount; LDAP query for user objects with servicePrincipalName set | lastLogonTimestamp (lags real logons), DC security events |
| GitHub | GitHub Apps, OAuth apps, fine-grained PATs, deploy keys | Organisation settings, Personal access tokens, Active tokens; REST endpoints for org fine-grained PATs (callable only by GitHub Apps) | Audit log; classic PATs cannot be listed by owners, only restricted |
| SaaS (Salesforce, Okta, Slack, others) | Integration users, connected apps, API tokens, OAuth grants | Each admin API or console; SSPM or SaaS management tooling | Platform login history and token last-used fields where offered |
| CI/CD | Pipeline secrets, service connections, runner identities, OIDC trust | Platform APIs for repository, organisation and environment secrets; cloud trust policies naming CI issuers | Pipeline run logs; cloud logs of the federated role |
| Secrets managers | Stored secrets, their consumers and rotation status | Vault, AWS Secrets Manager, Azure Key Vault, Google Secret Manager listings | Secret access logs |
Two platform caveats matter for coverage. The AWS credential report includes only the first two access keys per user and excludes service-specific credentials, so use ListAccessKeys and ListServiceSpecificCredentials for completeness. GitHub organisation owners can view and revoke fine-grained PATs with access to organisation resources, but cannot view classic PATs in that interface, so the control for classic tokens is to restrict them. For the pipeline layer, see the CI/CD Pipeline Identity Security Guide.
Finding what no platform lists
API enumeration finds identities a platform manages. It does not find a third-party API key in a configuration file, a database password in a pipeline variable or a token embedded in a container image. Use four further methods:
| Method | Finds | Strength | Limitation |
|---|---|---|---|
| Platform API enumeration | Managed identities and their registered credentials | Authoritative, includes metadata | Blind to unmanaged secrets |
| Secret scanning (repositories, images, wikis, tickets) | Hard-coded keys and tokens for any provider | Finds credentials no system lists | Needs validity checks and owner tracing; history matters |
| Log-derived discovery | Identities that authenticate, including ones missing from the CMDB | Shows real use and source | Misses idle identities; depends on log retention |
| Configuration and IaC analysis | Identities defined in Terraform, Helm, CloudFormation and pipeline files | Links identities to repositories and teams | Drift between code and live state |
| Owner interviews and attestation | Purpose, criticality, external integrations | Only source of business context | Slow; inaccurate without data in front of the owner |
Log-derived discovery is the bridge. Authentication logs show the identity name, the credential identifier and the source address: an access key ID in CloudTrail, an appId and key ID in Entra sign-in logs, a service account key ID in Google Cloud audit logs. An identifier that appears in logs but not in your inventory is a discovery finding in its own right. See the Git Secret Scanning Guide and the Secrets in Container Images Guide for the scanning side.
Discovering trust that has no stored credential
Workload identity federation removes secrets but adds trust relationships that are easy to overlook, because nothing shows up in a key list. Collect them explicitly:
- AWS: IAM OIDC identity providers (
aws iam list-open-id-connect-providers) and every role trust policy that names one, plus trust policies that allow other accounts or broad principals. Record the conditions onsubandaud; a trust policy that accepts any repository from a CI issuer is a finding. - Microsoft Entra ID: federated identity credentials on applications and user-assigned managed identities, with issuer and subject, alongside the secrets and certificates already collected.
- Google Cloud: workload identity pools and providers, and IAM bindings that grant
roles/iam.workloadIdentityUserorroles/iam.serviceAccountTokenCreator, which let one principal act as a service account. - SaaS and OAuth: consented OAuth applications and their scopes, which act with delegated or application permissions without any credential your teams hold.
Treat each trust relationship as a credential with an owner, a scope and a review date. When you later retire an identity, the trust relationship must go with it, or a pipeline in another organisation may still be able to assume it.
What to record for each finding
Collect enough to act. CIS Controls v8.1 Safeguard 5.5 (Establish and Maintain an Inventory of Service Accounts) names department owner, review date and purpose as the minimum, with review at least quarterly. Add the technical fields that let you rotate and retire:
- Identity: platform, tenant or account, unique identifier (ARN, object ID, email, SID), display name, type, creation date, creator.
- Credentials: each credential's identifier (key ID, thumbprint, token name, never the value), type, creation date, expiry, last used date.
- Access: roles and permissions, privileged flag, trust relationships, resources reached.
- Context: owning team, technical contact, purpose, application or service, environment (production, test), data classification.
- Provenance: which discovery source reported it, and when each source last saw it.
Use the Service Account Inventory Template for column definitions and the Machine Identity Naming and Tagging Standard Template so new identities arrive with owner tags already set.
A phased discovery plan
- Weeks 1 to 2, scope and access. List every cloud account, subscription, project, tenant, cluster, domain, source control organisation, CI platform and top SaaS application. Create read-only collection identities for each (for example the AWS IAM
Get*andList*actions plusiam:GenerateCredentialReport, Entra Reports Reader for sign-in activity). These collectors are NHIs too: inventory them first. - Weeks 2 to 4, cloud and directory pass. Pull AWS, Entra, Google Cloud and Active Directory, including credentials and usage signals. These usually hold the largest and most privileged population.
- Weeks 4 to 6, code and pipeline pass. Run historical secret scanning across repositories, container registries and CI logs; enumerate pipeline secrets and OIDC trust relationships.
- Weeks 6 to 8, SaaS and Kubernetes pass. Enumerate connected apps, integration users and API tokens in the top SaaS platforms by data sensitivity, then cluster ServiceAccounts and legacy tokens.
- Weeks 8 to 10, reconcile and assign. Join the sources, remove duplicates and open ownership tasks. See the NHI Inventory Reconciliation guide.
- From then on, schedule. Daily for cloud and identity provider sources, weekly for SaaS, continuous for secret scanning, with alerts when a collector fails.
Discovery is read-only, so there is little to roll back. The test is coverage: before declaring a source complete, compare its count against the platform console and against identifiers seen in that platform's authentication logs over the last 30 days.
Choosing an approach: small and large estates
- Small organisations (one cloud, one IdP, a few SaaS apps): scripts against the native reports above, written to a shared table, are enough. Spend the effort on secret scanning and on GitHub and SaaS tokens, which usually outnumber cloud identities.
- Large or multi-cloud estates: use organisation-level collection (AWS Organizations with Access Analyzer at organisation scope, Google Cloud Asset Inventory at organisation level, Entra across all tenants) and a dedicated NHI or identity security platform to normalise sources. See the NHI Security Platform Buyer's Guide.
- Build or buy: building is reasonable for the cloud layer, where APIs are documented and stable. Buying pays off when SaaS coverage, secret validity checking and owner workflows are needed across many platforms.
- Agents and AI workloads: agent identities often run on service principals, API keys or OAuth grants created by individual teams. Include them from the start; the Shadow AI Discovery Guide covers the unsanctioned side.
Measuring discovery
Log and alert on the collectors themselves: last successful run per source, record counts per run, and sudden drops. Then track:
- Source coverage: share of known accounts, tenants, clusters and SaaS apps with an active collector.
- Log-to-inventory gap: number of credential identifiers seen authenticating in logs that are not in the inventory (target: falling to zero).
- Ownership rate: share of discovered identities with a named owning team.
- Freshness: share of records seen by at least one source in the last seven days.
- Unmanaged secrets: live secrets found by scanning that have no matching managed credential.
- Time to inventory: median hours from an identity's creation to its appearance in the inventory.
Framework mapping
| Framework | Reference | Relevance |
|---|---|---|
| NIST CSF 2.0 | ID.AM-02, PR.AA-01 | Inventories of software, services and systems; identities and credentials for services managed |
| NIST SP 800-53 Rev 5 | CM-8, AC-2, IA-5, PM-5 | Component inventory, account management, authenticator management, system inventory |
| CIS Controls v8.1 | Safeguards 5.1 and 5.5 | Inventory of accounts; inventory of service accounts with owner, purpose and review date |
| OWASP Non-Human Identities Top 10 2025 | NHI1 Improper Offboarding, NHI2 Secret Leakage, NHI7 Long-Lived Secrets | Risks that cannot be addressed without discovery |
| MITRE ATT&CK | T1078.004 Cloud Accounts, T1552.001 Credentials In Files | Attacker use of unknown cloud identities and unmanaged secrets |
Common failure patterns
- Discovering only one cloud. Teams inventory their primary platform and miss test tenants and acquired environments. The Microsoft Midnight Blizzard breach began with a legacy test tenant and a test OAuth application with elevated access to the corporate environment.
- Listing identities but not credentials. A role inventory says nothing about the three access keys or two client secrets attached to an identity, which are what leak.
- Ignoring source control applications. GitHub Apps and PATs are created by developers outside identity teams. The leaked GitHub App private keys research found 474 keys still authenticating, mostly from small, internal or abandoned Apps nobody tracked.
- One-off spreadsheets. An inventory built once for an audit is stale within weeks and gives false assurance.
- Collectors with excess rights. A discovery account with write access to every tenant becomes the most valuable NHI in the estate. Keep collectors read-only and monitored.
- Storing secret values. Copying discovered secret values into the inventory creates a new leak; record identifiers and fingerprints only.
Lessons from incidents
The recurring lesson across NHI breaches is that the credential used was one nobody was looking at. In the Klue OAuth breach, a GitHub personal access token issued in 2022 for an abandoned pilot was still active and could change code in the integration service. A discovery process that included source control tokens, with a creation date and purpose for each, would have put that token in front of an owner years earlier.
Practitioner checklist
- List every platform boundary (accounts, tenants, projects, clusters, domains, organisations, SaaS apps) before collecting anything.
- Create read-only collectors per platform and inventory them as NHIs.
- Collect identities, credentials and trust relationships as separate linked records.
- Capture native usage signals (credential report, sign-in activity, service account insights, legacy token labels) at collection time.
- Run historical secret scanning across code, images and CI logs and record identifiers, not values.
- Compare authentication log identifiers with the inventory weekly and treat gaps as findings.
- Schedule each source, record its last successful run and alert on failures.
- Open an ownership task for every identity without a named owning team.
- Restrict classic GitHub PATs and other credentials that cannot be enumerated.
Standards and references
- NIST: Cybersecurity Framework 2.0
- OWASP: Non-Human Identities Top 10 2025
- AWS: Getting credential reports for your AWS account
- Microsoft Learn: Usage and insights in Microsoft Entra
- Google Cloud: Service account insights
- Kubernetes: Managing service accounts
- GitHub Docs: Reviewing and revoking personal access tokens in your organization
- CIS: Control 5 Account Management
Related NHI Mgmt Group resources: Non-Human Identity (NHI) Guide · NHI Inventory Reconciliation · NHI Dormancy Detection · NHI Ownership Guide · CI/CD Pipeline Identity Security Guide