AWS Builder Center
Securing the Unseen: A Complete Deep Dive into Non-Human Identities in AWS

Securing the Unseen: A Complete Deep Dive into Non-Human Identities in AWS

An exhaustive technical guide on the rising threat of Non-Human Identities (NHIs) in AWS, covering IAM Roles, STS, IMDSv2, OIDC federation, IRSA, Secrets Manager, and advanced detection techniques.

Cybersecurity Student | Pentester | AWS Cloud Learner
For decades, cybersecurity focused on humans. We built password policies, enforced Multi-Factor Authentication (MFA), and trained employees not to click on phishing links.
But the cloud changed everything. In 2026, the majority of identities in an enterprise AWS environment are not human. They are applications, microservices, CI/CD pipelines, and AI agents. These are called Non-Human Identities (NHIs).
According to recent cloud security reports, NHIs now outnumber human identities by a ratio of 45 to 1 in large organizations. Yet, most security teams barely monitor them. Attackers know this. They are no longer trying to steal a developer's password. They are hunting for unrotated access keys, overly permissive IAM roles, and exposed service accounts.
This article is a comprehensive technical deep dive into how NHIs work in AWS, the mechanics of AWS STS, how they are compromised, and the architectural best practices to secure them.

1. What is a Non-Human Identity (NHI)?

A Non-Human Identity is any identity used by a machine, application, or automated process to authenticate and interact with AWS resources. It is a digital identity that represents a workload, not a person.
Common examples of NHIs in AWS:
  • An IAM Role attached to an EC2 instance (Instance Profile).
  • An IAM Role for Service Accounts (IRSA) used by an Amazon EKS pod.
  • A Lambda Execution Role.
  • A CI/CD pipeline (like GitHub Actions) using OpenID Connect (OIDC) to assume a role.
  • Long-term IAM User Access Keys used by legacy applications.
  • AWS Service Roles used by services like Config, GuardDuty, or CloudTrail.
Unlike humans, NHIs do not log in through a web browser. They authenticate via API calls using temporary credentials or access keys. They do not take a lunch break. They run 24/7, making thousands of API calls per minute.

2. The Core Technology: How AWS STS Powers NHIs

To understand NHIs, you must understand the AWS Security Token Service (STS). STS is the engine that issues temporary credentials.
When a non-human identity needs to access an AWS resource, it does not use a password. It calls the STS  AssumeRole  API. STS validates the identity and returns three things:
  1. Access Key ID
  1. Secret Access Key
  1. Session Token
These credentials are temporary. They expire based on the duration you set (minimum 15 minutes, maximum 12 hours). This is the fundamental security advantage of IAM Roles over IAM Users.

3. The Anatomy of an NHI Compromise

How do attackers exploit NHIs? It usually happens in three phases.

Phase 1: Discovery

Attackers look for exposed credentials. They scan public GitHub repositories 24/7 for strings starting with  AKIA . They look for misconfigured S3 buckets containing  .env  files. They exploit SSRF vulnerabilities in web applications to query the EC2 metadata service.

Phase 2: Privilege Escalation

Once they have a credential, they use tools like  Pacu ,  enumerate-iam , or  ScoutSuite  to figure out what permissions the identity has. If the NHI has an overly permissive policy (like  IAMFullAccess  or  * ), the attacker can create a new backdoor user or escalate to full administrator.
A common escalation path is  iam:CreatePolicyVersion . If an attacker has this permission on a role, they can create a new version of the policy that grants  *:*  and set it as the default.

Phase 3: Lateral Movement

Using the compromised NHI, the attacker moves laterally. If a CI/CD role has read access to an S3 bucket, they steal the data. If a Lambda role has write access to DynamoDB, they manipulate the database.

4. The IAM Role vs. Access Key Problem

The most critical distinction in NHI security is between IAM Roles (temporary credentials) and Access Keys (long-term credentials).

The Danger of Long-Term Access Keys

Access keys do not expire. If an access key is leaked, it remains valid until someone manually deletes it. Attackers love access keys because they offer persistent, uninterrupted access.

The Power of IAM Roles

IAM Roles use the AWS Security Token Service (STS) to issue temporary credentials. These credentials automatically expire. Even if an attacker intercepts them, they are useless after a short window.
The Golden Rule: Never use long-term access keys for applications running inside AWS. Always use IAM Roles.

5. Deep Dive: EC2 Instance Profiles and IMDSv2

When you attach an IAM Role to an EC2 instance, AWS automatically injects temporary credentials into the instance metadata service (IMDS). The application calls  http://169.254.169.254/latest/meta-data/iam/security-credentials/  to retrieve the credentials.

The SSRF Problem

IMDSv1 had a critical vulnerability. If a web application on the EC2 instance had a Server-Side Request Forgery (SSRF) flaw, an attacker could make the server request the metadata URL. The server would return the IAM role credentials to the attacker.

The Solution: IMDSv2

AWS introduced IMDSv2 to fix this. It requires a two-step process:
  1. The application makes a  PUT  request to get a session token.
  1. It uses that token in the  X-aws-ec2-metadata-token  header to request credentials.
Because IMDSv2 requires a  PUT  request with a custom header, most SSRF vulnerabilities cannot exploit it.
How to Enforce IMDSv2: You can enforce IMDSv2 at the account level using AWS Organizations Service Control Policies (SCPs), or by setting  HttpTokens  to  required  on each instance.

6. Deep Dive: IAM Roles for Service Accounts (IRSA) in EKS

In Amazon EKS, pods often need to access AWS services. Before IRSA, people used the EC2 instance profile, which meant every pod on the node had the same permissions. This was a massive blast radius problem.

How IRSA Works

IRSA solves this by using OIDC federation.
  1. The EKS cluster has an OIDC provider URL.
  1. Each service account in Kubernetes is annotated with an IAM role ARN.
  1. When a pod starts, Kubernetes injects a signed JWT token into the pod.
  1. The AWS SDK in the pod calls STS  AssumeRoleWithWebIdentity , passing the JWT.
  1. STS validates the JWT against the OIDC provider and issues temporary credentials.
If one pod is compromised, the blast radius is contained to that specific service account.

7. Deep Dive: OIDC for CI/CD Pipelines

Modern CI/CD tools (GitHub Actions, GitLab) no longer need to store long-term AWS access keys. They use OpenID Connect (OIDC).

How it Works

  1. The CI/CD provider acts as an OIDC identity provider.
  1. AWS IAM is configured to trust this provider.
  1. When a workflow runs, the CI/CD platform generates a signed JWT token.
  1. The workflow calls  sts:AssumeRoleWithWebIdentity  passing the JWT.
  1. STS validates the token and issues temporary credentials.
The IAM role trust policy can be scoped to a specific repository and branch. For example, only the  main  branch of the  my-app  repository can assume the role.

8. Storing Secrets: Secrets Manager vs. Parameter Store

While IAM Roles are great for AWS-to-AWS authentication, what about database passwords or third-party API keys? You cannot use an IAM Role for those. You must use a secret store.
Do not hardcode secrets. Use AWS Secrets Manager or Systems Manager Parameter Store.

Secrets Manager

  • Specifically designed for secrets.
  • Supports automatic rotation (e.g., automatically rotating an RDS password every 30 days).
  • Cost: Charged per secret per month.

Parameter Store (SecureString)

  • Good for configuration and simple secrets.
  • Uses KMS for encryption.
  • Cheaper (Standard tier is free).
  • No built-in native rotation (requires a Lambda function to rotate).

9. Detecting NHI Compromises with GuardDuty

AWS GuardDuty has specific findings designed to catch compromised NHIs.
GuardDuty Findings to Watch:
  •  UnauthorizedAccess:IAMUser/InstanceCredentialExfiltration : This fires when credentials assigned to an EC2 instance are used from an IP address outside of AWS. This indicates the credentials were stolen.
  •  UnauthorizedAccess:IAMUser/InstanceCredentialExfiltration.InsideAWS : This fires when credentials are used from another AWS account. This often indicates lateral movement by an attacker.
  •  Discovery:IAMUser/AnomalousBehavior : This detects unusual API calls, such as an application suddenly trying to list all IAM users.

10. Best Practices for NHI Governance

Securing NHIs requires a shift in mindset. You must treat them with the same rigor as human identities.

10.1 Enforce Least Privilege with IAM Access Analyzer

Do not guess permissions. Use IAM Access Analyzer to generate a policy based on actual CloudTrail activity. It watches what the role actually does and creates a precise policy for it.

10.2 Use Permissions Boundaries

If you allow developers to create IAM roles, attach a Permissions Boundary. This ensures that even if they create a role with  AdministratorAccess , the boundary blocks them from exceeding a safe limit.

10.3 Rotate Credentials Automatically

If you absolutely must use access keys (e.g., for a legacy on-premise server), rotate them every 90 days. Use AWS Config or a custom Lambda function to enforce rotation.

10.4 Inventory and Tag Your NHIs

You cannot secure what you cannot see. Use AWS Resource Access Manager (RAM) and tagging to build an inventory of all IAM roles, their owners, and their purpose. AWS recommends tagging roles with  owner ,  environment , and  data-classification .

11. Final Summary

The era of focusing solely on human identity is over. Non-Human Identities are the backbone of modern cloud architecture, and they are the primary target for sophisticated attackers.
To secure NHIs, you must eliminate long-term access keys, embrace IAM Roles and OIDC, monitor with GuardDuty, and enforce least privilege through tooling like Access Analyzer.
As a cybersecurity professional, understanding NHIs is no longer a niche skill. It is a fundamental requirement for securing the cloud.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article