AWS Machine Identity Discovery: How to Find Every Role, Key and Trust Relationship
A walkthrough for discovering machine identities across an AWS organization: roles, access keys, trust policies, last used data and cross-account access.
Key takeaways
- Overprivileged machine identities are not only a big company problem. A four person startup can have more than a hundred.
- Look across the whole AWS organization, not one account at a time.
- Read every role's trust policy. It tells you who can become that role.
- Treat last used data as a reason to ask, not proof that something is safe to delete.
- Every role trusted from outside your organization needs an internal owner.
We recently worked with a four person startup on AWS that had more than 130 machine identities with more access than they needed. Four people. It is a useful reminder that this is not just a big company problem. Every team that ships on AWS builds up roles, keys and trust relationships faster than anyone tracks them.
The good news is that AWS gives you most of what you need to find them. Here is how to approach it.
Know what you are looking for
In AWS, machine identities mostly show up as IAM roles assumed by services, workloads, other accounts or federated users 1. Add IAM users that hold access keys, which AWS recommends replacing with temporary credentials where possible 2, plus instance profiles, service-linked roles and the SAML or OIDC identity providers that let outside systems such as CI pipelines assume roles. Any AI agent or workload acting through these counts too.
Look across the whole organization
Checking one account at a time misses things. Place a single read-only role in every account through AWS Organizations so new accounts are covered automatically. While you are there, note the service control policies, since they set the outer limits on what any identity in an account can do 3.
Read the trust policies
This is the step most inventories skip, and often the most revealing. A role's permissions tell you what it can do. Its trust policy tells you who can become it. Watch for outside account IDs you don't recognize, wildcard principals, loosely conditioned identity providers, and third-party roles with no external ID, which AWS calls a confused deputy risk 4. IAM Access Analyzer can point out roles and resources shared outside your organization 5.
Use last used data carefully
The IAM credential report lists every user with key status, key age and last use 6. Last accessed information shows which services, and some actions, a role or user has touched 7. Both are helpful. Neither is complete: tracking covers a limited window and not every action. Treat "unused" as a prompt to ask the owner, not as permission to delete.
Pay attention to access from outside
Map which roles can be assumed from other accounts in your organization and which from outside it. Vendor roles in particular tend to keep their access long after the relationship changes. Each needs someone inside your team who owns it.
An example of what to look for
Here is a made-up case. A role called deploy-legacy is trusted by an outside account nobody recognizes, has administrator access, and was last used eight months ago. The trust makes it a way in, the permissions make it a wide one, and the age suggests nobody is watching. It goes to the top of the list, and the first question is simply: who owns this?
From a list to an inventory
Once you can see everything, give each identity an owner, a purpose and a note on what it can reach, then repeat discovery regularly and compare runs. Our guide to keeping a machine identity inventory current walks through that routine.
Where Avistar fits, and where it doesn't
Avistar discovers AWS machine identities across accounts with read-only, agentless access, reads trust relationships, and shows the blast radius of each identity alongside ownership and staleness. It does the same for Azure and Google Cloud, so you work from one list instead of three. It does not modify roles, delete keys or block an attacker. Your teams make the changes.
Read next: IAM for AI agents and machine identities, the bigger picture on why agents should never simply borrow your access.
Frequently asked questions
- What counts as a machine identity in AWS?
- IAM roles, IAM users with access keys, instance profiles, service-linked roles, federated identity providers, and any AI agents or workloads that act through them.
- Why do trust policies matter?
- A role's permissions say what it can do; its trust policy says who can become it. A role trusted by an outside account or a broad principal can be a way in even if nobody inside your organization uses it.
- Does unused last accessed data mean a permission is safe to remove?
- Not on its own. AWS tracks last accessed data over a limited period and not for every action, so check with the owner before removing access that might be needed for rare tasks such as disaster recovery.
Sources
- https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html
- https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html
- https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scps.html
- https://docs.aws.amazon.com/IAM/latest/UserGuide/confused-deputy.html
- https://docs.aws.amazon.com/IAM/latest/UserGuide/what-is-access-analyzer.html
- https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_getting-report.html
- https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_last-accessed.html