Note_Tech

All technological notes.


Project maintained by simonangel-fong Hosted on GitHub Pages — Theme by mattgraham

AWS - Identity and Access Management (AWS IAM)

Back


IAM

User & Group

group


Security

Password Policy


Hands-on

pwd_policy


MFA

mfa


Security Tools


Hands-on

credential report

Access Advisor


Access of user


AWS CLI


Hands-on

aws configure
# AWS Access Key ID: input id
# AWS Secret Access Key [None]: input secret
# Default region name [None]: input a region, eg: us-east-1
# Default output format [None]: press enter

# to test if configureation correct, use the following command:
aws iam list-users  # list users in iam
# if success:
# {
#     "Users": [
#         {
#             "Path": "/",
#             "UserName": userName,
#             "UserId": userId,
#             "Arn": arn,
#             "CreateDate": "2023-04-30T20:12:05+00:00",
#             "PasswordLastUsed": "2023-09-10T02:19:21+00:00"
#         }
#     ]
# }

AWS SDK


IAM Policy

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "ec2:Describe*",
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": "elasticloadbalancing:Describe*",
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "cloudwatch:ListMetrics",
        "cloudwatch:GetMetricStatistics",
        "cloudwatch:Describe*"
      ],
      "Resource": "*"
    }
  ]
}

IAM Policy Evaluation Logic

iam_policy_evaluation


iam_policy_example


Policies inheritance


Policies Structure

policy_structure


Policy Conditions


Common Policy Conditions

iam_conditions_sourceip_example

Deny any action unless client calls are made from the a range IP.

  • Only API calls are made within these IP addresses.
  • Use case:
    • limit access to AWS environment only from user’s company network.

iam_conditions_requestedregion_example.png

  • Deny access if API calls are made from these regions.

  • Use case:

    • Global company want to restrict access to aws resources from some regions.

iam_conditions_tag_example.png

  • Only the PrincipalTag(user tag) ,Department, which is Data and ResourceTag, Project, which is DataAnalytics, can perform start and stop instances.
    • Restrict based on both resource and user tags

iam_conditions_mfa_example.png

  • Allow all action on all ec2 instances.
  • Deny stop and terminate actions if has not MFA.

iam_condition_awsPrincipalOrgID

  • S3 object operation are limited to the member within an organization.

Example: IAM policy for S3

iam_s3

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowsRead",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::123456789012:user/Dave"
      },
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::static-files-bucket-xxx"
    }
  ]
}

Role


IAM Roles vs Resource Based Policies

iam_cross_account_role_diagram

iam_cross_account_policy_diagram.png


Example: Amazon EventBridge (记住服务)

iam_cross_account_policy_eventbridge.png

iam_cross_account_role_eventbridge.png


IAM Permission Boundaries

iam_permission_boundaries_example

  • Permission Boundary defines permission on s3, cloudwatch, and ec2. But attach a policy defining permission on iam.
  • Because the attached policy is outside the permission boudary, there is no permission.
  • Permission boudary 只是定义范围,不定义具体权限. 只有附加的 policy 才是实质赋权.

Use Case

iam_permission_boundaries_organ_scp_policy

只有三方重合的权限才有效


Hands-on

iam_permission_boundaries_handson01

iam_permission_boundaries_handson01


Best Practice


Summary: IAM Section


TOP