Logo

身份与访问管理(IAM)

深入了解 AWS IAM 及其相关内容。

概念

身份与访问管理(IAM)

深入了解 AWS IAM 及其相关内容。

IAM

IAM 用于管理用户及其对 AWS 资源的访问权限。在考虑 IAM 时,请记住以下几点:

  1. IAM 是全局性的,不局限于特定区域或可用区
  2. 对 AWS 账户实现集中式控制
  3. 支持共享 AWS 账户访问权限
  4. 细粒度的权限管理
  5. 支持身份联合(如 Active Directory)
  6. MFA(多因素认证)——双因素认证
  7. 为用户提供临时访问权限
  8. 可自定义密码轮换策略
  9. 与多种 AWS 服务集成,并支持 PCI DSS 合规性

IAM 实体

在 IAM 中,有四种类型的实体:

  1. 用户 – 最终用户
  2. 用户组 – 将多个用户归集到一组统一的权限下
  3. 角色 – 可创建角色并将其分配给 AWS 资源
  4. 策略 – 定义一个或多个权限的文档

可以将 策略 应用于用户、用户组和角色。用户、用户组和角色均可共享相同的策略文档。

以下是 JSON 格式的策略文档示例:

1{ 2 "Version": "2012-10-17", 3 "Statement": [ 4 { 5 "Effect": "Allow", 6 "Action": [ 7 "aws-portal:ViewBilling", 8 "aws-portal:ViewPaymentMethods", 9 "aws-portal:ModifyPaymentMethods", 10 "aws-portal:ViewAccount", 11 "aws-portal:ModifyAccount", 12 "aws-portal:ViewUsage" 13 ], 14 "Resource": [ 15 "*" 16 ], 17 "Condition": { 18 "IpAddress": { 19 "aws:SourceIp": "203.0.113.0/24" 20 } 21 } 22 }, 23 { 24 "Effect": "Deny", 25 "Action": [ 26 "s3:*" 27 ], 28 "Resource": [ 29 "arn:aws:s3:::customer", 30 "arn:aws:s3:::customer/*" 31 ] 32 }, 33 { 34 "Effect": "Allow", 35 "Action": [ 36 "ec2:GetConsoleScreenshots" 37 ], 38 "Resource": [ 39 "*" 40 ] 41 }, 42 { 43 "Effect": "Allow", 44 "Action": [ 45 "codedeploy:*", 46 "codecommit:*" 47 ], 48 "Resource": [ 49 "arn:aws:codedeploy:us-west-2:123456789012:deploymentgroup:*", 50 "arn:aws:codebuild:us-east-1:123456789012:project/my-demo-project" 51 ] 52 }, 53 { 54 "Effect": "Allow", 55 "Action": [ 56 "s3:ListAllMyBuckets", 57 "s3:GetObject", 58 "s3:DeleteObject", 59 "s3:PutObject", 60 "s3:PutObjectAcl" 61 ], 62 "Resource": [ 63 "arn:aws:s3:::developer_bucket", 64 "arn:aws:s3:::developer_bucket/*", 65 "arn:aws:autoscaling:us-east-2:123456789012:autoscalinggroup" 66 ], 67 "Condition": { 68 "StringEquals": { 69 "s3:x-amz-acl": [ 70 "public-read" 71 ], 72 "s3:prefix": [ 73 "custom", 74 "other" 75 ] 76 } 77 } 78 } 79 ] 80}

“根账户”是在首次设置 AWS 账户时创建的账户,拥有完全的管理员权限。

  1. 新创建的用户初始时没有任何权限
  2. 新用户会被分配一个访问密钥 ID(Access Key ID)和一个秘密访问密钥(Secret Access Key)
  3. 访问 ID 和秘密访问密钥用于通过 API 和 CLI 进行访问

关键要点:IAM 策略可分配给 用户、用户组 或 角色。

AWS:其他服务

AWS:计算服务