What is the difference between an identity-based and a resource-based policy?
AWS · Basic level
Answer
Identity-based policies attach to users, groups, or roles and define what they can do. Resource-based policies attach to resources like S3 buckets, KMS keys, queues, and Lambda functions and define who can access that resource.
Technical explanation
Cross-account access often needs permission on both sides: identity policy in the caller account and resource policy or role trust in the target account.
IAM evaluation is layered: identity policies, resource policies, trust policies, boundaries, SCPs, session policies, and explicit denies all contribute to the final decision.
Prefer temporary credentials through STS, roles, IAM Identity Center, instance profiles, IRSA, or OIDC federation instead of long-lived access keys.
Use conditions, resource ARNs, tags, MFA requirements, external IDs, source account/source ARN constraints, and Access Analyzer to reduce blast radius.
Hands-on example
1. Create a least-privilege IAM role for a small workload, including trust policy, permission policy, tags, and CloudTrail visibility.
2. Test the role with aws sts get-caller-identity and one allowed action, then deliberately test one denied action.
3. Run IAM Access Analyzer or policy simulation and refine broad actions/resources before production.
4. Record the access pattern in IaC and require review for future policy changes.
Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.
More AWS interview questions
- Explain how an IAM policy is evaluated when there is both an allow and an explicit deny.
- What is the difference between an IAM role and an IAM user, and when do you use a role?
- Explain the difference between IAM users, groups, roles, and policies.
- How would you give a Kubernetes pod scoped AWS permissions (IRSA / IAM Roles for Service Accounts)?
- Explain VPC peering and its limitations (e.g., non-transitive routing).
- How does a NAT Gateway differ from a NAT instance?
- What is an Internet Gateway versus a NAT Gateway, and when do you need each?
- Are Security Groups stateful or stateless? What about NACLs?