IAM (Identity and Access Management)


  • IAM ์ด๋ž€ AWS Resources ์ ‘๊ทผ ๊ถŒํ•œ์„ ๊ด€๋ฆฌํ•˜๋Š” Global Service
  • Root Account ๋Š” AWS ๊ณ„์ • ์ƒ์„ฑ ์‹œ์— ๊ธฐ๋ณธ์œผ๋กœ ์ƒ์„ฑ๋˜๊ณ  AWS ๊ณ„์ • ์ƒ์„ฑ์—๋งŒ ์‚ฌ์šฉ

IAM Users & User Groups


  • User ๋Š” ํ•˜๋‚˜์˜ ์กฐ์ง ๋‚ด ์‚ฌ์šฉ์ž์— ํ•ด๋‹นํ•˜๋ฉฐ ํ•„์š”ํ•˜๋‹ค๋ฉด Group ์œผ๋กœ ๋ฌถ์„ ์ˆ˜ ์žˆ์Œ
    • User ๋Š” 0~10๊ฐœ์˜ Group ์— ์†ํ•  ์ˆ˜ ์žˆ์Œ
  • Group ์€ User ๋งŒ์„ ํฌํ•จํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ Group ์„ ํฌํ•จํ•˜๋Š” ๊ฒƒ์€ ๋ถˆ๊ฐ€๋Šฅ
  • ์ตœ์†Œ ๊ถŒํ•œ ์›์น™์„ ๋ฐ”ํƒ•์œผ๋กœ AWS ๋ฅผ ์‚ฌ์šฉํ•˜๊ฒŒ๋” ํ•˜๊ธฐ ์œ„ํ•ด์„œ IAM User ์™€ Group ์„ ์‚ฌ์šฉ
  • User ๋˜๋Š” Group ์€ JSON ํ˜•์‹์œผ๋กœ ์ด๋ฃจ์–ด์ง„ IAM Policy ๋ฅผ ํ• ๋‹น ๋ฐ›์„ ์ˆ˜ ์žˆ์Œ

IAM User ์ƒ์„ฑ

  • AWS Management Console ์—์„œ IAM โ†’ Users โ†’ Create user

  • Provide user access to the AWS Management Console ํ™œ์„ฑํ™”๋ฅผ ํ†ตํ•ด User ์—๊ฒŒ AWS Management Console ์ด์šฉ ๊ถŒํ•œ ๋ถ€์—ฌ
  • Console password ๋ฅผ Custom password ๋กœ ์„ค์ •ํ•ด์„œ User ์ƒ์„ฑ
    • ํƒ€์ธ์„ ์œ„ํ•œ IAM User ์ƒ์„ฑ ์‹œ Autogenerated password + User must create a new password at next sign-in ์œผ๋กœ ๋น„๋ฐ€๋ฒˆํ˜ธ ์žฌ์„ค์ • ์˜๋ฌดํ™”

  • Create group ์œผ๋กœ User ๊ฐ€ ์†ํ•  Group ์„ ๋งŒ๋“ค๋ฉด์„œ ๋™์‹œ์— Permission policies ๊นŒ์ง€ ํ• ๋‹น

  • ๋งˆ์ง€๋ง‰ Review ํ›„ Create user ํด๋ฆญ ์‹œ User ์ƒ์„ฑ ์™„๋ฃŒ

  • Users ๋กœ ๋‹ค์‹œ ๋Œ์•„์™€๋ณด๋ฉด User ๊ฐ€ ์„ฑ๊ณต์ ์œผ๋กœ ์ƒ์„ฑ๋˜์–ด์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธ ๊ฐ€๋Šฅ

IAM User Access Key for AWS CLI

  • AWS Management Console ์—์„œ IAM โ†’ Users โ†’ User ์„ ํƒ โ†’ Security credentials ํƒญ โ†’ Access keys ์—์„œ Create access key

  • CLI ์„ ํƒํ›„ ๋งˆ์ง€๋ง‰ ํ™”๋ฉด์ด Access Key ์™€ Secret Access Key ๋ฅผ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋Š” ์œ ์ผํ•œ ์‹œ๊ฐ„
$ aws configure
AWS Access Key ID [None]: ACCESS_KEY
AWS Secret Access Key [None]: SECRET_ACCESS_KEY
Default region name [None]: ap-east-1
Default output format [None]:
  • aws configure ๋ช…๋ น์–ด ์ž…๋ ฅ ํ›„ ์œ„์™€ ๊ฐ™์ด ์„ค์ •ํ•˜๋ฉด CLI ๋กœ AWS API ๋ฅผ ์‚ฌ์šฉ ๊ฐ€๋Šฅ
  • ๋‹จ, EC2 ์ธ์Šคํ„ด์Šค์™€ ๊ฐ™์ด ํƒ€์ธ์ด ์ ‘์†ํ•  ์ˆ˜ ์žˆ๋Š” ๋จธ์‹ ์—์„œ ์ด ๋ฐฉ๋ฒ•์„ ์“ฐ๋ฉด ํƒ€์ธ์ด ์ธ์Šคํ„ด์Šค์— ์ž…๋ ฅ๋œ ์ž๊ฒฉ ์ฆ๋ช… ์ •๋ณด๋ฅผ ํšŒ์ˆ˜ํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— best practice ๊ฐ€ ์•„๋‹˜
  • ๋”ฐ๋ผ์„œ EC2 ์—์„œ AWS API ๋ฅผ ์‚ฌ์šฉํ•˜๊ธธ ์›ํ•  ๊ฒฝ์šฐ IAM Role ์„ ์ง€์ •ํ•˜๋Š”๊ฒŒ best practice

IAM Policies


  • IAM Policy is a JSON document that allows or denies permissions to AWS resources
    • Follow the security principle of least privilege when granting permissions
    • IAM Policy can be assigned to User Groups or User itself with inline-policy

IAM Policies Structure

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "iam:GenerateCredentialReport",
                "iam:GenerateServiceLastAccessedDetails",
                "iam:Get*",
                "iam:List*",
                "iam:SimulateCustomPolicy",
                "iam:SimulatePrincipalPolicy"
            ],
            "Resource": "*"
        }
    ]
}
  • Version: Policy language version, mostly โ€œ2012-10-17โ€
  • Id: Identifier for the policy (Optional)
  • Statement: One or more individual statements
    • Sid: Identifier for the statement (Optional)
    • Effect: Allow or Deny
    • Principal: Account/User/Role to which this policy applied to
    • Action: List of actions this policy allows or denies
    • Resource: List of resources to which the action applied to
    • Condition: Conditions for when this policy is in effect (Optional)

IAM Policies ์ข…๋ฅ˜

  • Identity-based policies: IAM Users, IAM User Groups, IAM Roles ์— ์ ์šฉํ•˜๋Š” Policy
    • AWS Managed Policy: AWS ์—์„œ ๊ธฐ๋ณธ์œผ๋กœ ์ œ๊ณตํ•˜๋Š” Policy, ์—ฌ๋Ÿฌ ๊ณ„์ •์—์„œ ๋™์ผํ•œ Policy ์‚ฌ์šฉ ๊ฐ€๋Šฅ
    • AWS Customer Managed Policy: ์‚ฌ์šฉ์ž๊ฐ€ ์ƒ์„ฑํ•œ Custom Policy, ํ•ด๋‹น Policy ๊ฐ€ ์ƒ์„ฑ๋œ ๊ณ„์ •๋งŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅ
    • AWS Inline Policy: ๋ช…์‹œ์ ์œผ๋กœ ํ• ๋‹นํ•˜๋Š” 1๋Œ€1 Policy, ๋ณดํ†ต Managed ๋ฅผ ์‚ฌ์šฉํ•˜๊ธธ ๊ถŒ์žฅ, ๋ช…์‹œ์ ์œผ๋กœ ํŠน์ • ์‚ฌ์šฉ์ž์—๊ฒŒ ํŠน์ • ๊ถŒํ•œ์„ ๋ถ€์—ฌํ•˜๊ณ  ์‹ถ์„ ๊ฒฝ์šฐ์— ์‚ฌ์šฉํ•˜๋ฉด ์œ ์šฉ
  • Resource-based policies: AWS Resource ์— ์ ์šฉํ•˜๋Š” Policy, ๋Œ€ํ‘œ์ ์œผ๋กœ S3 Bucket Policy ๊ฐ€ ์žˆ์Œ
  • Permissions boundaries
  • Organizations SCPs
  • Access control lists - ACLs
  • Session policies

IAM Roles


  • IAM Role ์€ AWS Services ๋ฅผ ์œ„ํ•œ IAM User ๋ผ๊ณ  ์ƒ๊ฐํ•  ์ˆ˜ ์žˆ์Œ
  • An identity that you can assume to gain temporary access to permissions
  • Ideal for situations in which access to services or resources needs to be granted temporarily, instead of long-term
  • To grant users in one AWS account access to resources in another AWS account
  • IAM Users ์˜ ๊ถŒํ•œ์„ ์‰ฝ๊ฒŒ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด IAM User Groups ๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๋ฐ, ๊ถŒํ•œ์ด ๋‹ค์–‘ํ•ด์ง€๋ฉด ๊ด€๋ฆฌ๊ฐ€ ๋ณต์žกํ•ด์ง€๊ณ  ์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด IAM Roles ๋ฅผ ์‚ฌ์šฉ
  • User Group ์— ๊ถŒํ•œ์„ ๋ฐ”๋กœ ๋ถ€์—ฌํ•˜๋Š” ๋Œ€์‹ , Role ์„ ๋งŒ๋“ค๊ณ  User ๋˜๋Š” User Group ์— ํ• ๋‹น
    • ์ž„์‹œ ์„ธ์…˜ํ† ํฐ์„ ๋ฐœ๊ธ‰ํ•˜์—ฌ ์ผ์‹œ์ ์ธ ๊ถŒํ•œ์„ ์œ„์ž„

IAM Security Tools


IAM Credential Reports (account-level)

  • AWS Management Console ์—์„œ IAM โ†’ Credential report โ†’ Download Report
  • A report that lists all accountโ€™s users and the status of their various credentials

IAM Access Advisor (user-level)

  • AWS Management Console ์—์„œ IAM โ†’ Users โ†’ User ์„ ํƒ โ†’ Access Advisor ํƒญ
  • ์–ด๋–ค AWS Services ์— ๋งˆ์ง€๋ง‰์œผ๋กœ ์ ‘๊ทผํ–ˆ๋Š”์ง€ ํ™•์ธ ๊ฐ€๋Šฅ
    • ์ ‘๊ทผํ•˜์ง€ ์•Š๋Š” Resources ๋Š” ์ œํ•œํ•˜์—ฌ principle of least privilege ๋ฅผ ์ง€ํ‚ฌ ์ˆ˜ ์žˆ์Œ

IAM ๊ถŒํ•œ ๊ฒ€์ฆ ์ ˆ์ฐจ


IAM User ๊ฐ€ S3 ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ

  1. IAM User ์—๊ฒŒ S3 ์‚ฌ์šฉ Policy ๊ฐ€ ๋ถ€์—ฌ๋˜์—ˆ๋Š”๊ฐ€?
  2. IAM User ๊ฐ€ ์†ํ•œ IAM User Group ์— S3 ์‚ฌ์šฉ Policy ๊ฐ€ ๋ถ€์—ฌ๋˜์—ˆ๋Š”๊ฐ€?
  3. IAM User ์—๊ฒŒ ์œ„์ž„๋œ Role ์— S3 ์‚ฌ์šฉ Policy ๊ฐ€ ๋ถ€์—ฌ๋˜์—ˆ๋Š”๊ฐ€?
  4. OK ๋˜๋Š” Fail

Lambda ๊ฐ€ S3 ๋ฅผ ์ด์šฉํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ

  1. Lambda ์— S3 ์‚ฌ์šฉ Role ์ด ๋ถ€์—ฌ๋˜์—ˆ๋Š”๊ฐ€?
  2. OK ๋˜๋Š” Fail
  • IAM Access Analyzer
    • Identifies whether an Amazon S3 bucket or an IAM role has been shared with an external entity such as another AWS account
    • Checks access policies and offers actionable recommendations to help users set secure and functional policies
  • IAM Credential Report
    • To audit its password and access key rotation details for compliance purposes
  • AWS Security Token Service (STS)
    • To request temporary, limited-privilege credentials for users

IAM Conditions


aws:SourceIp

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Deny",
            "Action": "*",
            "Resource": "*",
            "Condition": {
	            "NotIpAddress": {
		            "aws:SourceIp": [
			            "192.0.2.0/24",
			            "203.0.113.0/24"
		            ]
	            }
            }
        }
    ]
}
  • Restrict the client IP from which the API calls are being made

aws:RequestedRegion

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Deny",
            "Action": "*",
            "Resource": "*",
            "Condition": {
	            "StringEquals": {
		            "aws:RequestedRegion": [
			            "eu-central-1",
			            "eu-west-1"
		            ]
	            }
            }
        }
    ]
}
  • Restrict the Region the API calls are made to

ec2:ResourceTag

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "*",
            "Resource": "*",
            "Condition": {
	            "StringEquals": {
		            "aws:ResourceTag/Project": "DataAnalytics"
	            }
            }
        }
    ]
}
  • Restrict based on tags

aws:MultiFactorAuthPresent

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Deny",
            "Action": "*",
            "Resource": "*",
            "Condition": {
	            "BoolIfExists": {
		            "aws:MultiFactorAuthPresent": false
	            }
            }
        }
    ]
}
  • To force MFA

IAM for S3


  • s3:ListBucket permission applies to arn:aws:s3:::test
    • Bucket level permission
  • s3:GetObject permission applies to arn:aws:s3:::test/*
    • Object level permission

Resource Policies & aws:PrincipalOrgID


  • aws:PrincipalOrgID can be used in any resource policies to restrict access to accounts that are members of an AWS Organization

IAM Role vs Resource-Based Policies


  • In Cross-Account situation
    • Resource-Based Policy can be attached to a resource (e.g. S3 bucket policy)
    • OR use a Role as a proxy
  • When using Assume Role, original permissions will not work
  • When using Resource-Based Policy, resource allows given permissions

Amazon EventBridge - Security

  • When a rule runs, it needs permissions on the target
    • Resource-Based Policy: Lambda, SNS, SQS, CloudWatch Logs, API Gateway, โ€ฆ
    • IAM Role: Kinesis Stream, Systems Manager Run Command, ECS task, โ€ฆ

IAM Permission Boundaries


  • IAM Permission Boundaries are supported for users and roles (not group)
  • Advanced feature to use a managed policy to set the maximum permissions an IAM entity can get
  • Can be used in combinations of AWS Org SCP

References