Join our Newsletter — 33% off our NHI Course
Home› Guides› Detection Engineering for Non-Human Identities Guide: Baselining Service…
Guide SOC & Detection Engineering

Detection Engineering for Non-Human Identities Guide: Baselining Service Accounts, Keys and Tokens

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 27 October 2026 13 min read
On this page

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

CharacteristicHuman identityNon-human identityDetection consequence
AuthenticationInteractive, MFA, device signalsSecret, key, certificate or federated token; no MFASign-in risk rules built on MFA and device state do not apply
BehaviourVariable hours, locations, tasksRepetitive API set, fixed sources, scheduledTight baselines with low false positive rates are achievable
Credentials per identityUsually one password plus sessionsOften several keys or secrets, sometimes shared across systemsRules must key on credential ID (access key ID, key name, token hash)
OwnershipThe personOften unclear or departedTriage stalls without an owner field in the inventory
LifecycleJoiner, mover, leaver processCreated ad hoc, rarely retiredDormant identities that become active are a key signal
Who should use itIts ownerOnly its workloadHuman 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.

PlatformLog sourceIdentity and credential fieldsNotes
AWSCloudTrailuserIdentity.type (IAMUser, AssumedRole, AWSService and others), userIdentity.accessKeyId, sessionContext.sessionIssuer.arn, sessionContext.attributes.creationDate, sessionContext.ec2RoleDeliveryFor 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 IDService principal sign-in logs; managed identity sign-in logs; audit logsApplication ID, service principal ID, credential used, IP address, resourceManaged identity sign-ins are aggregated by identity, status and resource in the portal; export raw logs through diagnostic settings for detection
Google CloudCloud Audit LogsauthenticationInfo.principalEmail, authenticationInfo.serviceAccountKeyName, serviceAccountDelegationInfo for impersonationSome services do not log the key name; GenerateAccessToken events need IAM Data Access audit logs enabled
GitHubOrganisation or enterprise audit loghashed_token (SHA-256, Base64), programmatic_access_type, token_scopesGit events are not returned by UI or API search and need an audit log export or stream
KubernetesAPI server audit loguser.username (system:serviceaccount:<ns>:<name>), sourceIPs, userAgentOnly generated when an audit policy is configured. See the Kubernetes Audit Log Detection Guide
Active DirectoryDomain controller security logService account name, logon type, source hostInteractive logon (type 2 or 10) by a service account is a classic high-fidelity rule
Secrets managersVault or cloud secrets manager audit logsCaller identity, secret path, operationReads by unexpected principals reveal credential harvesting
SaaS platformsAdmin and API audit logsAPI key or integration user, OAuth client IDCoverage 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 ListUsers or GetSecretValue is 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

RuleLogic (summary)Why it mattersATT&CK
New credential added to an existing identityKey, secret or certificate created on a service account or service principal, outside the rotation pipeline's identityClassic persistence that survives password resetsT1098.001 Additional Cloud Credentials
Privilege grant to a machine identityRole assignment, policy attachment or app role grant to an NHI outside change windowsEscalation and persistence; Midnight Blizzard granted itself a mail-wide application roleT1098.003 Additional Cloud Roles
Credential used from a new sourceFirst use of a key or token from an IP, ASN or region not in its baselineMost direct signal of theftT1078.004 Cloud Accounts, T1550.001 Application Access Token
Dormant identity reactivatedNo activity for [90] days, then any authenticationStolen credentials for forgotten identities are a common footholdT1078
Human use of a machine credentialInteractive logon, console sign-in, or CLI user agent for an identity whose baseline is SDK onlyInsider shortcut or attacker hands-on useT1078
Discovery burstIdentity calls enumeration APIs (users, roles, buckets, secrets) it has not used beforeAttackers' first moves with a stolen keyT1087.004 Cloud Account, T1580 Cloud Infrastructure Discovery
Secret read by an unexpected principalSecrets manager reads by an identity not mapped to that secretCredential harvesting and lateral movementT1555.006 Cloud Secrets Management Stores
Instance credentials used outside the instanceInstance or workload role session used from an address outside your cloudMetadata credential theftT1552.005 Cloud Instance Metadata API
New machine identity created by a machine identityService account or app registration created by an NHI outside provisioning automationAttacker-made identities for persistenceT1136.003 Cloud Account
Bulk data accessObject reads or exports far above baseline volumeExfiltration with a valid keyT1530 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

  1. 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.
  2. Normalise identity fields across platforms into a common schema: identity ID, credential ID, identity type, source, action, result.
  3. Write the change-event rules first (new credential, new privilege, new identity), because they need no baseline and fire rarely.
  4. Add baseline rules for the most privileged identities, then expand by tier.
  5. 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.
  6. 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.
  7. 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.
  8. 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_app role. 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

FrameworkReferenceRelevance
OWASP Non-Human Identities Top 10 2025NHI1 Improper Offboarding; NHI2 Secret Leakage; NHI5 Overprivileged NHI; NHI7 Long-Lived Secrets; NHI10 Human Use of NHIRisks that dormant-identity, new-source, privilege and human-use rules detect
NIST CSF 2.0PR.AA-01; PR.PS-04; DE.CM-03; DE.CM-09; DE.AE-02; DE.AE-03Managed identities and credentials, log generation, monitoring, analysis and correlation
NIST SP 800-53 Rev. 5AC-2 Account Management; AC-2(12) Account Monitoring for Atypical Usage; AU-6 Audit Record Review, Analysis, and Reporting; SI-4 System MonitoringControl basis for monitoring machine accounts
CIS Controls v8.1Control 5 Account Management; Control 8 Audit Log ManagementService account inventory and log collection
MITRE ATT&CKT1078, T1078.004, T1098.001, T1098.003, T1136.003, T1550.001, T1552.005, T1555.006, T1087.004, T1580, T1530Behaviours 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

Related NHI Mgmt Group resources: ITDR Guide · Detection Engineering Guide · Service Account Security Guide · Honeytokens and Canary Credentials Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 27 October 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.