Secure architectures · 13 min
Root user, roles and temporary credentials in IAM
In this lesson you will learn which tasks the root user is for, when an IAM user is the right choice and when a role is, how long a role's credentials last and where an application gets credentials without storing keys in the code.
AWS Identity and Access Management (IAM) is the service that decides who can get into an AWS account and what they can do inside it. Without IAM, anyone who got into the account could do everything, even delete it. For example, in an online store, IAM is what lets the support person see the orders without being able to delete the database, and lets the site's program store product photos without being able to touch billing.
The IAM identities are the root user, users, groups and roles. On the Solutions Architect exam you are asked which of them you put in an architecture, and the difference that decides most of those questions is how long their credentials last. An access key, which is a pair of long codes a program uses to identify itself to AWS, never expires on an IAM user and lasts until someone deletes it, while a role's credentials expire on their own within hours. For example, if someone copies the access key of one of the store's users, they can use it months later; if they copy a role's credentials, those stop working that same day.
The root user
When you create an AWS account, a single identity with full access to all services and resources is created, which is called the root user and signs in with the email address and password the account was opened with. AWS requires MFA for the root user by default, but you register the device yourself, when you create the account or when AWS asks you to at sign-in. MFA (multi-factor authentication) asks, besides the password, for a code that comes from something only you have, such as an app on your phone or a physical key. For example, if someone guesses the store's root password, they still can't get in without the code from the owner's phone. Both the root user and each IAM user can register up to eight MFA devices of any type.
Because it has full access, the IAM guide calls for using the root user only for the tasks that require it. The official list of those tasks includes, among others, closing the account, restoring IAM permissions if the only administrator removed their own, and deleting a badly written S3 bucket policy or SQS queue policy that denies access to everyone. A policy is a document with rules that says who can do what. Everything else, such as creating users, launching instances (virtual servers in Amazon EC2) or viewing the bill, is done with another identity. For example, the store's owner keeps the root password locked away with its MFA and signs in every day with their own IAM user, which has only the permissions they use.
True or false?
0 of 3To launch EC2 instances in production it is better to sign in as the root user, because it has every permission.
If a bucket policy denies access to everyone, the root user can delete it.
The root user can have up to eight registered MFA devices.
IAM user or role?
An IAM user represents a person or an application and can have long-term credentials, which are a console password and access keys. Neither of them expires on its own: the keys last until someone deletes them, and the password only expires if a password policy requires it. An IAM group, for its part, is a set of users who get the same permissions, such as the store's support group.
A role, on the other hand, has no password or keys. It is a set of permissions that a person or a service borrows for a while, and taking it is called assuming the role. Whoever assumes it receives temporary credentials from AWS Security Token Service (AWS STS), the service that hands out those credentials, and those credentials expire on their own. For example, the program that charges for the store's orders assumes a role that lets it read the orders database; if someone steals those credentials, they expire in a few hours and the thief would have to request them again, which they can't do.
The first two best practices in the IAM guide apply that difference, one to people and the other to applications:
- People, who sign in with federation from an identity provider and receive temporary credentials. An identity provider is the system where the company already keeps its employees' accounts, and federation means letting AWS trust it. For example, the store's employees sign in to AWS with the same user as their work email, and when one leaves the company it is enough to remove them in a single place.
- Workloads, which are the programs that run on their own, such as the site or a nightly process, and which use IAM roles and temporary credentials. For example, the process that adds up the day's sales every night assumes a role instead of using an employee's keys.
The guide's list goes on with other practices, which come up throughout this step: MFA, updating access keys when a use case really needs long-term credentials, protecting the root user, least privilege, IAM Access Analyzer, removing what isn't used, conditions in policies, guardrails across accounts and permissions boundaries for delegating.
How long do a role's credentials last?
Whoever assumes a role with the AssumeRole call, which is the request to AWS STS to receive the credentials, can request a duration from 900 seconds (15 minutes) up to the maximum configured on the role, and that maximum is set between 1 and 12 hours. The time those credentials last is called a session. For example, if the store's support role has a maximum of four hours, a support person can request a session of one hour or of four hours, but not of five.
This rule has one exception, role chaining, which is using a role's credentials to assume another role. In that case the session is limited to one hour, and if you request more the call fails. For example, if one of the store's scripts is already working with the support role and from there assumes the billing role, that second session lasts one hour at most.
How long does the session last?
A role is configured with a maximum duration of 8 hours. A script assumes that role using the credentials of another role and requests 6 hours. What happens?
An application on EC2 without keys
An application on EC2 that calls another AWS service gets its credentials from a role, without anyone writing a key in the code or in a file. To do that, the role is assigned to the instance inside an instance profile, which is the container EC2 uses to attach a role to an instance. For example, the store's site runs on an instance and saves the product photos in S3: with an instance profile, the site's code doesn't have any key written in it.

EC2 gets temporary credentials from the role and places them in the instance metadata, where the AWS SDK finds them without you doing anything. An instance carries a single role at a time, and if you change that role's policy, the change reaches every instance that uses it.
Outside EC2 the mechanism is the same, with other names. A Lambda function uses its execution role and an ECS task uses its task role. A server outside AWS can use IAM Roles Anywhere, which gives temporary credentials to workloads that present an X.509 certificate from your certificate authority, which is the system that signs those certificates. For example, the inventory server the store keeps in its own warehouse uses Roles Anywhere to read from AWS without storing keys. Finally, a CI/CD system such as GitHub Actions uses OIDC federation, which exchanges the token its provider gives it for a role's credentials.
Where does it get credentials?
0 of 4 pairsTap the workload and then how it gets temporary credentials.
0 of 4 pairs.
In a new experience account
In a new experience account there is no root user, because the owner of the projects is your AWS Builder ID. You can create IAM users and roles, but only with programmatic access, that is, for programs that use keys and not for people who sign in to the console with a password. The reason is the SCP that AWS places on the account, a rule that limits what can be done in it and that denies creating groups, console passwords and SAML or OIDC identity providers.
Roles for EC2 and Lambda work the same as in a full account. If a bucket policy denies access to everyone, the project owner deletes it from IAM, in "Root access management". For example, to practice the store's case in that account you can create the site's role and assign it to an instance, but you can't give an employee a console password.
How does it show up on the exam?
Questions on this topic usually describe where some credentials are stored or who needs to get in, and these phrases in the question point to the answer:
| If the question says | The answer |
|---|---|
| "Access keys stored on the instance" or "in a configuration file" | The option that keeps them is wrong, and the right one uses a role |
| "Employees with their corporate user" | Federation, usually with IAM Identity Center |
| "Credentials that expire on their own" | AWS STS |
| "Which task requires the root user" | Closing the account, restoring IAM permissions or deleting a bucket policy that denies everyone |
For example, if the question says the store saved a user's keys in a file on its server, the right answer removes that file and gives the instance a profile with a role.
Review question
An application runs on EC2 instances that an Auto Scaling group creates and deletes based on traffic, and it needs to write to a DynamoDB table, an AWS database. The team proposes creating an IAM user, storing its keys encrypted in Parameter Store, an AWS service for storing configuration, and changing them every month. What does an architect recommend?
Next
- The Security best practices in IAM, in the AWS documentation.
- The Solutions Architect practice exams at /examenes.