DEV Community

Sushant Gaurav
Sushant Gaurav

Posted on

Interview Questions on AWS Identity and Access Management (IAM)

1. What is AWS IAM, and why is it important?

Answer:

AWS IAM is a web service that allows you to securely control access to AWS services and resources for your users. It provides features like user management, roles, policies, and multi-factor authentication (MFA).

Example Explanation:

If you have a team working on an AWS project, IAM ensures that developers can only access specific resources like EC2 or S3 while restricting access to billing information.

2. What are IAM users, groups, and roles?

Answer:

  1. IAM Users: Individual accounts created for people or applications. Each user has credentials like a password or access key.
  2. IAM Groups: A collection of IAM users. Permissions assigned to a group apply to all its members.
  3. IAM Roles: Temporary credentials for users or services. Roles are assumed by entities to perform specific tasks.

Example Explanation:

  • IAM User: A developer named Alice can have her own IAM user account.
  • IAM Group: Add Alice to the "Developers" group, which has permissions for EC2 and RDS.
  • IAM Role: Create a role for an EC2 instance to access S3 buckets without embedding credentials in the instance.

3. What are IAM Policies, and how are they structured?

Answer:

IAM policies are JSON documents that define permissions for an IAM identity (user, group, or role). Policies contain statements with the following elements:

  • Effect: Allow or Deny.
  • Action: Specific AWS actions (e.g., s3:ListBucket).
  • Resource: AWS resource ARN (e.g., arn:aws:s3:::example-bucket).

Example Policy:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "s3:ListBucket",
      "Resource": "arn:aws:s3:::example-bucket"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Example Explanation:

This policy allows listing objects in the S3 bucket example-bucket. You might attach this policy to an IAM user managing the bucket.

4. What is the difference between an Inline Policy and a Managed Policy?

Answer:

  • Inline Policy: Directly embedded in a user, group, or role.
  • Managed Policy: Standalone policy that can be attached to multiple IAM entities.

Example Explanation:

Use a managed policy like AmazonS3FullAccess for all developers working with S3. For a specific user requiring unique permissions, add an inline policy tailored to their needs.

5. What is AWS STS, and how does it work with IAM?

Answer:

AWS Security Token Service (STS) provides temporary, limited-privilege credentials for IAM roles or federated users. It’s commonly used for cross-account access or federated login.

Example Explanation:

If you have two AWS accounts (A and B), and a user in Account A needs to access resources in Account B, they assume a role in Account B using STS.

6. How do you implement multi-factor authentication (MFA) in IAM?

Answer:

MFA adds a layer of security by requiring a second authentication factor (e.g., a one-time code from a mobile app). To enable MFA:

  1. Attach an MFA device to the IAM user.
  2. Configure MFA settings via the AWS Management Console or CLI.

Example Explanation:

If your root account is compromised, MFA ensures attackers cannot access your AWS resources without the additional one-time code.

7. What is the principle of least privilege in IAM?

Answer:

The principle of least privilege means granting only the permissions necessary to perform a specific task. This reduces the risk of accidental or malicious access to resources.

Example Explanation:

If a user needs to upload files to S3, grant them s3:PutObject permission rather than s3:*, which includes unnecessary actions like deleting buckets.

8. How do you ensure secure access to AWS resources from an EC2 instance?

Answer:

The recommended way is to use IAM roles attached to the EC2 instance. This avoids embedding access keys in the code.

Example Explanation:

If an EC2 instance needs to read data from DynamoDB, attach an IAM role with the policy:

{
  "Effect": "Allow",
  "Action": "dynamodb:GetItem",
  "Resource": "arn:aws:dynamodb:region:account-id:table/example-table"
}
Enter fullscreen mode Exit fullscreen mode

9. What is the difference between IAM roles and service-linked roles?

Answer:

  • IAM Roles: General-purpose roles for AWS services or applications.
  • Service-Linked Roles: Predefined roles directly managed by AWS services for specific use cases.

Example Explanation: To enable AWS Auto Scaling, use its service-linked role (AWSServiceRoleForAutoScaling) without needing to manually configure permissions.

10. How do you audit and monitor IAM activity?

Answer:

  1. Use AWS CloudTrail to log all API activities related to IAM.
  2. Analyze IAM Access Advisor to identify unused permissions.
  3. Review AWS IAM Credential Reports for user security posture.

Example Explanation:

If you notice an unused access key in the Credential Report, you can disable or delete it to improve security.

11. Can IAM policies deny access explicitly, even if there is an allow?

Answer:

Yes, explicit deny in IAM policies always overrides allows.

Example Explanation:

If a group policy allows S3 access, but an inline policy for a user in that group explicitly denies it, the user cannot access S3.

12. What is a resource-based policy, and how does it differ from identity-based policies?

Answer:

  • Resource-Based Policy: Attached directly to a resource (e.g., an S3 bucket).
  • Identity-Based Policy: Attached to a user, group, or role.

Example Explanation:

To share an S3 bucket across accounts, you attach a resource-based policy to the bucket allowing specific actions for a role in another account.

13. How do you restrict access to a specific IP address using IAM?

Answer:

Use a condition in the policy with the aws:SourceIp key.

Example Policy:

{
  "Effect": "Allow",
  "Action": "s3:*",
  "Resource": "arn:aws:s3:::example-bucket/*",
  "Condition": {
    "IpAddress": {
      "aws:SourceIp": "192.168.1.1/32"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Example Explanation:

This policy allows access to the S3 bucket only from the IP address 192.168.1.1.

14. How do you manage cross-account access with IAM?

Answer:

  1. Create a role in Account A with permissions for the desired resources.
  2. Add a trust policy to allow Account B to assume the role.
  3. Use AWS STS to assume the role from Account B.

Example Explanation:

For developers in Account B to access an S3 bucket in Account A, create a trust policy allowing sts:AssumeRole from Account B.

15. What is AWS Organizations, and how does it enhance IAM?

Answer:

AWS Organizations is a service for managing multiple AWS accounts. It allows centralized access control, billing, and policy enforcement across accounts using Service Control Policies (SCPs).

Example Explanation:

If you want to restrict all accounts in your organization from creating IAM users, enforce an SCP with the following:

{
  "Effect": "Deny",
  "Action": "iam:CreateUser",
  "Resource": "*"
}
Enter fullscreen mode Exit fullscreen mode

Conclusion

These comprehensive IAM interview questions, with detailed examples, will help you confidently approach interviews. The next article will cover AWS Networking: VPC, Subnets, and Security Group Interview Questions with real-world scenarios.

Top comments (1)

Collapse
 
lindiwe09 profile image
Lindiwe

Thank you for this comprehensive article on AWS IAM! Looking forward to exploring more of your content!