AWS CognitoをOAuth 2.0認証プロバイダーとして使用する
- プラン: Free、Premium、Ultimate
- 提供形態: GitLab Self-Managed
Amazon Web Services(AWS)Cognitoを使用すると、GitLabインスタンスにユーザー登録、サインイン、およびアクセス制御を追加できます。次のドキュメントでは、AWS CognitoをOAuth 2.0プロバイダーとして有効にします。
AWS Cognitoを設定する
AWS Cognito OAuth 2.0 OmniAuthプロバイダーを有効にするには、アプリケーションをCognitoに登録します。このプロセスにより、アプリケーションのクライアントIDとクライアントのシークレットキーが生成されます。AWS Cognitoを認証プロバイダーとして有効にするには、次の手順を完了してください。後で、設定を適宜変更できます。
AWS consoleにサインインします。
サービスメニューから、Cognitoを選択します。
Manage User Poolsを選択し、右上隅にあるCreate a user poolを選択します。
ユーザープール名を入力し、Step through settingsを選択します。
How do you want your end users to sign in?で、Email address or phone numberとAllow email addressesを選択します。
**Which standard attributes do you want to require?**で、emailを選択します。
残りの設定は必要に応じて構成します。基本的なセットアップでは、これらの設定はGitLab設定に影響しません。
App clientsの設定で、以下を行います:
- Add an app clientを選択します。
- App client nameを追加します。
- Enable username password based authenticationチェックボックスを選択します。
Create app clientを選択します。
AWS Lambda機能でメール送信を設定し、ユーザープールの作成を完了します。
ユーザープールの作成後、App client settingsに移動して、必要な情報を提供します:
- Enabled Identity Providers - すべて選択
- コールバックURL -
https://<your_gitlab_instance_url>/users/auth/cognito/callback - Allowed OAuth Flows - Authorization code grant
- Allowed OAuth 2.0 Scopes -
email、openid、およびprofile
アプリクライアントの設定の変更を保存します。
Domain nameで、AWS CognitoアプリケーションのAWSドメイン名を含めます。
App Clientsで、アプリクライアントIDを見つけます。アプリクライアントのシークレットキーを表示するには、詳細を表示を選択します。これらの値は、OAuth 2.0クライアントIDとクライアントのシークレットキーに対応します。これらの値を保存します。
GitLabを設定する
共通設定で、
cognitoをシングルサインオンプロバイダーとして追加します。これにより、既存のGitLabアカウントを持たないユーザーに対して、Just-In-Timeアカウントプロビジョニングが有効になります。GitLabサーバーで、設定ファイルを開きます。Linuxパッケージインストールの場合:
sudo editor /etc/gitlab/gitlab.rb次のコードでAWS Cognitoアプリケーション情報を次のパラメータに入力します:
app_id: クライアントID。app_secret: クライアントのシークレットキー。site: Amazonのドメインとリージョン。
コードブロックを
/etc/gitlab/gitlab.rbファイルに含めます:gitlab_rails['omniauth_allow_single_sign_on'] = ['cognito'] gitlab_rails['omniauth_providers'] = [ { name: "cognito", label: "Provider name", # optional label for login button, defaults to "Cognito" icon: nil, # Optional icon URL app_id: "<client_id>", app_secret: "<client_secret>", args: { scope: "openid profile email", client_options: { site: "https://<your_domain>.auth.<your_region>.amazoncognito.com", authorize_url: "/oauth2/authorize", token_url: "/oauth2/token", user_info_url: "/oauth2/userInfo" }, user_response_structure: { root_path: [], id_path: ["sub"], attributes: { nickname: "email", name: "email", email: "email" } }, name: "cognito", strategy_class: "OmniAuth::Strategies::OAuth2Generic" } } ]設定ファイルを保存します。
ファイルを保存し、変更を有効にするためにGitLabをreconfigureします。
サインインページに通常のサインインフォームの下にCognitoオプションが表示されるようになりました。このオプションを選択すると、認証プロセスが開始されます。AWS CognitoはサインインとGitLabアプリケーションの認可を要求します。認可が成功すると、リダイレクトされてGitLabインスタンスにサインインします。
詳細については、Configure common設定を参照してください。