LoginSignup
18
19

More than 5 years have passed since last update.

「特定のS3バケットのみ操作可能+アカウント内の他のバケットは見れない」ユーザーとバケット設定

Posted at

用途

ファイルのアップロード先としてS3バケットを多数作成しているが、
バケット毎に使用する人が違うため、IAMユーザーで権限管理する。
IAMポリシーとS3バケットポリシーの2つを設定しなければならない。

IAMポリシー

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "s3:*",
      "Resource": "arn:aws:s3:::s3bucket-name"
    }
  ]
}

S3バケットポリシー

{
    "Version": "2008-10-17",
    "Statement": [
        {
            "Sid": "PublicReadForGetBucketObjects",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::AWSアカウントID:user/IAMユーザー名"
            },
            "Action": "s3:*",
            "Resource": "arn:aws:s3:::このポリシーを設定するバケット名/*"
        }
    ]
}

解説

S3に関する操作は全て許可

  "Effect": "Allow",
  "Action": "s3:*",

"s3bucket-name"のバケットのみに上記権限を付与

  "Resource": "arn:aws:s3:::s3bucket-name"

awscliで見てみる

# アカウント内全てのS3バケット情報は権限無しで見れない
$ aws s3 ls --profile s3share
A client error (AccessDenied) occurred: Access Denied

# バケットを指定すると見る事が出来る
$ aws s3 ls s3://s3bucket-name --profile s3share
                           PRE logs/

# upload成功
$ aws s3 cp ~/logo.png s3://s3bucket-name/ --profile s3share
upload: ../../logo.png to s3://s3bucket-name/logo.png
18
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
19