■ はじめに
https://dk521123.hatenablog.com/entry/2020/09/29/165636
の続き。 今回は、IAM Policy を使ったアクセス制御について、メモする。 これを細かく設定できれば、セキュリティ強化にかなり役立ちそう。
目次
【0】実装前に 【1】Read Onlyにする 【2】特定のS3バケットのみしかアクセスできないようにする 【3】特定の IAM ロールのみアクセスできるにする 【4】特定の VPC エンドポイントへのアクセスのみ制限
【0】実装前に
* 使用できるAction は、以下の公式サイトを参照のこと。
公式サイト:Action 一覧
https://docs.aws.amazon.com/AmazonS3/latest/API/API_Operations.html
* 以下の公式サイトのチュートリアル / サンプル もみておくといいかも。
公式サイト:チュートリアル / サンプル
https://docs.aws.amazon.com/ja_jp/AmazonS3/latest/dev/walkthrough1.html
https://docs.aws.amazon.com/ja_jp/AmazonS3/latest/dev/example-policies-s3.html
注意
* 明示的な拒否ステートメント(Deny)は、許可ステートメント(Allow)よりも優先される
【1】Read Onlyにする
サンプル
{ "Version": "2012-10-17", "Statement": [ { "Sid": "S3ReadOnly", "Effect": "Allow", "Action": [ "s3:Get*", "s3:List*" ], "Resource": "*" } ] }
【2】特定のS3バケットのみしかアクセスできないようにする
https://qiita.com/komazawa/items/988c346274666023d9dd
にある以下の設定に注意。 ~~~~~~ bucketそのものに対するアクセスと、 bucket配下のオブジェクトに対するアクセス 両方を指定する必要があるらしい ~~~~~~
サンプル
{ "Version": "2012-10-17", "Statement": [ { "Sid": "S3PolicySample", "Effect": "Allow", "Action": [ "s3:GetObject", "s3:PutObject", "s3:GetObjectAcl", "s3:PutObjectAcl", "s3:DeleteObject", "s3:ListAllMyBuckets", "s3:GetBucketLocation", "s3:ListBucket" ], "Resource": [ "arn:aws:s3:::your-bucket-name", "arn:aws:s3:::your-bucket-name/*" ] } ] }
【3】特定の IAM ロールのみアクセスできるにする
https://dev.classmethod.jp/articles/s3-bucket-acces-to-a-specific-role/
が参考になる
サンプル
{ "Version": "2012-10-17", "Statement": [ { "Sid": "S3PolicySample", "Effect": "Deny", "Principal": "*", "Action": "s3:*", "Resource": [ "arn:aws:s3:::your-bucket-name", "arn:aws:s3:::your-bucket-name/*" ] "Condition": { "StringNotLike": { "aws:userId": [ "xxxxxxxxxxxxxxxxxxxxxx:*" ] } } } ] }
【4】特定の VPC エンドポイントへのアクセスのみ制限
https://docs.aws.amazon.com/ja_jp/AmazonS3/latest/dev/example-bucket-policies-vpc-endpoint.html
https://dev.classmethod.jp/articles/s3-access-from-specific-ip-and-vpc/
が参考になる
サンプル
{ "Version": "2012-10-17", "Statement": [ { "Sid": "S3-Access-to-specific-VPCE-only", "Effect": "Deny", "Principal": "*", "Action": "s3:*", "Resource": [ "arn:aws:s3:::your-bucket-name", "arn:aws:s3:::your-bucket-name/*" ] "Condition": { "StringNotEquals": { "aws:sourceVpc": [ "vpc-xxxxxxxxxxxxxxxxx" ] } } } ] }
参考文献
https://qiita.com/komazawa/items/988c346274666023d9dd
https://dev.classmethod.jp/articles/what-permissions-are-needed-for-s3-sync/
https://qastack.jp/programming/38774798/accessdenied-for-listobjects-for-s3-bucket-when-permissions-are-s3
公式サイト
https://docs.aws.amazon.com/ja_jp/IAM/latest/UserGuide/list_amazons3.html
https://docs.aws.amazon.com/ja_jp/AmazonS3/latest/dev/using-with-s3-actions.html
https://aws.amazon.com/jp/premiumsupport/knowledge-center/s3-access-denied-listobjects-sync/
関連記事
Amazon S3 ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2017/03/06/212734
Amazon S3 ~ アクセス制御編 ~
https://dk521123.hatenablog.com/entry/2020/09/29/165636
IAM ~ IAM Policy 編 ~
https://dk521123.hatenablog.com/entry/2020/09/30/133123
Amazon EMR に関するトラブルシューティング
https://dk521123.hatenablog.com/entry/2020/08/05/144724