Non-human identity: governing the machine accounts that outnumber your users
Pull the identity list for almost any mature SaaS deployment and the humans are a rounding error. Service accounts, CI runners, Kubernetes service identities, API keys, webhook signers, OAuth clients, and now autonomous agents make up the overwhelming majority of principals that can authenticate. These non-human identities (NHIs) typically outnumber employees by an order of magnitude, and unlike employees they do not go through joiners-movers-leavers review, they rarely rotate their credentials, and nobody gets a calendar reminder when one should be retired. The breaches that start with a leaked token almost never start with a human password.
Why NHIs rot faster than human accounts
Human identity governance has decades of tooling: HR systems trigger deprovisioning, managers certify access quarterly, and a departing employee's accounts get disabled on their last day. None of that fires for a machine. A service account created for a one-off migration in 2023 is still there, still holds the broad database role it was granted "temporarily," and its static credential sits in a secret store that three teams can read.
The structural problems are consistent:
- No owner. The engineer who created the account left the company; the account's purpose lives only in their memory.
- No expiry. Static keys and client secrets outlive the workloads they were minted for.
- Over-scoping. It is faster to grant admin than to enumerate the three permissions a job actually needs, so people grant admin.
- Credential sprawl. The same key is copied into a CI variable, a Terraform state file, and a developer's laptop.
Step one: inventory what can authenticate
You cannot govern what you cannot see. An inventory means every principal that holds a credential, across every system, with enough metadata to make decisions. At minimum capture the identity, its type, its owner, its last authentication time, and its granted privileges.
-- Non-human identities that have not authenticated in 90 days
SELECT i.id,
i.display_name,
i.identity_type, -- service_account | api_key | oauth_client | agent
i.owner_team,
i.created_at,
i.last_auth_at,
i.scopes
FROM identities i
WHERE i.identity_type <> 'human'
AND (i.last_auth_at IS NULL
OR i.last_auth_at < now() - interval '90 days')
ORDER BY i.last_auth_at NULLS FIRST;The rows that come back with a null owner or a null last-auth timestamp are your highest-risk population: live credentials nobody is watching and nothing is using. Dormant-but-privileged is the worst quadrant — attractive to an attacker, invisible to you.
Rule of thumb: every non-human identity needs a named human or team owner recorded at creation time, and creation should be refused without one. Ownership is not metadata you backfill during an incident; it is the single field that makes all later governance possible.
Step two: scope to the job
Least privilege for machines is more tractable than for people because a machine's job is narrow and observable. Watch what an account actually calls for a few weeks, then cut its grant down to that set. Replace standing broad roles with purpose-built roles:
- A backup job gets read on the tables it dumps and write on the backup bucket — not
db_owner. - A webhook receiver gets permission to enqueue events — not to read user records.
- An agent gets a scope per tool it is allowed to call, minted per session.
Prefer workload identity federation over static keys wherever the platform supports it. A workload that can prove what it is — through its cloud instance identity, its Kubernetes service account token, or a signed OIDC assertion — can exchange that proof for a short-lived credential instead of carrying a long-lived secret. The static key you never issued is the one you never have to rotate or revoke.
Step three: rotate, expire, and revoke
Static credentials that must exist need a rotation schedule enforced by the platform, not by goodwill. Set a maximum age and treat an over-age secret as an incident. Better still, issue credentials with a built-in exp so the default outcome is expiry, and continuation requires an explicit refresh you can observe and cut off.
# Flag client secrets older than the 90-day policy
for c in $(list-oauth-clients --type=service); do
age=$(client-secret-age-days "$c")
if [ "$age" -gt 90 ]; then
echo "ROTATE: $c (secret age ${age}d)"
fi
doneCertification, for machines
Borrow access review from human IAM but automate the evidence. Each quarter, send every owner the list of NHIs they own, each account's recent activity, and its current scope, and require an explicit keep-or-kill decision. Accounts with no activity and no response default to disabled. This is the control that actually shrinks the population over time.
Agents are NHIs with a new failure mode
Autonomous agents belong in this inventory, but they carry a twist: their behavior is driven by text that an attacker may influence through prompt injection. An over-scoped service account is dangerous if its credential leaks; an over-scoped agent is dangerous even if nothing leaks, because the agent can be argued into misusing the authority it legitimately holds. The mitigation is the same discipline turned up: the narrowest possible scope, the shortest possible token lifetime, and an audit record that attributes every action back to the delegating user.
Machine identities are not a niche corner of IAM anymore; they are the majority of your attack surface, and governing them is ongoing inventory, scoping, and rotation rather than a one-time cleanup. Keeping the issuance point, the scope catalog, and the revocation switch for every non-human principal inside infrastructure you operate — rather than scattered across vendor consoles — is what makes that discipline sustainable. Self-hosting your identity layer is one way to keep that switch in reach.
Run it yourself
Bastionary is free, open-source software. Follow the quick start to have it running on your own server, or browse the releases on Git.