0
0

More than 1 year has passed since last update.

S3バケットポリシーによるアクセス制限

Last updated at Posted at 2021-09-22

特定の VPC からのアクセス制限をしようとして、バケットポリシーでミスったので、その備忘録。

特定の VPC でエンドポイントを作成した後、S3 のバケットポリシーで特定の VPC からのアクセスのみ許可する設定として以下を実施した。
が、設定が不足していたため、AWS マネジメントコンソールからもアクセスできなくなってしまった。

{
    "Version": "2012-10-17",
    "Id": "PolicyDemo",
    "Statement": [
        {
            "Sid": "Allow-from-specific-only",
            "Effect": "Deny",
            "Principal": "*",
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::S3バケット名",
                "arn:aws:s3:::S3バケット名/*"
            ],
            "Condition": {
                "StringNotEquals": {
                    "aws:sourceVpc": "VPC ID"
                }
            }
        }
    ]
}

とりあえず、上記の VPC 内の EC2 から以下のコマンドを実行し、バケットポリシーを削除。

# aws s3api delete-bucket-policy --bucket <S3バケット名>

その後、バケットポリシーを設定し直し。

{
    "Version": "2012-10-17",
    "Id": "PolicyDemo",
    "Statement": [
        {
            "Sid": "Allow-from-specific-only",
            "Effect": "Deny",
            "Principal": "*",
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::S3バケット名",
                "arn:aws:s3:::S3バケット名/*"
            ],
            "Condition": {
                "NotIpAddress": {
                    "aws:SourceIp": "自端末のIP/32"
                },
                "StringNotEquals": {
                    "aws:sourceVpc": "VPC ID"
                }
            }
        }
    ]
}

参考資料

S3バケットポリシーを使用した VPC エンドポイントからのアクセス制御
https://cloud5.jp/s3_policy_endpoint/

複数の否定条件を使ったS3バケットポリシーを正しく理解してますか?
https://dev.classmethod.jp/articles/s3-bucket-policy-multi-condition/

2つのVPCエンドポイントの違いを知る
https://dev.classmethod.jp/articles/vpc-endpoint-gateway-type/

0
0
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
0
0