ELB(ALB) で認証機能 (OIDC [Google 認証], Cognito)

OIDC

Google 認証で Gmail のメールアドレスによるログイン

  1. Google APIsへアクセス https://console.developers.google.com/apis/credentials

    • "認証情報を作成" から "OAuthクライアントID" を選択、承認済みのリダイレクト URI は、https://<domain name>/oauth2/idpresponse
    • 作成されるクライアント ID とクライアントのシークレットはコピーして控えておく。
  2. ALB のリスナールール編集

    • ALB のリスナールール編集で、IF パスが / , THEN 認証を OIDC として、以下の curl コマンドの実行結果に対応させて値を入力。(発行者はissuer,認証エンドポイントはauthorization_endpoint,トークンエンドポイントはtoken_endpoint,ユーザー情報エンドポイントはuserinfo_endpoint)
    • クライアント IDとクライアントのシークレットはGoogle APIsで認証情報作成時に控えておいた値
$ curl https://accounts.google.com/.well-known/openid-configuration
{
 "issuer": "https://accounts.google.com",
 "authorization_endpoint": "https://accounts.google.com/o/oauth2/v2/auth",
 "token_endpoint": "https://www.googleapis.com/oauth2/v4/token",
 "userinfo_endpoint": "https://www.googleapis.com/oauth2/v3/userinfo",
 "revocation_endpoint": "https://oauth2.googleapis.com/revoke",
 :

上記仕組みのフローの詳細は、こちらの URL より参照 https://www.exampleloadbalancer.com/auth_detail.html

Cognito

ユーザープール

  • 名前 プール名を "MyUserPool" のように入力

  • 属性 "エンドユーザーをどのようにサインインさせますか?"で"E メールアドレスおよび電話番号"を選択 "どの標準属性が必要ですか?"で"email"を必須に選択。

  • ポリシー 以下のように入力して、「次のステップ」を選択 "パスワードの強度はどれくらいを要求しますか?"で、最小長を6 "ユーザーに自己サインアップを許可しますか?"を"ユーザーに自己サインアップを許可する" "管理者が作成したユーザーアカウントが使用されない期間がどれくらい続くと、有効期限が切れますか?"を有効期限 (日数)を7

  • MFAそして確認 "多要素認証 (MFA) を有効にしますか?": オフ "E メールまたは電話番号の検証を要求しますか?": Eメール "Amazon Cognito に対して SMS メッセージの送信を許可するロールを提供する必要があります。": "MyUserPool-SMS-Role"で"ロールの作成"

  • アプリクライアント "アプリクライアント名": MyAppClient "トークンの有効期限を更新 (日)": 30 "クライアントシークレットを生成"を選択 "アプリクライアントの作成"を選択。

  • サイドメニューの"アプリクライアントの設定"を選択。 有効な IP プロバイダ: Cognito User Pool コールバック URL: https://<domain name>/oauth2/idpresponse "許可されている OAuth フロー": Authorization code grant "許可されている OAuth スコープ": openid

  • サイドメニューの"ドメイン名"を選択 "ドメインのプレフィックス": https://my-hayashier-domain.auth.us-west-2.amazoncognito.com "変更の保存"

フェデレーテッドアイデンティティ

  • ステップ 1: ID プールを作成する 以下のように入力し、"プールを作成" を選択 ID プール名: My ID Pool 認証プロバイダー: Cognito

  • ユーザープール ID: <region-id>_XXXXXXXXX (ユーザープールで MyUserPool を選択した状態で、サイドメニューから"全般設定"を選択し、プールIDを確認)

  • アプリクライアント ID: xxxxxxxxxxxxxxxxxxxxxxxxxx (ユーザープールで MyUserPool を選択した状態で、サイドメニューから"アプリクライアント"を選択し、アプリクライアントID)

"Your Cognito identities require access to your resources "に対し、"許可"を選択

ALB のリスナールール編集

ALB のリスナールール編集で、IF パスが / , THEN 認証を Amazon Cognito として、Cognito ユーザープール(Cognitoのユーザープールの画面で、サイドメニューの全般設定からプール ID の項目)。アプリクライアント(Cognitoのユーザープールの画面で、サイドメニューのアプリクライアントの画面の ID の項目)の値を入力。

実際のテストは、Congito のユーザープールでユーザーを作成しておいてテスト。

参考

https://docs.aws.amazon.com/ja_jp/elasticloadbalancing/latest/application/listener-authenticate-users.html

Simplify Login with Application Load Balancer Built-in Authentication | AWS News Blog

Today I’m excited to announce built-in authentication support in Application Load Balancers (ALB). ALB can now securely authenticate users as they access appli…

【新機能】AWS ELBのApplication Load Balancer(ALB)の認証機能でWebアプリにGoogle認証を追加する | DevelopersIO

Application Load Balancer(ALB)の認証機能のひとつ、OpenID Connectの例としてWebアプリにGoogle認証をかける様子をご紹介します。

https://dev.classmethod.jp/cloud/alb-cognito-user-pool/

My Twitter & RSS

Leave a Reply

Your email address will not be published. Required fields are marked *