Get Hands-on with Amazon EKS - Workshop Event Series
Whether you're taking your first steps with Kubernetes or you're an experienced practitioner looking to sharpen your skills, our Amazon EKS workshop series delivers practical, real-world experience that moves you forward. Learn directly from AWS solutions architects and EKS specialists through hands-on sessions designed to build your confidence with Kubernetes. Register now and start building with Amazon EKS!
IAM 用户在重新创建后无法访问 S3 存储桶
如果删除并重新创建用户,请使用用户 ARN 更新 S3 存储桶策略以授予用户对存储桶的访问权限。
客户抱怨说,在 IAM 控制台中重新创建用户后,IAM 用户无法访问 S3 存储桶。客户认为新用户已经通过 S3 存储桶策略中的 ARN 授予了权限,因为旧用户和新用户具有相同的用户名。 然而,一旦删除了旧用户,S3 存储桶策略中的用户 ARN 被更改为旧用户的唯一 ID,实际上并未授予新用户任何权限,因此新用户在访问 S3 存储桶时被拒绝访问。 为解决此问题,客户应使用用户的 ARN 更新 S3 存储桶策略以授予用户对存储桶的访问权限。。
请参阅以下重现该问题的步骤:
- AWS CLI 用户配置:
$ aws configure --profile s3testuser AWS Access Key ID [None]: OldAccessKeyID AWS Secret Access Key [None]: OldSecretAccessKey Default region name [None]: us-east-1 Default output format [None]: json $ export AWS_PROFILE=s3testuser $ aws sts get-caller-identity { "UserId": "AIDACKCEVSQ6C2EXAMPLE", <========== 旧用户 ID。 "Account": "111122223333", "Arn": "arn:aws:iam::111122223333:user/s3testuser" }
- S3 存储桶策略授予用户存储桶权限:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::111122223333:user/s3testuser" <========== 用户 ARN。 }, "Action": "s3:*", "Resource": [ "arn:aws:s3:::mybucketnamehere", "arn:aws:s3:::mybucketnamehere/*" ] } ] }
- 用户可以访问存储桶:
$ aws s3 ls s3://mybucketnamehere 2024-06-21 02:27:27 80755 1.JPG $ aws s3 cp s3://mybucketnamehere/1.JPG . download: s3://mybucketnamehere/1.JPG to ./1.JPG
-
从 IAM 控制台中删除用户。
-
S3 存储桶策略发生变化:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "AIDACKCEVSQ6C2EXAMPLE" <========== 从用户 ARN 变为用户 ID。 }, "Action": "s3:*", "Resource": [ "arn:aws:s3:::mybucketnamehere", "arn:aws:s3:::mybucketnamehere/*" ] } ] }
- 使用相同用户名重新创建用户并配置用户配置文件:
$ aws configure --profile s3testuser AWS Access Key ID [****************DX7D]: NewAccessKeyID AWS Secret Access Key [****************HfeF]: NewSecretAccessKey Default region name [us-east-1]: Default output format [json]: $ export AWS_PROFILE=s3testuser $ aws sts get-caller-identity { "UserId": "AIDAT2GQOK7BGGEXAMPLE", <========== 新用户 ID。 "Account": "111122223333", "Arn": "arn:aws:iam::111122223333:user/s3testuser" }
- 新用户被拒绝访问:
$ aws s3 ls s3://mybucketnamehere An error occurred (AccessDenied) when calling the ListObjectsV2 operation: Access Denied $ aws s3 cp s3://mybucketnamehere/1.JPG . fatal error: An error occurred (403) when calling the HeadObject operation: Forbidden
- 使用用户 ARN 更新 S3 存储桶策略:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::111122223333:user/s3testuser" }, "Action": "s3:*", "Resource": [ "arn:aws:s3:::mybucketnamehere", "arn:aws:s3:::mybucketnamehere/*" ] } ] }
- 新用户成功访问 S3 存储桶:
$ aws s3 ls s3://mybucketnamehere 2024-06-21 02:27:27 80755 1.JPG $ aws s3 cp s3://mybucketnamehere/1.JPG . download: s3://mybucketnamehere/1.JPG to ./1.JPG
总结:如果删除并重新创建用户,请使用用户 ARN 更新 S3 存储桶策略以授予用户对存储桶的访问权限。
参考文献: [1] AWS IAM 用户指南 - 策略和权限
- 语言
- 中文 (简体)
