1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

CloudFrontでのBasic認証

Last updated at Posted at 2024-06-02

はじめに

Basic認証は、HTTPプロトコルを使用してWebサーバーとクライアント間でユーザー認証を行うためのシンプルな方法です。
本記事では、CloudFrontでのBasic認証について解説します。

実装について

CloudFrontでBasic認証を実装するにはいくつかの方法があります。

・Lambda@Edgeの利用
・CloudFront Functionsの利用
・Amazon CloudFront KeyValueStore+CloudFront Functionsの利用

本記事では3つ目の「Amazon CloudFront KeyValueStore+CloudFront Functionsの利用」について説明します。
この実装方法では、複数のユーザ名/パスワードを管理し、Basic認証を実装することが可能です。

CloudFront Functions

CloudFront FunctionsはCloudFrontのコンテンツ配信ネットワークで、シンプルな処理をより高速に、素早く、安価に実行できるサービスです。

◆CloudFront FunctionsとLambda@Edge

CloudFront Functions Lambda@Edge
プログラミング言語 JavaScript Node.js,Python
イベントソース Viewer request, Viewer response Viewer request, Viewer response,
Origin request, Origin response
Scale リクエスト数: 毎秒 10,000,000 件以上 リクエスト数: 1 リージョンあたり毎秒 10,000 件まで
最大実行時間 1ms未満 5s (Viewer request, Viewer response),
30s (Origin request, Origin response)
最大メモリ 2MB 128 ~ 3,008MB
最大サイズ 10KB 1MB (Viewer request, Viewer response),
50MB (Origin request, Origin response)

上表の通り、CloudFront FunctionsはLambda@Edgeに比べ制限が厳しくなっています。
また、ネットワークやファイルシステムへのアクセスなどもできないため、DynamoDBや外部のAPIを叩くような処理についてはCloudFront Functionsではできません。

◆料金
・100 万件の呼び出しあたり 0.10USD (1 回の呼び出しごとに 0.0000001 USD)

Amazon CloudFront KeyValueStore

CloudFront KeyValueStore は、CloudFront Functions 内からの読み取りアクセスを許可する、安全でグローバルな低レイテンシーのキーバリューストアです。

◆ユースケース
URL の書き換えまたはリダイレクト:キーと値のペアには、書き換えられた URL またはリダイレクト URL を含めることができます。

A/B テストと機能フラグ:ウェブサイトの特定のバージョンにトラフィックの割合を割り当てることで、テストを実行する関数を作成できます。

アクセスの許可:独自に定義した条件とキー値ストアに保存したデータに基づいて、リクエストを許可または拒否するアクセスコントロールを実装できます。

◆サポートされている値の形式
キーと値のペアの値は、以下のいずれかの形式で保存できます。

・文字列
・バイトでエンコードされた文字列
・JSON

まとめ

KeyValueStore で認証情報を管理することにより、アプリケーションコードのデプロイを行うこと無く、認証情報の追加や変更を行うことができるようになります。
ただし、マネジメントコンソールにアクセスさえできればユーザー名とパスワードが平文で見えてしまうという点には注意が必要です。

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?