S3 のアクセス制御の基本
大前提
S3のバケットとオブジェクトは、作成時点ではすべてプライベート
作成したAWSアカウントの所有者とそのアカウント内のIAMユーザーのみがアクセスできる
出典: Access control in Amazon S3
アクセス制御の4つの手段
出典: Access control in Amazon S3
“The most commonly used access management tool is an access policy. An access policy can be a resource-based policy that is attached to an AWS resource, such as a bucket policy for a bucket. An access policy can also be an identity-based policy that is attached to an AWS Identity and Access Management (IAM) identity, such as an IAM user, group, or role.”
| 手段 | 付与先 | 用途 |
|---|---|---|
| IAMポリシー(Identity-based policy) | IAMユーザー/グループ/ロール | 自アカウント内のIAMアイデンティティにS3アクセス権を付与 |
| バケットポリシー(Bucket policy) | バケット | 他のAWSアカウントやIAMアイデンティティにバケット・オブジェクトへの権限を付与 |
| ACL | バケット/オブジェクト | 他のAWSアカウントに基本的なread/write権限を付与(非推奨) |
| Access Points | バケット | 共有データセットへのアクセス管理を簡素化 |
バケットポリシー: 出典: Access control in Amazon S3 - Access management tools
“Use bucket policies to grant other AWS accounts or IAM identities permissions for the bucket and the objects in it.”
IAMポリシー: 出典: Access control in Amazon S3 - Access management tools
“You can use identity-based policies to grant an IAM identity access to your buckets or objects.”
ACL: 出典: Access control list (ACL) overview
“Modern use cases typically do not require ACLs, and policies are recommended for controlling access to all objects in a bucket.”
Access Points: 出典: Access control in Amazon S3 - Access management tools
“Access Points are named network endpoints that are attached to buckets that you can use to perform Amazon S3 object operations, such as GetObject and PutObject. Each access point has distinct permissions, network controls, and a customized access point policy.”
判断のめやす
- 自アカウント内のユーザー/ロール → IAMポリシー
- 別のAWSアカウント → バケットポリシー
- 特定条件(IP、VPC等)で制限 → バケットポリシー
- 大規模・複数チーム → Access Points
- ACLは原則使わない
ACL(Access Control List)について
なぜ非推奨か
- 粒度が粗い(READ/WRITEなど基本的な権限のみ)
authenticated-readのような誤解を招く設定がある- オブジェクトごとに設定が必要で管理が煩雑
- 2023年4月以降、新規バケットはデフォルトでACLが無効化されている
出典: Access control list (ACL) overview
既定ACL(Canned ACL)一覧
| ACL名 | 適用対象 | 権限 |
|---|---|---|
private | バケット/オブジェクト | 所有者のみFULL_CONTROL(デフォルト) |
public-read | バケット/オブジェクト | 所有者はFULL_CONTROL、全員がREAD |
public-read-write | バケット/オブジェクト | 所有者はFULL_CONTROL、全員がREAD/WRITE |
aws-exec-read | バケット/オブジェクト | 所有者はFULL_CONTROL、EC2がREAD |
authenticated-read | バケット/オブジェクト | 所有者はFULL_CONTROL、全AWSアカウント保持者がREAD |
bucket-owner-read | オブジェクトのみ | オブジェクト所有者はFULL_CONTROL、バケット所有者がREAD |
bucket-owner-full-control | オブジェクトのみ | 両者がFULL_CONTROL |
log-delivery-write | バケットのみ | LogDeliveryグループがWRITEとREAD_ACP |
※ authenticated-read について
authenticated-readは「認証されたユーザーだけ」ではなく「AWSアカウントを持つ世界中の誰でもアクセス可能」という意味
出典: Canned ACL - Amazon S3 User Guide
# まずい例
aws s3 cp --acl authenticated-read myapp s3://artifact