All technological notes.
Identity and Access Management (AWS IAM)Identity and Access Management (AWS IAM)
User & GroupIAM:
Identity and Access ManagementRoot account
User
Groups
Users don’t have to belong to a group, and user can belong to multiple groups

In AWS, you can setup a password policy:
IAM Console -> Account settings -> Password policy -> Edit
MFA
Multi Factor AuthenticationMFA = password you know + security device you own
Main benefit of MFA:
MFA devices options
Google Authenticator, Authy, Microsoft AuthenticatorAWS GovCloud (US)
IAM Credentials Report (account-level)
IAM Access Advisor (user-level)
IAM > Credential Report > download
IAM > Usesr > select user > Access Advisor tab
To access AWS, you have three options:
AWS Management Console (protected by password + MFA)AWS Command Line Interface (CLI): protected by access keysAWS Software Developer Kit (SDK) - for code: protected by access keysAccess Keys
Access Key ID ~= usernameSecret Access Key ~= passwordAWS CLIAWS CLI: AWS Command Line Interface
Install
Configure
IAM > Users > select user > Security credentials > Access keys > Create access keyaws 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 SDKAWS SDK: AWS Software Development Kit
Supports
Example: AWS CLI is built on AWS SDK for Python
IAM PolicyPermission
Policy
Users or Groups can be assigned JSON documents called policies
Principle of permission in AWS: the least privilege principle:
{
"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": "*"
}
]
}


sqs:*, Deny, #
"2012-10-17"Statement: one or more individual statements (required)

IAM Conditions
aws:SourceIp

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.
aws:RequestedRegion

Deny access if API calls are made from these regions.
Use case:
- Global company want to restrict access to aws resources from some regions.
RequestedRegion, not RequiredRegionec2:ResourceTag

- 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

- Allow all action on all ec2 instances.
- Deny stop and terminate actions if has not MFA.
aws:PrincipalOrgID

- S3 object operation are limited to the member within an organization.
s3:ListBucket permission applies to arn:aws:s3:::test
ListBucket is a bucket level permission.
s3:GetObject, s3:PutObject, s3:DeleteObject applies to arn:awn:s3:::test/*
object level permission
bucket_name/*
{
"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"
}
]
}
-xxx/#, because this is an object-level permission.Rolerole
Common roles:
Cross account:
2 Options:


Difference
role (user, application or service), you give up your original permissions and take the permissions assigned to the roleresource-based policy, the principal doesn’t have to give up his permissionsExample:
resource-based policy, as not to give up any permission.Reousrce-based policy is supported by:
S3 buckets, SNS topics, SQS queues, etc…记住When a rule runs, it needs permissions on the target
Services supporting Resource-based policy:
Lambda, SNS, SQS, CloudWatch Logs, API Gateway…
IAM role:
Kinesis stream, Systems Manager Run Command, ECS task…
IAM Permission BoundariesIAM Permission Boundaries are supported for users and roles (not groups)
- 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 才是实质赋权.
Organizations SCP
只有三方重合的权限才有效
permission boundaries,
Organizations & SCP

Term
Users:
Groups:
Policies:
Roles:
Security:
MFA + Password PolicyAccess of User
AWS CLI: manage your AWS services using the command-lineAWS SDK: manage your AWS services using a programming languageAccess Keys:
IAM Credential Reports: users + credential statusIAM Access Advisor: permission of a user + last access