20
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AWS S3のバケットポリシー設定~リファラーでの制限~

Last updated at Posted at 2016-12-09

めもです。

やりたかったこと

S3にバケットを用意して、
特定のリファラーでのみ、使用可能にしたい。
(要は、特定のWEBアプリ以外からのアクセス・操作を拒みたいという話です)

最初にやっちまってた書き方

Getは行けるんです。
ただ、Putが上手くいかず・・・
Conditionの設定を外すとPutが成功するので、Conditionの書き方でまずってるんだなぁと。

{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Sid": "Public Read Bucket Objects",
			"Effect": "Allow",
			"Principal": "*",
			"Action": "s3:*",
			"Resource": "arn:aws:s3:::xxxx.xxxx.xx/*",
			"Condition": {
				"StringLike": {
					"aws:Referer": [
						"http://sitea.xxx/*",
						"http://siteb.xxxxx/*"
					]
				}
			}
		}
	]
}

(たぶん)正しい書き方

こちらを参考にさせて頂きました!

最初にS3に対するアクセスを全て許可して
特定のリファラ以外からのアクセスが拒否だよ~

ってしてるわけですね。

{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Sid": "Public Read Bucket Objects",
			"Effect": "Allow",
			"Principal": "*",
			"Action": "s3:*",
			"Resource": "arn:aws:s3:::xxxx.xxxx.xx/*"
		},
		{
			"Sid": "Referer Deny",
			"Effect": "Deny",
			"Principal": "*",
			"Action": "s3:*",
			"Resource": "arn:aws:s3:::xxxx.xxxx.xx/*",
			"Condition": {
				"StringNotLike": {
					"aws:Referer": [
						"http://sitea.xxx/*",
						"http://siteb.xxxxx/*"
					]
				}
			}
		}
	]
}
20
16
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
20
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?