Sub topic 7
Your duties for identity and access
This chapter covers the identity and access duties that fall to you under the shared responsibility model. It assumes you know the basics of IAM (users, roles, policies), can read a short AWS CLI command, and understand least privilege. Earlier chapters drew the line between security of the cloud and security in the cloud. Here we look at the part of that line that is most often misdrawn: who can do what in your account.
Where the line falls for identity
AWS runs the IAM service. It operates the authentication endpoints, keeps the policy evaluation engine correct and available, and protects the systems that store credentials and policy documents. That is security of the cloud.
Everything you put into IAM is yours. That includes:
- Which principals exist (users, roles, federated identities).
- Which policies are attached to them.
- How credentials are issued, stored, rotated, and removed.
- Whether multi-factor authentication (MFA) is required.
- Who can reach the root user, and how it is protected.
AWS will faithfully enforce a policy that grants "Action": "*" on "Resource": "*". It does not judge whether that was a good idea. The service works as designed, and the exposure is still your responsibility.
The shape of identity in an account
Every request to AWS is made by a principal, authenticated, and then authorized by evaluating policies. Your duties map onto those stages.
AWS operates the machinery in the boxes labeled AWS. You supply the inputs the machinery acts on.
The root user
Each account has a root user with unrestricted access that policies cannot limit. Protecting it is a customer duty.
- Enable MFA on the root user, preferably with a hardware or passkey device.
- Do not create access keys for root. If any exist, delete them.
- Use root only for the few tasks that require it, such as changing the account's support plan or closing the account.
- Use a monitored shared mailbox for the root email address, so account recovery does not depend on one person.
In an AWS Organizations setup, you can also centralize root access management for member accounts, so that member accounts do not need long-lived root credentials at all.
Human access: prefer federation
Long-lived IAM user passwords and access keys are the weakest form of human access, because they can leak and are easy to forget. The usual recommendation is to federate human users from a central identity provider and give them temporary credentials.
AWS IAM Identity Center is the common way to do this. You connect it to your identity provider or use its built-in directory, define permission sets, and assign them to groups for each account. Users sign in and receive short-lived credentials.
What stays with you:
- The joiner, mover, leaver process. If someone leaves the company and your identity provider still lists them, AWS has no way to know.
- Group membership. Adding a user to an "Admins" group is an authorization decision that you make.
- MFA enforcement at the identity provider or in Identity Center.
Workload access: roles, not keys
Code running on AWS should get credentials from a role, not from a key pair pasted into a config file.
| Workload | Preferred credential source | Avoid |
|---|---|---|
| EC2 instance | Instance profile with an IAM role | Access keys in user data or on disk |
| Lambda function | Execution role | Environment variables holding keys |
| ECS task | Task role | Keys baked into the image |
| CI/CD pipeline | OIDC federation to a role | Stored IAM user keys |
| On-premises server | IAM Roles Anywhere | Long-lived keys on the host |
Roles give temporary credentials that AWS rotates for you. That rotation is a feature AWS provides. Choosing to use roles is your decision, and so is scoping what each role may do.
A trust policy on a role controls who can assume it. Treat trust policies with the same care as permission policies. A role that trusts "Principal": {"AWS": "*"} without conditions lets any AWS principal try to assume it.
Writing policies: least privilege in practice
Least privilege is a customer duty at every layer. In practice you work through several policy types.
| Policy type | Attached to | Effect |
|---|---|---|
| Identity-based | User, group, or role | Grants permissions to that principal |
| Resource-based | Resource such as a bucket or key | Grants access to listed principals, including other accounts |
| Permissions boundary | User or role | Sets the maximum permissions the identity can have |
| Service control policy (SCP) | Organization, OU, or account | Sets the maximum permissions for accounts in scope |
| Session policy | A role session | Further narrows one session's permissions |
Two points trip people up. First, an explicit Deny always wins. Second, boundaries and SCPs never grant anything. They only cap what other policies can grant.
Here is a policy that allows read access to one prefix in one bucket, and only over TLS:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ReadReportsPrefix",
"Effect": "Allow",
"Action": ["s3:GetObject"],
"Resource": "arn:aws:s3:::amzn-s3-demo-bucket/reports/*",
"Condition": {
"Bool": { "aws:SecureTransport": "true" }
}
},
{
"Sid": "ListReportsPrefix",
"Effect": "Allow",
"Action": ["s3:ListBucket"],
"Resource": "arn:aws:s3:::amzn-s3-demo-bucket",
"Condition": {
"StringLike": { "s3:prefix": ["reports/*"] }
}
}
]
}Note that s3:ListBucket applies to the bucket ARN, while s3:GetObject applies to object ARNs. Mixing those up is a common reason a policy "does not work", and the usual fix, widening to *, quietly breaks least privilege.
Finding the right permissions
Starting from a broad policy and narrowing it is safer than guessing blindly, if you follow through. Use these tools:
- IAM Access Analyzer can generate a policy from the CloudTrail activity of a role.
- Access Advisor, in the IAM console, shows the last time each service was used by a principal.
- The IAM policy simulator lets you test whether a principal can perform an action before you deploy.
Remove permissions that go unused for a period you define, and record that period in your standards.
Credential hygiene
If you do keep IAM users with access keys, you own the lifecycle.
- Give each key one owner and one purpose.
- Limit to two keys per user, which is the AWS maximum, and use the second only during rotation.
- Rotate on a schedule and delete keys you do not use.
- Never commit keys to source control. Scan repositories for them.
The credential report lists every user and the age and last use of their password and keys. You can generate and read it with the CLI:
aws iam generate-credential-report
aws iam get-credential-report \
--query Content --output text | base64 --decodeThe output is CSV. Look for users with password_enabled true and mfa_active false, and for keys where access_key_1_last_used_date is old or N/A.
To see which access keys exist for a single user and when each was last used:
aws iam list-access-keys --user-name example-user
aws iam get-access-key-last-used --access-key-id AKIAIOSFODNN7EXAMPLECross-account and public access
Resource-based policies can grant access to principals in other accounts, or to everyone. AWS will honor those grants. Reviewing them is your job.
IAM Access Analyzer's external access findings list resources shared outside your zone of trust, which you define as an account or an organization. Each finding names the resource, the principal, and the action. You then decide whether the access is intended, archive the finding if so, and fix the policy if not.
Use condition keys to narrow grants. For example, aws:PrincipalOrgID restricts access to principals in your organization, which is easier to maintain than listing account IDs.
Guardrails with Organizations
In a multi-account setup, SCPs enforce rules that no individual administrator can override inside a member account. Common guardrails include denying the disabling of CloudTrail, denying leaving the organization, and restricting Regions you do not use.
SCPs do not affect the management account, and they do not grant permissions. Test them in a non-production organizational unit first, because a wrong SCP can lock out an entire account.
Common mistakes
- Attaching
AdministratorAccessto a role "temporarily" and never removing it. - Using wildcards in
ActionorResourcewhen the real set is small. - Leaving trust policies open to broad principals.
- Skipping MFA for console users who have permissions to change IAM.
- Forgetting that a role's permissions apply to everything that can assume it, including a compromised instance. An EC2 role is only as safe as the instance.
- Assuming AWS will warn you. Access Analyzer and Config can flag issues, but only if you enable them and read the results.
Summary of ownership
| Control | AWS | You |
|---|---|---|
| IAM service availability and correctness | Yes | No |
| Authentication endpoints and policy engine | Yes | No |
| Root user protection and MFA | No | Yes |
| User, role, and group design | No | Yes |
| Policies, boundaries, and SCPs | No | Yes |
| Credential rotation and removal | Provides tools | Yes |
| Federation and joiner/leaver process | Provides tools | Yes |
| Review of external access | Provides Access Analyzer | Yes |
Exercise
A developer reports that an IAM policy allowing s3:GetObject on arn:aws:s3:::amzn-s3-demo-bucket/reports/ works, but listing the bucket with the CLI fails with AccessDenied. A colleague suggests changing the Resource to "". What is the cause, and what is a least-privilege fix?
Show answer
s3:GetObject is checked against object ARNs, but s3:ListBucket is checked against the bucket ARN (arn:aws:s3:::amzn-s3-demo-bucket), which the policy does not cover. Add a separate statement allowing s3:ListBucket on the bucket ARN, optionally with a condition such as s3:prefix set to reports/. Do not widen Resource to "".
Exercise
Your organization has an SCP that allows only the ec2 and s3 services. A role in a member account has an identity policy allowing dynamodb:GetItem. Can the role read from DynamoDB, and why?
Show answer
No. An SCP sets the maximum permissions for accounts in scope and does not grant any. Because dynamodb is not allowed by the SCP, the identity policy's allow has no effect. Access requires both the SCP and the identity policy to allow the action.
Exercise
Name two reasons a CI/CD pipeline should use OIDC federation to a role instead of a stored IAM user access key, and name one duty that remains yours either way.
Show answer
Federation issues short-lived credentials that expire on their own, and there is no long-lived secret to leak from the pipeline's settings or logs. It also lets you scope the role's trust policy to a specific repository or branch. Either way, you remain responsible for scoping the role's permissions to least privilege.