Service accounts, API keys, OAuth apps and workload tokens now outnumber human users in most environments, yet most detection content still assumes the attacker is a person signing in. Machine identities cannot use MFA, rarely trigger impossible-travel rules, and often have permissions nobody has reviewed, so a stolen key can be used for weeks before anyone notices. The good news is that machines are predictable: the same workload calls the same APIs from the same places on the same schedule, which makes deviations easier to detect than for humans. This guide explains how to build detections for non-human identities (NHIs): which logs identify the identity and credential, how to baseline them, the detection rules that matter, and how to measure coverage. It is for detection engineers, SOC leads and NHI programme owners. The broader identity threat detection discipline is covered in the ITDR Guide; this page goes deeper on machine identities.
Key takeaways
- Attribute to the credential, not just the identity. Detection needs to know which key, token or certificate was used, because one service account can hold several and only one may be stolen.
- Machines are predictable, so baseline them. Source network, API set, user agent and time pattern change little for a healthy workload; a change is a strong signal.
- Change events are the highest-value rules. New credentials on an existing identity, new role grants and new consent are how attackers persist, and they are rare in normal operations.
- Inventory is a detection dependency. Without owner, purpose and expected environment for each NHI, analysts cannot tell anomaly from intent.
- Measure coverage per identity type, not rule count: the gap is usually a whole platform (a SaaS tool, a CI system) that sends no logs at all.
Why NHI detection is different
| Characteristic | Human identity | Non-human identity | Detection consequence |
|---|---|---|---|
| Authentication | Interactive, MFA, device signals | Secret, key, certificate or federated token; no MFA | Sign-in risk rules built on MFA and device state do not apply |
| Behaviour | Variable hours, locations, tasks | Repetitive API set, fixed sources, scheduled | Tight baselines with low false positive rates are achievable |
| Credentials per identity | Usually one password plus sessions | Often several keys or secrets, sometimes shared across systems | Rules must key on credential ID (access key ID, key name, token hash) |
| Ownership | The person | Often unclear or departed | Triage stalls without an owner field in the inventory |
| Lifecycle | Joiner, mover, leaver process | Created ad hoc, rarely retired | Dormant identities that become active are a key signal |
| Who should use it | Its owner | Only its workload | Human use of a machine credential (OWASP NHI10:2025 Human Use of NHI) is detectable |
Telemetry: logs that identify the machine and the credential
Start by confirming, platform by platform, that you can answer three questions from logs: which identity acted, which credential it used, and from where.
| Platform | Log source | Identity and credential fields | Notes |
|---|---|---|---|
| AWS | CloudTrail | userIdentity.type (IAMUser, AssumedRole, AWSService and others), userIdentity.accessKeyId, sessionContext.sessionIssuer.arn, sessionContext.attributes.creationDate, sessionContext.ec2RoleDelivery | For assumed roles, link later events to the AssumeRole event by matching responseElements.credentials.accessKeyId. ec2RoleDelivery shows whether instance credentials came from IMDSv1 (1.0) or IMDSv2 (2.0) |
| Microsoft Entra ID | Service principal sign-in logs; managed identity sign-in logs; audit logs | Application ID, service principal ID, credential used, IP address, resource | Managed identity sign-ins are aggregated by identity, status and resource in the portal; export raw logs through diagnostic settings for detection |
| Google Cloud | Cloud Audit Logs | authenticationInfo.principalEmail, authenticationInfo.serviceAccountKeyName, serviceAccountDelegationInfo for impersonation | Some services do not log the key name; GenerateAccessToken events need IAM Data Access audit logs enabled |
| GitHub | Organisation or enterprise audit log | hashed_token (SHA-256, Base64), programmatic_access_type, token_scopes | Git events are not returned by UI or API search and need an audit log export or stream |
| Kubernetes | API server audit log | user.username (system:serviceaccount:<ns>:<name>), sourceIPs, userAgent | Only generated when an audit policy is configured. See the Kubernetes Audit Log Detection Guide |
| Active Directory | Domain controller security log | Service account name, logon type, source host | Interactive logon (type 2 or 10) by a service account is a classic high-fidelity rule |
| Secrets managers | Vault or cloud secrets manager audit logs | Caller identity, secret path, operation | Reads by unexpected principals reveal credential harvesting |
| SaaS platforms | Admin and API audit logs | API key or integration user, OAuth client ID | Coverage varies widely; check retention and export before relying on it |
For the GitHub case, you can find every action a leaked token took by computing its SHA-256 hash and searching hashed_token, which turns a leak report into a scoped investigation. See the GitHub Personal Access Tokens Security Guide.
Baselining machine identity behaviour
A baseline is a per-identity profile of normal use, learned over a window long enough to cover the workload's cycle (at least one month for most workloads, a full quarter for batch and reporting jobs). Microsoft documents that its own suspicious sign-in detection for workload identities takes between 2 and 60 days to learn a baseline, which is a useful reference point.
- Source: IP ranges, ASNs, cloud regions, VPC endpoints, Kubernetes namespaces or hosts the identity normally acts from. For workloads in your cloud, sources outside your address space are the strongest signal.
- Action set: the distinct API operations the identity calls. A deployment role that suddenly calls
ListUsersorGetSecretValueis doing reconnaissance or harvesting. - Client: user agent and SDK version. A Java service whose key appears with a command-line tool user agent is being used by a person.
- Volume and timing: calls per hour and schedule. Bulk reads at unusual volume are exfiltration indicators.
- Credential set: which keys or certificates are active and used; a newly used credential is noteworthy.
- Peers: identities in the same role or application should behave alike; the outlier is interesting.
Decision: statistical or rule-based baselines? For small estates (hundreds of NHIs) explicit allow-lists per identity, maintained as code, are precise and auditable. For large estates (tens of thousands), learned baselines from UEBA, ITDR or NHI platforms scale better, but need the inventory context to explain alerts. Most teams combine them: explicit rules for the top 5% most privileged identities and learned baselines for the rest.
Worked example: a CI deployment role
Take an AWS role assumed by a CI pipeline through OIDC federation to deploy one application. Its baseline after a month might be: assumed only via AssumeRoleWithWebIdentity from the CI provider; sessions lasting under an hour; actions limited to the deployment service, the artefact bucket and a single parameter path; user agent the deployment tool's SDK; activity only when pipelines run. Rules then follow directly: any AssumeRole by a different caller, any session used from an address outside the CI provider's published ranges, any IAM or secrets API call, or any activity outside a pipeline run. Each is cheap to express and rarely noisy. The same pattern applies to an Entra service principal used by a reporting job or a Kubernetes service account used by an operator: write down what the workload does, then alert on everything else.
High-value detection rules
| Rule | Logic (summary) | Why it matters | ATT&CK |
|---|---|---|---|
| New credential added to an existing identity | Key, secret or certificate created on a service account or service principal, outside the rotation pipeline's identity | Classic persistence that survives password resets | T1098.001 Additional Cloud Credentials |
| Privilege grant to a machine identity | Role assignment, policy attachment or app role grant to an NHI outside change windows | Escalation and persistence; Midnight Blizzard granted itself a mail-wide application role | T1098.003 Additional Cloud Roles |
| Credential used from a new source | First use of a key or token from an IP, ASN or region not in its baseline | Most direct signal of theft | T1078.004 Cloud Accounts, T1550.001 Application Access Token |
| Dormant identity reactivated | No activity for [90] days, then any authentication | Stolen credentials for forgotten identities are a common foothold | T1078 |
| Human use of a machine credential | Interactive logon, console sign-in, or CLI user agent for an identity whose baseline is SDK only | Insider shortcut or attacker hands-on use | T1078 |
| Discovery burst | Identity calls enumeration APIs (users, roles, buckets, secrets) it has not used before | Attackers' first moves with a stolen key | T1087.004 Cloud Account, T1580 Cloud Infrastructure Discovery |
| Secret read by an unexpected principal | Secrets manager reads by an identity not mapped to that secret | Credential harvesting and lateral movement | T1555.006 Cloud Secrets Management Stores |
| Instance credentials used outside the instance | Instance or workload role session used from an address outside your cloud | Metadata credential theft | T1552.005 Cloud Instance Metadata API |
| New machine identity created by a machine identity | Service account or app registration created by an NHI outside provisioning automation | Attacker-made identities for persistence | T1136.003 Cloud Account |
| Bulk data access | Object reads or exports far above baseline volume | Exfiltration with a valid key | T1530 Data from Cloud Storage |
Augment your own rules with provider signals where available. Microsoft Entra ID Protection raises workload identity detections including Leaked Credentials, Suspicious Sign-ins, Anomalous service principal activity and Suspicious API Traffic; full detail and risk-based Conditional Access need the Workload Identities Premium licence, and managed identities are not currently in scope.
Building the pipeline: from inventory to rule
- Join the inventory to the logs. Load each NHI's owner, purpose, environment, expected sources and privilege tier into a lookup table in the SIEM. See the Service Account Inventory Template.
- Normalise identity fields across platforms into a common schema: identity ID, credential ID, identity type, source, action, result.
- Write the change-event rules first (new credential, new privilege, new identity), because they need no baseline and fire rarely.
- Add baseline rules for the most privileged identities, then expand by tier.
- Manage rules as code with tests and peer review, in a vendor-neutral format such as Sigma where your SIEM supports it. See the Detection as Code Guide.
- Test before enabling: run new rules in a monitoring-only mode for two to four weeks, measure alert volume and tune; replay known-bad activity (an authorised test key used from an external address) to confirm the rule fires.
- Roll back safely: keep each rule versioned so a noisy change can be reverted without losing the previous logic; never suppress an identity entirely, scope exclusions to a source or action.
- Add canaries for locations you cannot baseline. See the Honeytokens and Canary Credentials Guide.
Triage and response for NHI alerts
- Owner first: the alert should name the owner and purpose. If the activity matches a planned change, close with evidence; if there is no owner, escalate as higher severity.
- Scope by credential: list every action taken with the specific key or token since its first anomalous use, not only since the alert.
- Contain without breaking production blindly: disable the specific credential rather than the identity where possible; Microsoft's guidance for a compromised service principal is to inventory its credentials, add a new one (certificates preferred), remove the compromised ones and rotate any Key Vault secrets it could read.
- Look for persistence: new credentials, roles and identities created by the suspect identity.
- Rotate what it could reach, following the Leaked Credential Response Playbook.
Lessons from incidents
- In the Cloudflare Thanksgiving breach, a service token and three service accounts stolen in the Okta support breach were left unrotated because they were believed to be unused. Last-used data in the inventory and a dormant-identity reactivation rule address exactly this.
- In the Midnight Blizzard breach, a legacy test OAuth application was used to register further applications and grant the
full_access_as_approle. New app registrations, new consent and new application role assignments are the change events that would have surfaced it.
Measuring coverage and effectiveness
- Telemetry coverage: percentage of NHI types (cloud roles, service principals, SaaS keys, CI tokens, Kubernetes service accounts) whose authentication and actions reach the SIEM with a credential identifier.
- Inventory join rate: percentage of NHI alerts that arrive with owner and purpose populated.
- Baseline coverage: percentage of privileged NHIs with an active baseline or allow-list rule.
- Change-event coverage: credential creation, role grant and identity creation rules deployed for every platform in scope.
- Mean time to contain a confirmed NHI compromise, from alert to credential disabled.
- Precision: share of NHI alerts that are true positives or confirmed authorised changes needing a process fix.
Framework mapping
| Framework | Reference | Relevance |
|---|---|---|
| OWASP Non-Human Identities Top 10 2025 | NHI1 Improper Offboarding; NHI2 Secret Leakage; NHI5 Overprivileged NHI; NHI7 Long-Lived Secrets; NHI10 Human Use of NHI | Risks that dormant-identity, new-source, privilege and human-use rules detect |
| NIST CSF 2.0 | PR.AA-01; PR.PS-04; DE.CM-03; DE.CM-09; DE.AE-02; DE.AE-03 | Managed identities and credentials, log generation, monitoring, analysis and correlation |
| NIST SP 800-53 Rev. 5 | AC-2 Account Management; AC-2(12) Account Monitoring for Atypical Usage; AU-6 Audit Record Review, Analysis, and Reporting; SI-4 System Monitoring | Control basis for monitoring machine accounts |
| CIS Controls v8.1 | Control 5 Account Management; Control 8 Audit Log Management | Service account inventory and log collection |
| MITRE ATT&CK | T1078, T1078.004, T1098.001, T1098.003, T1136.003, T1550.001, T1552.005, T1555.006, T1087.004, T1580, T1530 | Behaviours the rule set covers |
Common failure patterns
- Baselining humans only: service principals and API keys have no behavioural model, so stolen keys look normal.
- Identity without credential: logs show the service account but not which key, so containment means disabling the whole workload.
- Missing platforms: CI systems and SaaS tools send no audit logs, and that is where tokens are stolen.
- Allow-listing whole identities because they are noisy, which removes the very identities attackers target.
- Treating "unused" as fact: skipping rotation for credentials assumed idle, as in the Cloudflare case.
- Retention shorter than dwell time: cloud and SaaS logs kept for days while key abuse runs for months.
Practitioner checklist
- Confirm each platform logs identity, credential identifier and source for machine activity, and export it to the SIEM.
- Join the NHI inventory (owner, purpose, environment, privilege tier) to identity logs.
- Deploy change-event rules: new credential, new privilege grant, new machine identity, new consent.
- Baseline the most privileged NHIs on source, action set, client and volume.
- Add rules for dormant reactivation, human use of machine credentials and instance credentials used outside the cloud.
- Enable provider workload identity risk signals where licensed and route them to the SOC.
- Manage NHI rules as code, tested in monitoring mode before enforcement.
- Track telemetry coverage, inventory join rate and time to contain for NHI incidents.
Standards and references
- OWASP: Non-Human Identities Top 10 2025
- NIST: SP 800-53 Rev. 5
- AWS: CloudTrail userIdentity element
- Microsoft Learn: Securing workload identities with ID Protection
- Microsoft Learn: Sign-in logs in Microsoft Entra ID
- Google Cloud: Examples of audit logs for service accounts
- GitHub Docs: Identifying audit log events performed by an access token
- MITRE ATT&CK: Additional Cloud Credentials
Related NHI Mgmt Group resources: ITDR Guide · Detection Engineering Guide · Service Account Security Guide · Honeytokens and Canary Credentials Guide