Join our Newsletter — 33% off our NHI Course
Home› Guides› Service Account Behavioural Baselining Guide: Spotting Machine Identities…
Guide Non-Human Identity (NHI)

Service Account Behavioural Baselining Guide: Spotting Machine Identities That Change Behaviour

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

When an attacker steals a service account key or API token, every request they make is authenticated and authorised, so the only thing that gives them away is that the identity starts behaving differently. Service accounts, workload roles and API keys are well suited to behavioural baselining because, unlike people, they normally do the same things from the same places on a predictable schedule. This guide explains which behaviours to baseline (source network, API calls, resources, timing, volume, user agent and credential), which log sources to use in AWS, Microsoft Entra ID, Google Cloud, Kubernetes and SaaS, how to build and tune baselines, what the built-in cloud detections already cover, and how to measure the result. It is written for detection engineers, identity security teams and cloud security architects. For turning these signals into a prioritised risk score, see the NHI Risk Scoring Guide; this page covers the detection layer underneath.

Key takeaways

  • Machine identities are predictable, which makes deviations meaningful. A deployment role that has called the same 15 APIs from one VPC for a year and suddenly lists every bucket from a residential IP is a far stronger signal than most human anomalies.
  • Baseline per identity and per credential, not per account. One service principal may have three secrets and a certificate; a sign-in with a key that is normally unused is itself an anomaly.
  • Source network is the highest-value dimension. Stolen NHI credentials are almost always used from somewhere new: AWS GuardDuty has dedicated findings for instance credentials used outside AWS, and Entra ID Protection flags unfamiliar IP, ASN and country for service principals.
  • First-seen actions beat volume thresholds. First use of an API, region, resource or permission-discovery call catches reconnaissance early; volume rules catch abuse only after damage has started.
  • Baselines need change context. Feed deployments and configuration changes into the detection pipeline, or every release will look like a compromise and analysts will stop trusting the alerts.

Why baselining works for non-human identities

Static rules such as "alert on access from a Tor exit node" catch careless attackers. Behavioural baselining catches the rest: an attacker using a valid key from an ordinary cloud host, calling permitted APIs. It works well for NHIs because their behaviour is defined by code. A payment service calls the same endpoints for the same tables every day; a backup job runs at 02:00; a CI deployment role is only active during pipeline runs. The same property makes NHI baselines cheaper to build than human UEBA: there is less natural variance, so shorter learning windows and simpler models work. See the UEBA Guide for the human side and shared tooling.

NIST SP 800-53 Rev. 5 names this directly in AC-2(12) Account Monitoring for Atypical Usage, which asks organisations to monitor system accounts for atypical usage and report it. It applies to service accounts as much as to people.

What to baseline: the core dimensions

DimensionExamples of normalAnomaly that mattersTypical attacker cause
Source networkSpecific VPC endpoints, NAT gateway IPs, a CI provider's ranges, one cloud regionNew IP, new ASN, residential or hosting provider not seen before, new country, IP outside the cloud for an instance credentialKey copied from code, logs or a compromised host and used elsewhere
API and action setA fixed list of read and write callsFirst-seen API, especially List*, Get*Policy, GetCallerIdentity-style identity checks, or IAM write callsReconnaissance, privilege escalation, persistence
ResourcesNamed buckets, tables, queues, projectsAccess to resources outside the usual set, cross-account or cross-project callsData discovery and exfiltration
Region and serviceOne or two regions, a known set of servicesCalls in unused regions or to new services (for example AI model APIs)Resource abuse, hiding activity in unmonitored regions
TimingBusiness hours, cron schedules, pipeline windowsActivity outside schedule, a dormant identity becoming activeOff-hours attacker use, reuse of forgotten accounts
Volume and rateStable calls per hour, low error rateSpikes in calls, data transferred or access-denied errorsBulk exfiltration, permission brute-forcing
Client fingerprintOne SDK and version, one user agentCLI or browser user agent on a workload identity, new SDKHuman or attacker tooling using an NHI credential
Credential usedOne active key or certificate per identitySign-in with a rarely used secret, newly added credential, credential type changeAttacker-added credential or a leaked old key

The client fingerprint dimension also catches policy violations rather than attacks: an engineer using a production service account key from a laptop is OWASP NHI10 Human Use of NHI. See the OWASP NHI Top 10 NHI10 Human Use of NHI Guide.

Log sources by platform

PlatformSourceFields to baselineNotes
AWSCloudTrail management events (and data events for S3, Lambda and others where enabled)userIdentity.arn, accessKeyId, sourceIPAddress, userAgent, eventName, eventSource, awsRegion, errorCode, recipientAccountIdCollect all regions into one trail; attackers use regions you do not watch. See the AWS CloudTrail Guide
Microsoft Entra IDService principal sign-in logs and, separately, managed identity sign-in logsService principal, IP address, resource, status, credential usedManaged identity sign-ins are excluded from the service principal log and appear only in their own log
Google CloudCloud Audit Logs (Admin Activity, Data Access)authenticationInfo.principalEmail, service account key ID, callerIp, methodName, resourceData Access logs are off by default for most services; enable them for sensitive data
KubernetesAPI server audit logsService account username, verb, resource, namespace, source IP, user agentWatch service accounts that start reading secrets or creating pods. See the Kubernetes Service Account Token Guide
Databases and warehousesNative login and query historyClient IP, client driver, warehouse or schema, rows returnedService users should have a narrow, stable query pattern
SaaS and APIsAudit logs for API tokens and OAuth appsToken ID, IP, endpoints, record countsCoverage varies by vendor and licence tier; check before you rely on it

What the platforms already detect

Before building custom models, turn on the native detections. They are trained on far more data than any single organisation has, but each covers only its own platform and only some identity types.

Platform detectionBehaviour baselinedCoverage limits
AWS GuardDuty *:IAMUser/AnomalousBehavior families (CredentialAccess, DefenseEvasion, Discovery, Exfiltration, Impact, InitialAccess, Persistence, PrivilegeEscalation)An ML model over CloudTrail management events tracking factors such as the calling identity, location and specific APIManagement events only for these findings; severity ranges from Low (Discovery) to High (Exfiltration, Impact)
AWS GuardDuty UnauthorizedAccess:IAMUser/InstanceCredentialExfiltration.OutsideAWS and .InsideAWS; ResourceCredentialExfiltration variants for ECS and LambdaInstance or task credentials used from an external IP or a different AWS accountGuardDuty learns repeated remote sources as expected and stops alerting on them, so investigate the first alert
AWS CloudTrail InsightsAPI call rate and API error rate against a learned baseline, per regionRate anomalies only, not identity-specific; extra cost
Microsoft Entra ID Protection: Suspicious Sign-ins (workload identities)Baselines service principal sign-ins over 2 to 60 days; flags unfamiliar IP or ASN, target resource, user agent, hosting change, country or credential typeManaged identities are not in scope; full details and risk-based Conditional Access need Workload Identities Premium
Microsoft Entra ID Protection: Anomalous service principal activity, Suspicious API Traffic, Leaked CredentialsUnusual administrative directory changes, abnormal Graph traffic or enumeration, credentials found leakedSame licensing and scope limits
Google Security Command Center Event Threat DetectionRules such as Initial Access: Dormant Service Account Action, Dormant Service Account Key Created, Discovery: Service Account Self-Investigation, Initial Access: Leaked Service Account Key UsedTier and rule availability vary; dormant rules apply to user-managed service accounts

The Google "self-investigation" rule is worth copying to other clouds: a service account that suddenly queries its own permissions is very rarely doing so for a legitimate reason. In AWS the equivalent is a workload role calling IAM read APIs it has never called before.

Building baselines: a phased approach

  1. Inventory and classify. Join your NHI inventory to owners, environment and purpose (deployment, application runtime, integration, batch). Purpose sets expectations: a CI role should only be active during pipeline runs. See the Service Account Inventory Template.
  2. Centralise logs. Bring cloud audit, sign-in, Kubernetes audit and database logs into one store with a normalised identity key (role ARN, service principal ID, service account email, key ID).
  3. Learn per-identity profiles. For each identity, record the set of source networks (as CIDR or ASN), APIs, resources, regions, user agents, credentials and active hours over a learning window. Two to four weeks suits most workloads; monthly batch jobs need at least one full cycle. Entra's own learning period of 2 to 60 days is a useful reference.
  4. Start with first-seen rules. Alert when an identity uses a network, API, region or credential not in its profile. These are simple, explainable and catch most credential theft.
  5. Add peer-group comparison. Compare identities of the same purpose (for example all Lambda execution roles in a service). An identity that differs from its peers is suspicious even if its own history is short.
  6. Add rate and volume models. Use per-identity percentiles for calls per hour, bytes read and error rates. Alert on large deviations combined with a first-seen signal, not on volume alone.
  7. Run in shadow mode. Write alerts to a test index for two to four weeks, review them against change records and tune before paging anyone.
  8. Roll back safely. Keep each rule versioned and switchable; if a rule floods the queue after a platform change, disable it and re-learn rather than widening it permanently.

Decision guidance: small teams should rely on native detections plus a handful of first-seen rules on their most privileged identities (deployment roles, identities with IAM write or data export rights). Large estates with thousands of NHIs need automated profiling, peer groups and suppression driven by change management data, typically in the SIEM or an ITDR platform. See the ITDR Guide.

Detection rules worth having

RuleLogicATT&CK
Workload credential used off-platformCredential issued to a cloud workload used from an IP outside the provider or the organisation's rangesT1078.004, T1552.005
First-seen identity discoveryIdentity calls permission or identity enumeration APIs for the first timeT1087.004
New credential added to an NHIAccess key, client secret or certificate created for an existing identity outside an approved pipelineT1098.001
Dormant identity activeNo activity for 30 days or more, then any actionT1078
Human tooling on an NHICLI, browser or console user agent on a workload credentialT1078
New region or new serviceFirst calls in an unused region or to a new service familyT1078.004
Bulk data readVolume of object or row reads far above the identity's percentile, combined with a new network or resourceT1530
Logging tamperingIdentity changes logging or monitoring configuration it has never touched; a first-time query of that configuration is an early warningT1685

The LLMjacking campaigns show why first-seen rules matter: attackers with stolen cloud keys tested model access with deliberately invalid requests, checked whether invocation logging was enabled, requested model access for the first time and then spread usage across regions. Each step was a first-seen API or region for the identity, visible well before the bill arrived. For more rule content, see the Detection Engineering for Non-Human Identities Guide.

Responding to an anomaly

  • Triage with context: check for a matching deployment or change record, the identity's owner and the credential involved. The anomaly is a lead, not a verdict.
  • Contain the credential, not just the session: deactivate the specific key or secret, revoke active sessions where the platform supports it (for AWS, an explicit deny on tokens issued before a time), and check for credentials the attacker may have added.
  • Use platform workflows: in Entra ID, confirm or dismiss the risky workload identity so the risk history and Conditional Access react; in AWS follow GuardDuty's remediation guidance for compromised credentials.
  • Feed the result back: a confirmed benign change updates the baseline; a confirmed compromise becomes a test case for the rule.

Detection and measurement

Metrics that show the baselining programme is working:

  • Percentage of privileged NHIs with an active behavioural profile and at least one first-seen rule.
  • Log coverage: percentage of NHIs whose activity reaches the SIEM from every platform and region they use.
  • Alert precision: share of NHI anomaly alerts that are true positives or policy violations, tracked per rule.
  • Mean time from first anomalous action to credential deactivation, measured in incidents and purple team exercises.
  • Number of human-use-of-NHI findings per month, trending down as owners move to proper human access.

Framework mapping

FrameworkReferenceRelevance
NIST SP 800-53 Rev. 5AC-2(12), SI-4, AU-6Monitoring accounts for atypical usage, system monitoring, audit review and analysis
NIST CSF 2.0DE.CM-03, DE.CM-09, DE.AE-02, DE.AE-03Monitoring technology usage, runtime environments, analysing and correlating events
ISO/IEC 27001:2022 Annex A8.15, 8.16Logging and monitoring activities
MITRE ATT&CKT1078.004, T1098.001, T1087.004, T1530Valid cloud accounts, added cloud credentials, cloud account discovery, data from cloud storage
OWASP NHI Top 10NHI2, NHI10Leaked secrets used by attackers; humans using NHI credentials

Common failure patterns

  • Baselining the account, not the identity: rate anomalies across a whole AWS account hide one role behaving badly among thousands.
  • Learning from a compromised period: if an attacker is already present during the learning window, their behaviour becomes normal. Review profiles of privileged identities by hand before trusting them.
  • Ignoring regions and services you do not use: attackers go where logging and baselines are thin. Collect logs from every region.
  • Alerting on volume only: by the time a volume threshold fires, data is gone. Combine first-seen and volume.
  • No change feed: every release triggers alerts, analysts mute the rules, and real compromises pass unnoticed.
  • Assuming native detection covers everything: Entra ID Protection does not cover managed identities, and GuardDuty stops alerting on remote sources it has seen repeatedly. Know the gaps and fill them.

Practitioner checklist

  • Enable GuardDuty, Entra ID Protection for workload identities and Security Command Center threat detection where you run those platforms.
  • Centralise cloud audit, sign-in, Kubernetes audit and database logs with a normalised identity and credential key.
  • Build per-identity profiles of networks, APIs, resources, regions, user agents, credentials and active hours.
  • Deploy first-seen rules for network, API, region and credential on privileged NHIs first.
  • Alert on new credentials added to existing NHIs outside approved pipelines.
  • Detect human tooling on workload credentials and route findings to the identity owner.
  • Feed deployment and change records into suppression logic.
  • Run new rules in shadow mode, track precision per rule and retire noisy ones.
  • Rehearse containment: deactivate a key and revoke sessions within an agreed time.

Standards and references

Related NHI Mgmt Group resources: NHI Risk Scoring Guide · Detection Engineering for Non-Human Identities Guide · UEBA Guide · AI Agent Behaviour Baselining and Anomaly Detection Guide · ITDR Guide

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