LoginSignup
7
7

More than 5 years have passed since last update.

s3cmd put するために必要最小限の IAM Policy

Last updated at Posted at 2015-02-11

夜な夜なバックアップを取って s3cmd put しようと思い、専用の IAM ユーザを作成しました。万一のことがあってもデータを削除されたりすることのないよう、バックアップファイルを put するだけに必要な最小の IAM Policy は下記です。

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

s3:GetBucketLocation が必要なところでひとしきりハマってました……。

この記事の本題ではありませんが、上記の Policy だと、 s3cmd --configure で最後に接続確認テストで失敗になります( s3cmd put でアップロードできることは確認しています)。もしここで接続確認テストを通過させたいのであれば s3:ListAllMyBuckets が必要なので下記のようになるでしょう。

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "s3:ListAllMyBuckets",
      "Resource": "arn:aws:s3:::*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:GetBucketLocation",
        "s3:PutObject"
      ],
      "Resource": [
        "arn:aws:s3:::youcube-backups",
        "arn:aws:s3:::youcube-backups/*"
      ]
    }
  ]
}
7
7
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
7
7