LoginSignup
99
84

More than 5 years have passed since last update.

AWSからS3のセキュリティについて警告メールが来た時の対処方法

Last updated at Posted at 2017-07-19

AWSからS3の警告メールが来たら

S3バケットのポリシーに関するTIPSです。
SORACOMの松井さんに教えていただいて大変助かったので情報共有として記事にします。

いきなりメールが来る

AWSからある日こんなメールが届きました。どうも特定の条件の人に一斉にメール送ってるようです。

Subject: Securing Amazon S3 Buckets [AWS Account: ******]

Hello,

We’re writing to remind you that one or more of your Amazon S3 bucket access control lists (ACLs) are currently configured to allow access from any user on the Internet. The list of buckets with this configuration is below.

By default, S3 bucket ACLs allow only the account owner to read contents from the bucket; however, these ACLs can be configured to permit world access. While there are reasons to configure buckets with world read access, including public websites or publicly downloadable content, recently, there have been public disclosures by third parties of S3 bucket contents that were inadvertently configured to allow world read access but were not intended to be publicly available.

We encourage you to promptly review your S3 buckets and their contents to ensure that you are not inadvertently making objects available to users that you don’t intend. Bucket ACLs can be reviewed in the AWS Management Console (http://console.aws.amazon.com ), or using the AWS CLI tools. ACLs permitting access to either “All Users” or “Any Authenticated AWS User” (which includes any AWS account) are effectively granting world access to the related content.

For more information on configuring your bucket ACLs, please visit: https://docs.aws.amazon.com/AmazonS3/latest/dev/S3_ACLs_UsingACLs.html

For additional assistance reviewing your bucket ACLs, please visit http://aws.amazon.com/support to create a case with AWS Developer Support.

Your list of buckets configured to allow access from anyone on the Internet are:

バケットの名前

要約すると「おめー、S3のバケットを世界中から見られるように設定してるけどまずいんじゃね?ちゃんと制限しろよ」ということのようです。

とはいえ

指摘されたバケットはいずれもstatic web hostingで使っているバケットです。その性質上、世界中から見えないとあまり意味がないです。
公式ドキュメントでも以下のように「該当バケット以下のすべてのオブジェクトに対するGetObjectメソッドを、全てのアクセスに対して許可しろ」と書いてあります。

これは困った・・。

そこに救いの手が

Facebookで相談したところ、元・中の人の松井さんが教えてくれました。

Bucket policy でアクセス元IPアドレスを 0.0.0.0/1 と 128.0.0.0/1 からのみ許可するというライフハック

これはどういうことかというと

  • 0.0.0.0/0を開放するとこれは全開放になっちゃうのでこれまでと変わらないから多分また警告が来る
  • ネットマスクを最小値の1として0.0.0.0/1とするとこれは0.0.0.1~127.255.255.255.254のレンジになる
  • 追加で128.0.0.0/1を許可すると、これが128.0.0.1~255.255.255.254になる
  • 結局、2つ合わせると0.0.0.0/0とするのとほぼ等価になる(厳密にいうとブロードキャストアドレスの分があるけど、そんなアドレスからのアクセスはないだろう)

ということになります。ネットマスクの計算については割愛します。

というわけで

以下のように書き換えたら無事終了。

{
    "Version": "2008-10-17",
    "Statement": [
        {
            "Sid": "PublicReadForGetBucketObjects",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": "s3:GetObject",
            "Resource": "バケットのARN/*",
            "Condition": {
                "IpAddress": {
                    "aws:SourceIp": [
                        "0.0.0.0/1",
                        "128.0.0.0/1"
                    ]
                }
            }
        }
    ]
}

将来的なことを考えるとv6アドレスも足すべきでしょうけどとりあえずはこれでよさそうです。

しかし、そもそもstatic web hostingがONになってる人は対象から外すとかしてくれればいいんですけどねぇ・・。

あと、これで本当に警告が来なくなるのかは未検証です(しばらく待ってみないとわからないので)のでご了承ください。
また届いたら記事をアップデートします。

追記(2017/7/26)

AWSの公式ブログにも記事が出ました。こちらも一読されることをお勧めします。

Amazon S3バケットのアクセス設定に関する注意喚起メールにつきまして

また、AWSの松尾さんからもコメントを頂きましたので追記します。

  • 本来非公開にすべきバケットが意図せず公開されているかもしれないので、今回一斉に警告通知を行った
  • static web hostingのように本人が分かってやっているのであれば「メールを無視してもらってかまわない」(つまり、警告を無視したことによって何らかの制限が課せられるというわけでない)。ただ、メールを読まずに捨てるのではなく、対象バケット名はちゃんと確認して欲しい
  • 今後も不定期に同様の警告メールを送る可能性はある

ということでした。
メールを見て慌てて何か対処しないと問題になるかというとそういうわけではなく、あくまでも気をつけてね・・・という注意喚起だということですね。
上記の設定で今後のメールは来なくなるかもしれませんし、static web hostingのバケットを対象外にして欲しいというのは要望として伝えたので、今後は対象外になるかもしれません。その辺は様子を見てという感じですが、この機会に一度フルアクセスになってる(メールに記載の)バケットは確認してみるのはいいことかと思います。

99
84
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
99
84