[Osaka/Yokohama] Looking for infrastructure/server side engineers!

[Osaka/Yokohama] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

AWS Cloudfrontの地域制限機能を使って特定地域からのアクセスを遮断する

インフラエンジニアの寺岡です。

今回はAWSのCloudfrontを使って
特定地域からのアクセスを遮断する設定をやってみました。
設定自体は簡単ですが実用性ありだと思いましたのでまとめておきます。

Amazon CloudFront CDN (コンテンツ配信とストリーミング) | AWS

■Cloudfrontとは?

CloudfrontはAWSのCDN(Contents Delivery Network)サービスで
世界中に「エッジロケーション」と呼ばれる
コンテンツを配信するためのサーバが設置されています。
この「エッジロケーション」を使うことで
ユーザーがURLをリクエストしたときにIPアドレスから地域情報を割り出して
一番近い場所にあるサーバからレスポンスを返すという仕組みになっています。
この仕組みのおかげで、EC2やS3などのサービスの前にCloudfrontを設置するだけで
離れた場所にあるサーバにアクセスをしにいく必要がなくなるので
簡単にWebサイトを高速化することができます。

■地理制限機能ってなんだろう?

タイトルで出てきた「地理制限機能」を使ってみます。
Cloudfrontのデフォルトの設定だと
ユーザーがいる場所に関係なくリクエストされたコンテンツを配信します。
これはこれで便利でありがたいのですが

  • 特定地域から頻繁に攻撃を受けるのでアクセスを制限したい
  • 著作権上の理由からアクセスが許可されていない国がある

などの理由があったときに困ります。

こんなときにCloudfrontの機能で国レベルでアクセスを許可もしくは禁止をすることができます。
これが地域制限機能です。
実際に設定して使ってみましょう。

■実際に使ってみよう

あらかじめS3のコンテンツを配信するための
Cloudfrontのディストリビューションを作成しておきました。

AWS S3で静的サイトの配信をやってみた | 株式会社ビヨンド

S3に設置しているコンテンツを配信する設定にしている場合
Orginという項目がS3のエンドポイントになっています。
Domain Nameの項目を後からブラウザでアクセスするのでメモしておきます。
左側にチェックボックスがあるのでチェックして
Distribution Settingsをクリックします。

2016-09-10_03h06_58

ディストリビューションの設定画面になるので
Restrictionsタブを選択しましょう。
Geo Restrictionという項目がDisebledで無効になっているはずです。
これを有効にすることで地理制限機能が使えるようになります。
左のチェックボックスにチェックを入れてEditをクリックしましょう。

2016-09-10_01h42_05

Geo-Restrictionの設定画面になります。

2016-09-10_03h15_41

Enable Geo-Restrictionという項目がNoになっているはずなので
Yesを選択すると新たに項目が2つ増えるはずです。
Restriction Typeでは、制限を行うタイプを選択します。
それぞれについて軽くまとめると・・・

項目名 概要
Whitelist 「ホワイトリスト」はアクセスを許可したい国を設定し、リストに含まれているいずれかの国にユーザーがいる場合のみコンテンツへのアクセスを許可します。
Blacklist 「ブラックリスト」はアクセスを禁止したい国を設定し、リストに含まれているいずれかの国にユーザーがいる場合コンテンツへのアクセスを禁止します。

今回は、特定地域からのアクセスを禁止したいので「ブラックリスト」を使います。
Blacklistを選択してCountries項目で国を選択します。
アクセスが禁止されるかを確認するために日本を選択してみましょう。
左の国一覧からJP(日本)を選択してADD>>ボタンをクリックします。
すると右側に追加されるはずです。
この状態でYes, Editをクリックして編集を完了させます。

2016-09-10_03h38_59

Cloudfrontは設定が反映されるまでに少し時間がかかります。
ディストリビューションの一覧に戻って
statusがin progressからdeployedになるまで待ちましょう。

2016-09-10_03h36_56

ブラウザからcloudfrontのエンドポイントにアクセスしてみます。

2016-09-10_03h40_42

はい、見事に自分で作成したCloudfrontにブロックされました。

いかがでしたでしょうか。
これだけの手順でアクセスの制限が行えますし
使って損はない機能だと思いますので是非是非試してみてください。
ではまたの機会に、ありがとうございました。

この記事がお役に立てば【 いいね 】のご協力をお願いいたします!
0
読み込み中...
0 票, 平均: 0.00 / 10
2,491
X facebook はてなブックマーク pocket
[2024.6.30 CentOS support ended] CentOS server migration solution

[2024.6.30 CentOS support ended] CentOS server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

The person who wrote this article

About the author

Yuki Teraoka

Joined Beyond in 2016 and is currently in his 6th year as an Infrastructure Engineer
MSP, where he troubleshoots failures while
also designing and building infrastructure using public clouds such as AWS.
Recently, I
have been working with Hashicorp tools such as Terraform and Packer as part of building container infrastructure such as Docker and Kubernetes and automating operations, and I
also play the role of an evangelist who speaks at external study groups and seminars.

・GitHub
https://github.com/nezumisannn

・Presentation history
https://github.com/nezumisannn/my-profile

・Presentation materials (SpeakerDeck)
https://speakerdeck.com/nezumisannn

・Certification:
AWS Certified Solutions Architect - Associate
Google Cloud Professional Cloud Architect