LoginSignup
7
11

More than 5 years have passed since last update.

S3でIPアドレス制限をかけたい

Posted at

バケットポリシーを以下のような感じにします。hogehogeは該当のバケットを指定してください。192.0.2.0/24と203.0.113.1からのアクセスのみを許可したい場合の設定です。

{
    "Version": "2008-10-17",
    "Id": "PolicyForCloudFrontPrivateContent",
    "Statement": [
        {
            "Sid": "AllowPublicRead",
            "Effect": "Deny",
            "Principal": {
                "AWS": "*"
            },
            "Action": "s3:*",
            "Resource": "arn:aws:s3:::hogehoge/*",
            "Condition": {
                "NotIpAddress": {
                    "aws:SourceIp": [
                        "192.0.2.0/24",
                        "203.0.113.1"
                    ]
                }
            }
        }
    ]
}

気をつけないといけないのはAPI経由でのアクセスも制限される点です。デプロイサーバーを用意する場合はデプロイサーバーのIPアドレスも指定しましょう。

7
11
2

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
11