NHI discovery is building a complete list of the non-human identities in your estate (service accounts, cloud roles, managed identities, Kubernetes service accounts, CI/CD credentials and third-party OAuth grants) by querying each system that issues them, then reconciling that list against authentication logs. This page gives the commands per platform.
In short
- There is no single query. Non-human identities are minted in at least six systems that do not reconcile with each other.
- An identity provider export is a fraction of the population: it is authoritative for humans and close to blind for machines.
- Enumeration is the easy half. Reconciling against observed authentication events is what finds identities no enumeration returned.
- Record the query you ran, not just the result. An inventory without a stated method is not evidence of completeness.
Where identities actually live
Before running anything, decide what you are counting. An inventory whose scope is undefined produces a number nobody can defend. See defining your denominator.
| Source | In the IdP? | Who creates them |
|---|---|---|
| IdP service principals, app registrations | Yes | Admins, app registration flow |
| Cloud IAM (AWS, Azure, GCP) | No | Console, CLI, Terraform, anyone with account access |
| Kubernetes service accounts | No | Manifest apply; one created by default in every namespace |
| Databases and middleware | No | DBAs, migration scripts |
| CI/CD credentials, deploy keys | No | Repository and pipeline settings |
| Third-party OAuth grants | Partly | End users consenting, often without admin involvement |
AWS
Three populations: IAM users (which hold long-lived keys), IAM roles (which are assumed), and the trust relationships that decide who may assume them.
# IAM users with an access key, and when each key was last used.
# Users with keys are the long-lived-secret population (OWASP NHI7).
for u in $(aws iam list-users --query 'Users[].UserName' --output text); do
for k in $(aws iam list-access-keys --user-name "$u" \
--query 'AccessKeyMetadata[].AccessKeyId' --output text); do
last=$(aws iam get-access-key-last-used --access-key-id "$k" \
--query 'AccessKeyLastUsed.LastUsedDate' --output text)
created=$(aws iam list-access-keys --user-name "$u" \
--query "AccessKeyMetadata[?AccessKeyId=='$k'].CreateDate" --output text)
printf '%s\t%s\tcreated=%s\tlast_used=%s\n' "$u" "$k" "$created" "$last"
done
done
# Roles, excluding AWS service-linked roles, with last-used data.
# RoleLastUsed is the dormancy signal for OWASP NHI1.
aws iam list-roles \
--query "Roles[?!starts_with(Path, '/aws-service-role/')].[RoleName,CreateDate,Arn]" \
--output text
aws iam get-role --role-name ROLE_NAME \
--query '[Role.RoleName, Role.RoleLastUsed.LastUsedDate, Role.RoleLastUsed.Region]' \
--output text
# The credential report: every IAM user, key age and last use, in one CSV.
# Covers IAM users only (not roles); a useful first artefact.
# Generation is asynchronous: poll until the report is COMPLETE.
until [ "$(aws iam generate-credential-report --query State --output text)" = COMPLETE ]; do
sleep 5
done
aws iam get-credential-report --query Content --output text \
| base64 --decode > credential-report.csv
What this misses
Everything outside the account you are authenticated to. Run per account across every account in the organisation (aws organizations list-accounts gives you the list); forgotten accounts are where forgotten identities live. It also misses identities in services with their own principals, and it tells you nothing about effective permissions, only attached policies. Resource-based policies can grant access to principals that no identity-side query will show.
Azure / Entra ID
Two populations to keep apart: application service principals, which are backed by app registrations and can hold secrets or certificates, and managed identities, which are a special type of service principal whose credential Azure manages.
# Service principals excluding Microsoft first-party apps. Microsoft documents
# two owning tenants: f8cdef31-... (Microsoft Services) and 72f988bf-... (Microsoft).
az ad sp list --all \
--query "[?appOwnerOrganizationId != 'f8cdef31-a31e-4b4a-93e4-5f571e91255a' && appOwnerOrganizationId != '72f988bf-86f1-41af-91ab-2d7cd011db47'].[displayName,appId,servicePrincipalType]" \
-o tsv
# Application credentials and their expiry, the rotation population.
# Without --cert only client secrets are listed; run both.
az ad app credential list --id APP_ID \
--query '[].[keyId,startDateTime,endDateTime]' -o tsv
az ad app credential list --id APP_ID --cert \
--query '[].[keyId,startDateTime,endDateTime]' -o tsv
# Managed identities, which hold no credential you can rotate, by design.
az identity list --query '[].[name,resourceGroup,principalId]' -o tsv
Managed identities are the goal state, not a gap
A managed identity has no long-lived secret to store, rotate or inventory. Tokens are still issued to it, and Microsoft's managed identity best practice notes that anyone who can install or execute code on the resource has access to all the identities assigned to it. It still needs an owner, a permission review and a decommissioning path, so it belongs in the inventory, but do not treat its absence from your secrets store as a finding. Distinguish “no credential” from “credential not managed” in your reporting, or you will generate remediation tickets against your own best-configured workloads.
Google Cloud
# Service accounts per project.
for p in $(gcloud projects list --format='value(projectId)'); do
gcloud iam service-accounts list --project="$p" \
--format="table[no-heading](email,disabled,displayName)" \
| sed "s|^|$p\t|"
done
# User-managed keys, the long-lived secret population.
# Google-managed keys are rotated by Google and are not the concern here.
gcloud iam service-accounts keys list \
--iam-account=SA_EMAIL \
--managed-by=user \
--format='table(name,validAfterTime,validBeforeTime)'
The --managed-by=user filter matters. Without it the output can include Google-managed keys, which are rotated automatically and are not a finding. Reporting them as unrotated secrets is a false positive that undermines trust in the inventory.
Kubernetes
# Every service account in every namespace.
kubectl get serviceaccounts --all-namespaces \
-o custom-columns='NS:.metadata.namespace,NAME:.metadata.name,SECRETS:.secrets[*].name'
# Which service account each running pod is assigned.
# Accounts in the list above but not here are dormancy candidates: tokens can
# also be used from outside the cluster, so confirm in audit logs first.
kubectl get pods --all-namespaces \
-o custom-columns='NS:.metadata.namespace,POD:.metadata.name,SA:.spec.serviceAccountName' \
| sort -u
# Legacy long-lived token secrets. Modern clusters use projected,
# time-bound tokens; a service-account-token Secret is a standing credential.
kubectl get secrets --all-namespaces \
--field-selector type=kubernetes.io/service-account-token
# What each service account can actually do, bindings, not just existence.
kubectl get clusterrolebindings,rolebindings --all-namespaces -o json \
| jq -r '.items[]
| . as $b
| (.subjects // [])[]
| select(.kind=="ServiceAccount")
| [$b.kind, $b.metadata.name, $b.roleRef.name,
(.namespace // "-"), .name] | @tsv'
The default service account
Kubernetes creates a default service account in every namespace, and pods that do not specify one get it. Every workload that does not set its own account shares it, which is OWASP NHI9 NHI Reuse by default rather than by decision. Set automountServiceAccountToken: false where a workload does not need API access, and give workloads that do their own account.
GitHub
# Repository-level secrets, names only; values are not retrievable.
# The names are enough to know what credential types exist and where.
gh api --paginate /repos/ORG/REPO/actions/secrets --jq '.secrets[].name'
gh api --paginate /orgs/ORG/actions/secrets --jq '.secrets[].name'
# Deploy keys, which are SSH credentials that rarely appear in any inventory.
gh api --paginate /repos/ORG/REPO/keys --jq '.[] | [.title, .read_only, .created_at] | @tsv'
# Installed GitHub Apps, third-party NHIs holding grants into your org.
gh api --paginate /orgs/ORG/installations --jq '.installations[] | [.app_slug, .target_type] | @tsv'
Reconciliation: the part that matters
Enumeration finds identities that exist in a system you thought to query. It cannot find identities in a system you forgot. Reconciliation can.
The method: take authentication events from your logs over a period, extract the distinct principals, and subtract the inventory. Anything left is authenticating against your environment and is not in your list.
# AWS: distinct principals that authenticated, from CloudTrail.
# Compare the output against your inventory; the difference is your gap.
aws cloudtrail lookup-events \
--start-time "$(date -u -d '30 days ago' +%Y-%m-%dT%H:%M:%SZ)" \
--max-items 1000 \
--query 'Events[].CloudTrailEvent' --output json \
| jq -r '.[] | fromjson | .userIdentity
| [.type, (.sessionContext.sessionIssuer.arn // .arn // .invokedBy // .userName // "unknown")] | @tsv' \
| sort -u
Limits of this example. With --max-items 1000 the command returns at most 1,000 events, and the AWS CLI reference says the most recent event is listed first. In a busy account those 1,000 events may cover only a short part of the 30 days, so the output is a sample, not every principal that authenticated. To cover the whole window, run it again with the NextToken value it prints, passed as --starting-token. For any material estate, run this against CloudTrail in Athena or your SIEM rather than via lookup-events, which is limited to two requests per second per account per Region, looks up events in one Region, and covers only management events and CloudTrail Insights events from the last 90 days, not data events (AWS CLI reference). The principle holds either way: the log knows about identities your inventory does not.
What to record, and why each field earns its place
| Field | Why it is needed |
|---|---|
| Stable identifier | ARN, object ID, or namespace/name. Display names change; identifiers do not. |
| Source system + query | This is the completeness evidence. Without it your inventory is an assertion. |
| Credential type and age | Separates “no credential” (federated, managed identity) from “standing credential”. Feeds OWASP NHI7. |
| Effective permissions | Not attached policies. Privilege concentration is the metric; Veza reported in December 2025, from its own proprietary data, that 0.01% of NHIs control 80% of all cloud permissions (Veza press release), which is why a count of identities without a permission dimension misleads. |
| Last authentication | The dormancy signal, and the only defensible basis for proposing removal. |
| Accountable owner | Often blank, and the field every access review depends on. See ownership and custodianship. |
| Consuming workload | Determines whether rotation is safe and whether removal breaks something. |
Run it on a schedule from day one
A one-off inventory goes stale quickly and cannot evidence a control that operated over a period. Scheduling the same queries and retaining the run output is what converts discovery from a project into the SOC 2 Type II and ISO/IEC 27001 A 5.16 evidence described in SOC 2 evidence for NHI.
Frequently asked questions
How do I find all the service accounts in my organisation?
There is no single query. Enumerate each source separately (identity provider, each cloud tenant, each Kubernetes cluster, databases, CI systems, third-party grants), record which sources you queried and how, then reconcile the union against observed authentication events.
Why does an identity provider export miss most non-human identities?
Because most are not created there. Cloud IAM roles, Kubernetes service accounts, database accounts and CI credentials are created by engineers using consoles, CLIs, Terraform and manifests, and never appear in the directory.
How do I prove my inventory is complete?
Completeness is evidenced to increasing strength rather than proven: an attestation, then an enumerated source list with queries, then scheduled automated discovery with retained run evidence, then reconciliation against authentication events. Only the last finds what your discovery missed.
What should I record for each identity?
A stable identifier, the source and query, credential type and age, effective permissions, last authentication, a named accountable owner, and the consuming workload.
Sources
- OWASP Non-Human Identities Top 10 (2025), owasp.org
- OWASP NHI Top 10 (2025), full risk list, owasp.org
- NIST SP 800-53 Rev. 5, Security and Privacy Controls for Information Systems and Organizations (AC-2, AC-6, IA-5), csrc.nist.gov
- ISO/IEC 27001:2022 Annex A (controls 5.15-5.18, 8.2, 8.5, 8.15, 8.16) paywalled standard; cited by clause, not linked
- Entro Labs, NHI & Secrets Risk Report H1 2025 (144:1, up from 92:1), Entro release via GlobeNewswire, 22 July 2025
- SPIFFE, quickstart for Kubernetes, spiffe.io
- Veza, 2026 State of Identity & Access Report (11 Dec 2025; proprietary data across millions of identities and billions of permissions), veza.com verified 6 Aug 2026
Where a primary URL is not shown, we have not confirmed the figure against the publisher’s own document and say so on the page rather than linking a secondary source that paraphrases it. Paywalled standards (ISO/IEC, AICPA) are cited by clause and not linked. Corrections welcome: report an error.
Disclosure. This reference is free. No vendor pays for coverage, placement, or favourable treatment. HumanAudit Inc., which publishes this site, sells ISO/IEC 42001 documentation and plans NHI governance documentation packs, including an RFP kit that does not name, rank or recommend any vendor; it builds and sells no NHI scanner and no NHI discovery, monitoring or security tool (see About). Links to its offers appear in the header, in the site footer and in one marked box on guide pages; company profiles carry none. See our methodology, sourcing standards and corrections policy.
From the publisher
HumanAudit, which publishes this site, is preparing the NHI Governance pack: an NHI policy, ownership register, lifecycle procedures and one control set mapped, as our interpretation, to PCI DSS v4.0.1, ISO/IEC 27001:2022, NIS2 and DORA. Planned for March 2027; not yet on sale, and no price has been published.