0%
AWS Solutions Architect Associate (SAA-C03) Exam Prep: Secure, Resilient, High-Performing and Cost-Optimized Architectures
Domain 2: Design Resilient Architectures
Domain 3: Design High-Performing Architectures
Domain 4: Design Cost-Optimized Architectures
Final Review and Mock Exams
IAM Policies and How a Request Is Evaluated
Every request to AWS, whether it comes from the console, the command line, an SDK or another service, is checked by AWS Identity and Access Management before it is allowed to proceed. IAM decides whether a particular principal may perform a particular action on a particular resource under the current conditions. The exam tests this decision more than any other single topic in the security domain, because almost every secure design depends on getting permissions right. This lesson builds the model you need to answer those questions quickly. For a deeper engineering treatment, see IAM policy evaluation in the AWS in Practice course.
Principals
A principal is something that can make a request. There are a few kinds. The root user of an account is created with the account and has complete access to it. IAM users are long lived identities with a password, access keys or both. IAM roles are identities that are assumed for a period and give temporary credentials. Federated users are people who sign in through an external identity provider and receive role credentials. AWS services can also act as principals, for example when S3 delivers an event to a Lambda function or when CloudTrail writes logs to a bucket.
IAM groups are not principals. A group is a collection of users that lets you attach the same policies to many users at once. You cannot name a group in the principal element of a policy, and groups cannot contain other groups. This is a small detail that appears in questions surprisingly often: an option that grants access to a group in a bucket policy is wrong because a bucket policy cannot name a group.
The root user
The root user should be used for almost nothing. Its credentials cannot be limited by IAM policies in its own account. Best practice, and the answer to many exam questions, is to enable multi-factor authentication on the root user, never create access keys for it, store its credentials securely and use it only for the handful of tasks that require it, such as changing the account's support plan, closing the account or restoring IAM permissions if an administrator locks everyone out. Day to day administration belongs to IAM roles or users with appropriate permissions. In an organization, service control policies can restrict the root user of member accounts, which is one of the reasons organizations are used.
Policies are JSON documents
A policy is a JSON document containing one or more statements. Each statement has an Effect, which is either Allow or Deny; an Action, which lists API operations such as s3:GetObject or ec2:StartInstances; a Resource, which lists the Amazon Resource Names the statement applies to; and optionally a Condition, which restricts when the statement applies. Resource based policies also include a Principal element that names who the statement applies to, because the policy is attached to the resource rather than to the caller.
Actions and resources can use wildcards. s3:Get* matches every action that starts with Get. A resource of arn:aws:s3:::reports/* matches every object in the reports bucket, while arn:aws:s3:::reports matches the bucket itself. That difference matters: listing a bucket is an action on the bucket, while reading an object is an action on the object, so a policy that allows s3:ListBucket on the object ARN does nothing useful. Exam options sometimes contain exactly that mistake.
There are also negated elements. NotAction matches every action except those listed, and NotResource matches every resource except those listed. They are useful for broad denies, such as deny every action except those needed to manage your own MFA device until MFA is present, but they are easy to misuse with Allow, because allowing everything except a few actions grants far more than most people intend.
Identity based policies
Identity based policies are attached to users, groups or roles and say what that identity may do. There are three kinds. AWS managed policies are written and maintained by AWS, such as ReadOnlyAccess or AmazonS3ReadOnlyAccess. They are convenient but often broader than least privilege requires. Customer managed policies are written by you, stored as standalone objects and attached to any number of identities; they are versioned, so you can roll back a change. Inline policies are embedded in a single identity and deleted with it. They are useful for a strict one to one relationship but harder to manage at scale. When an exam question asks how to reuse the same permissions across many roles with central control, the answer is a customer managed policy.
Resource based policies
Resource based policies are attached to a resource and say who may access it. S3 bucket policies, SQS queue policies, SNS topic policies, KMS key policies, Lambda function policies, Secrets Manager secret policies and the trust policy on an IAM role are all resource based policies. Because they name a principal, they can grant access to principals in other accounts, which identity based policies cannot do on their own. They are the standard way to share a resource across accounts without asking the other account to assume a role.
The trust policy on a role deserves special mention. It is the resource based policy that says who may assume the role. A role has both a trust policy, which controls who can become the role, and permissions policies, which control what the role can do once assumed. Questions about cross-account roles often hinge on which of the two needs changing.
Access control lists
S3 also supports access control lists on buckets and objects, an older mechanism that predates bucket policies. For new buckets, ACLs are disabled by default through the bucket owner enforced setting for object ownership, which makes the bucket owner own every object and relies on policies alone. On the exam, if an option suggests using ACLs to solve a modern access problem, it is usually a distractor; policies are the preferred tool.
Least privilege
The guiding principle for every policy is least privilege: grant only the actions needed, on only the resources needed, under only the conditions needed. In practice, that means starting from a narrow policy and widening it when something legitimate fails, not starting from a broad one and hoping to narrow it later. Several AWS tools help, which this lesson covers at the end: last accessed information, IAM Access Analyzer policy generation and unused access findings.
Users versus roles
Exam questions strongly prefer roles over IAM users with long lived access keys. Applications on EC2 should use an instance profile with a role. Lambda functions use an execution role. Containers on ECS use a task role. People should sign in through IAM Identity Center or a federated identity provider and receive role credentials. Long lived access keys are acceptable only where nothing else works, such as some third party tools outside AWS, and even then they should be rotated and scoped tightly. An option that creates an IAM user with access keys for an application running on AWS is almost always wrong.
Service-linked roles and service roles
Two kinds of role are created for AWS services rather than for people. A service role is a role you create that a service assumes to act on your behalf, such as the role CodeBuild uses to fetch source code. You control its trust and permissions policies. A service-linked role is predefined by the service, linked to it and created automatically when you start using certain features, such as Auto Scaling or Elastic Load Balancing. You cannot edit its permissions, and service control policies do not restrict it. If an exam option suggests editing a service-linked role to grant extra access, it is wrong; you change your own policies or the service configuration instead.
Policy size and organisation
Policies have size limits, so very large policies listing hundreds of resources are a warning sign. Wildcards on well designed resource names, such as prefixing every resource for a team with the team name, keep policies short. Tags and attribute based access, covered later in this lesson, keep them shorter still.
Two habits keep policies readable: give each statement a Sid that describes its purpose, and group related actions in one statement rather than scattering them.
You cannot name an IAM group in the Principal element of a bucket policy or any other resource based policy. Grant access to roles or users, or attach an identity policy to the group instead.