OAuth 2.0認証プロバイダとしてOpenID Connectを使用します。
GitLabはOpenIDConnectをOmniAuthプロバイダとして使用することができます。
OpenID Connect OmniAuthプロバイダを有効にするには、アプリケーションをOpenID Connectプロバイダに登録する必要があります。OpenID Connectはクライアントの詳細とシークレットを提供します。
-
GitLab サーバーで設定ファイルを開きます。
Linuxパッケージ・インストールの場合:
sudo editor /etc/gitlab/gitlab.rbセルフコンパイルによるインストールの場合:
cd /home/git/gitlab sudo -u git -H editor config/gitlab.yml -
共通設定を構成して、シングルサインオンプロバイダとして
openid_connect。これにより、既存のGitLabアカウントを持っていないユーザーのためのJust-In-Timeアカウントプロビジョニングが可能になります。 -
プロバイダー設定を追加します。
Linuxパッケージ・インストールの場合:
gitlab_rails['omniauth_providers'] = [ { name: "openid_connect", # do not change this parameter label: "Provider name", # optional label for login button, defaults to "Openid Connect" icon: "<custom_provider_icon>", args: { name: "openid_connect", scope: ["openid","profile","email"], response_type: "code", issuer: "<your_oidc_url>", discovery: true, client_auth_method: "query", uid_field: "<uid_field>", send_scope_to_token_endpoint: "false", pkce: true, client_options: { identifier: "<your_oidc_client_id>", secret: "<your_oidc_client_secret>", redirect_uri: "<your_gitlab_url>/users/auth/openid_connect/callback" } } } ]複数の ID プロバイダーを使用する Linux パッケージ・インストールの場合:
{ 'name' => 'openid_connect', 'label' => '...', 'icon' => '...', 'args' => { 'name' => 'openid_connect', 'strategy_class': 'OmniAuth::Strategies::OpenIDConnect', 'scope' => ['openid', 'profile', 'email'], 'discovery' => true, 'response_type' => 'code', 'issuer' => 'https://...', 'client_auth_method' => 'query', 'uid_field' => '...', 'client_options' => { `identifier`: "<your_oidc_client_id>", `secret`: "<your_oidc_client_secret>", 'redirect_uri' => 'https://.../users/auth/openid_connect/callback' } } }, { 'name' => 'openid_connect_2fa', 'label' => '...', 'icon' => '...', 'args' => { 'name' => 'openid_connect_2fa', 'strategy_class': 'OmniAuth::Strategies::OpenIDConnect', 'scope' => ['openid', 'profile', 'email'], 'discovery' => true, 'response_type' => 'code', 'issuer' => 'https://...', 'client_auth_method' => 'query', 'uid_field' => '...', 'client_options' => { ... 'redirect_uri' => 'https://.../users/auth/openid_connect_2fa/callback' } } }OIDC で複数の ID プロバイダを使用する場合の詳細については、イシュー5992 を参照してください。セルフコンパイルによるインストールの場合:
- { name: 'openid_connect', # do not change this parameter label: 'Provider name', # optional label for login button, defaults to "Openid Connect" icon: '<custom_provider_icon>', args: { name: 'openid_connect', scope: ['openid','profile','email'], response_type: 'code', issuer: '<your_oidc_url>', discovery: true, client_auth_method: 'query', uid_field: '<uid_field>', send_scope_to_token_endpoint: false, pkce: true, client_options: { identifier: '<your_oidc_client_id>', secret: '<your_oidc_client_secret>', redirect_uri: '<your_gitlab_url>/users/auth/openid_connect/callback' } } }各設定オプションの詳細については、OmniAuth OpenID Connect usage documentationおよびOpenID Connect Core 1.0 specification を参照してください。 -
プロバイダの設定では、OpenID Connectクライアントの設定に合わせてプロバイダの値を変更します。以下を参考にしてください:
-
<your_oidc_label>はログインページに表示されるラベルです。 -
<custom_provider_icon>(オプション) はログインページに表示されるアイコンです。主要なソーシャルログインプラットフォームのアイコンはGitLabに組み込まれていますが、このパラメータを指定することでこれらのアイコンを上書きすることができます。GitLabはローカルパスと絶対URLの両方を受け入れます。 -
<your_oidc_url>(オプション)はOpenID Connectプロバイダを指すURLです(例えばhttps://example.com/auth/realms/your-realm)。この値が提供されない場合、URLは以下のフォーマットでclient_optionsから構築されます:<client_options.scheme>://<client_options.host>:<client_options.port>. -
discoveryがtrueに設定されている場合、OpenID Connect プロバイダは<your_oidc_url>/.well-known/openid-configurationを使用してクライアントオプションの自動検出を試みます。デフォルトはfalseです。 -
client_auth_method(オプション) は、OpenID Connect プロバイダとクライアントの認証に使用する方法を指定します。- 使用可能な値は以下のとおりです:
-
basic- HTTP 基本認証。 -
jwt_bearer- JWTベースの認証(秘密鍵とクライアントシークレットの署名)。 -
mtls- 相互TLSまたはX.509証明書の検証。 - それ以外の値では、リクエストボディにクライアントIDとシークレットを投稿します。
-
- 指定されない場合、この値のデフォルトは
basicです。
- 使用可能な値は以下のとおりです:
-
<uid_field>(オプション) は、uidの値を定義するuser_info.raw_attributesのフィールド名です (例:preferred_username)。この値を指定しない場合、または設定された値を持つフィールドがuser_info.raw_attributesの詳細にない場合、uidはsubフィールドを使用します。 -
send_scope_to_token_endpointはデフォルトでtrueです。したがって、このscopeパラメータは通常、トークン・エンドポイントへのリクエストに含まscopeれます。ただし、scopeOpenID Connectプロバイダがこのscopeようなリクエストでパラメータをscope受け付けないscope場合は、これをfalseに設定してください。 -
pkce(オプション):Proof Key for Code Exchangeを有効にします。GitLab 15.9で利用可能。 -
client_optionsはOpenID Connectクライアント固有のオプションです。具体的には-
identifierは、OpenID Connect サービスプロバイダで設定されているクライアント識別子です。 -
secretは、OpenID Connect サービスプロバイダで設定されているクライアントシークレットです。たとえば、OmniAuth OpenID Connectではこれが必要です。サービスプロバイダがシークレットを必要としない場合は、任意の値を指定しても無視されます。 -
redirect_uriはログイン成功後にユーザーをリダイレクトするGitLabのURLです(例えば、http://example.com/users/auth/openid_connect/callback)。 -
end_session_endpoint(オプション) は、セッションを終了するエンドポイントへの URL です。自動検出が無効または失敗した場合にこのURLを指定できます。 - 自動検出が無効または失敗しない限り、以下の
client_optionsはオプションです:-
authorization_endpointは、エンドユーザーを作成するエンドポイントへの URL です。 -
token_endpointは、アクセストークンを提供するエンドポイントへの URL です。 -
userinfo_endpointはユーザー情報を提供するエンドポイントへのURLです。 -
jwks_uriは、トークン署名者が鍵を公開するエンドポイントへの URL です。
-
-
-
- 設定ファイルを保存します。
-
変更を有効にするには
- Linux パッケージを使用して GitLab をインストールした場合は、GitLab を再設定してください。
- インストールしたGitLabをセルフコンパイルし、GitLabを再起動。
サインインページでは、通常のサインインフォームの下にOpenID Connectオプションがあります。このオプションを選択して認証プロセスを開始します。OpenID Connectプロバイダーは、GitLabアプリケーションにサインインし、クライアントによって確認が必要な場合は作成者を尋ねます。GitLabにリダイレクトされ、サインインします。
設定例
以下の設定は、Linux パッケージインストールを使用する際に、異なるプロバイダで OpenID を設定する方法を示しています。
Google の設定
詳しくはGoogleのドキュメントをご覧ください:
gitlab_rails['omniauth_providers'] = [
{
name: "openid_connect", # do not change this parameter
label: "Google OpenID", # optional label for login button, defaults to "Openid Connect"
args: {
name: "openid_connect",
scope: ["openid", "profile", "email"],
response_type: "code",
issuer: "https://accounts.google.com",
client_auth_method: "query",
discovery: true,
uid_field: "preferred_username",
pkce: true,
client_options: {
identifier: "<YOUR PROJECT CLIENT ID>",
secret: "<YOUR PROJECT CLIENT SECRET>",
redirect_uri: "https://example.com/users/auth/openid_connect/callback",
}
}
}
]
Microsoft Azureの設定
Microsoft Azure用のOpenID Connect(OIDC) プロトコルは、Microsoftアイデンティティプラットフォーム(v2)エンドポイントを使用します。開始するには、Azureポータルにサインインします。アプリには、以下の情報が必要です:
- テナント ID。すでにお持ちの場合もあります。詳細については、Microsoft Azureテナントのドキュメントを参照してください。
- クライアント ID とクライアントシークレット。Microsoft Quickstart Register an Applicationドキュメントの指示に従って、アプリのテナント ID、クライアント ID、クライアント シークレットを取得します。
Linuxパッケージインストール用の設定ブロック例:
gitlab_rails['omniauth_providers'] = [
{
name: "openid_connect", # do not change this parameter
label: "Azure OIDC", # optional label for login button, defaults to "Openid Connect"
args: {
name: "openid_connect",
scope: ["openid", "profile", "email"],
response_type: "code",
issuer: "https://login.microsoftonline.com/<YOUR-TENANT-ID>/v2.0",
client_auth_method: "query",
discovery: true,
uid_field: "preferred_username",
pkce: true,
client_options: {
identifier: "<YOUR APP CLIENT ID>",
secret: "<YOUR APP CLIENT SECRET>",
redirect_uri: "https://gitlab.example.com/users/auth/openid_connect/callback"
}
}
}
]
マイクロソフトはそのプラットフォームがOIDCプロトコルでどのように動作するかを文書化しています。
Microsoft Azure Active Directory B2Cの設定
GitLabがAzure Active Directory B2Cと連携するには特別な設定が必要です。始めるには、Azureポータルにサインインします。アプリには、Azureから以下の情報が必要です:
- テナントID。テナント ID。詳細については、Microsoft Azure Tenantドキュメントをレビューしてください。
- クライアント ID とクライアント シークレット。Microsoft チュートリアルドキュメントの指示に従って、アプリのクライアント ID とクライアント シークレットを取得します。
- ユーザーフローまたはポリシー名。Microsoftチュートリアルの指示に従ってください。
アプリを設定します:
-
アプリを
Redirect URIに設定します。例えば、GitLabドメインがgitlab.example.comの場合、アプリRedirect URIをhttps://gitlab.example.com/users/auth/openid_connect/callbackに設定します。 -
IDトークンを有効にします。
-
アプリに以下のAPI権限を追加します:
openidoffline_access
カスタムポリシーの設定
Azure B2Cでは、ユーザーをログインさせるためのビジネスロジックを定義する2つの方法があります:
標準の Azure B2C ユーザーフローでは、OpenIDemail クレームを送信しないため、カスタムポリシーが必要です。したがって、標準のユーザーフローは、allow_single_sign_on またはauto_link_user パラメータでは動作しません。標準の Azure B2C ポリシーでは、GitLab は新しいアカウントを作成したり、メールアドレスを使用して既存のアカウントにリンクしたりできません。
まず、カスタムポリシーを作成します。
Microsoftの説明では、カスタムポリシースターターパックのSocialAndLocalAccounts 、LocalAccounts 、ローカルのActive Directoryアカウントに対して認証を行います。ポリシーをアップロードする前に、以下を実行してください:
-
emailクレームをエクスポートするには、SignUpOrSignin.xmlを変更します。 次の行を置き換えます:<OutputClaim ClaimTypeReferenceId="email" />に置き換えてください:
<OutputClaim ClaimTypeReferenceId="signInNames.emailAddress" PartnerClaimType="email" /> -
OIDCディスカバリーをB2Cで動作させるには、OIDC仕様と互換性のある発行者でポリシーを設定してください。トークンの互換性設定を参照してください。
JwtIssuerの下のTrustFrameworkBase.xmlで、IssuanceClaimPatternをAuthorityWithTfpに設定します:<ClaimsProvider> <DisplayName>Token Issuer</DisplayName> <TechnicalProfiles> <TechnicalProfile Id="JwtIssuer"> <DisplayName>JWT Issuer</DisplayName> <Protocol Name="None" /> <OutputTokenFormat>JWT</OutputTokenFormat> <Metadata> <Item Key="IssuanceClaimPattern">AuthorityWithTfp</Item> ... -
ポリシーをアップロードします。既存のポリシーを更新する場合は、既存のファイルを上書きします。
-
発行者 URL を決定するには、サインインポリシーを使用します。発行者 URL は次の形式です:
https://<YOUR-DOMAIN>/tfp/<YOUR-TENANT-ID>/<YOUR-SIGN-IN-POLICY-NAME>/v2.0/ポリシー名は URL の小文字になります。たとえば、
B2C_1A_signup_signinポリシーは、b2c_1a_signup_siginと表示されます。末尾のスラッシュが含まれていることを確認してください。
-
OIDCディスカバリーURLと発行者URLのオペレーションを確認し、発行者URLに
.well-known/openid-configuration:https://<YOUR-DOMAIN>/tfp/<YOUR-TENANT-ID>/<YOUR-SIGN-IN-POLICY-NAME>/v2.0/.well-known/openid-configurationたとえば、
domainがexample.b2clogin.comで、テナント ID がfc40c736-476c-4da1-b489-ee48cee84386の場合、curlとjqを使って発行者を抽出できます:$ curl --silent "https://example.b2clogin.com/tfp/fc40c736-476c-4da1-b489-ee48cee84386/b2c_1a_signup_signin/v2.0/.well-known/openid-configuration" | jq .issuer "https://example.b2clogin.com/tfp/fc40c736-476c-4da1-b489-ee48cee84386/b2c_1a_signup_signin/v2.0/" -
signup_signinで使用したカスタムポリシーで発行者の URL を設定します。たとえば、これは Linux パッケージインストール用のb2c_1a_signup_signinのカスタムポリシーによる設定です:gitlab_rails['omniauth_providers'] = [ { name: "openid_connect", # do not change this parameter label: "Azure B2C OIDC", # optional label for login button, defaults to "Openid Connect" args: { name: "openid_connect", scope: ["openid"], response_mode: "query", response_type: "id_token", issuer: "https://<YOUR-DOMAIN>/tfp/<YOUR-TENANT-ID>/b2c_1a_signup_signin/v2.0/", client_auth_method: "query", discovery: true, send_scope_to_token_endpoint: true, pkce: true, client_options: { identifier: "<YOUR APP CLIENT ID>", secret: "<YOUR APP CLIENT SECRET>", redirect_uri: "https://gitlab.example.com/users/auth/openid_connect/callback" } } }]
Azure B2C のトラブルシューティング
-
yourtenant.onmicrosoft.com、ProxyIdentityExperienceFrameworkAppId、およびIdentityExperienceFrameworkAppIdがすべて、B2C テナントのホスト名と、XML ポリシー ファイルの各クライアント ID と一致していることを確認します。 - アプリにリダイレクト URI として
https://jwt.msを追加し、カスタムポリシーテスターを使用します。ペイロードにユーザーのメールアクセスと一致するemailが含まれていることを確認してください。 -
カスタムポリシーを有効にした後、ユーザーがサインインしようとすると
Invalid username or passwordが表示される場合があります。これは、IdentityExperienceFrameworkアプリの設定の問題である可能性があります。アプリのマニフェストにこれらの設定が含まれていることを確認することを示唆するMicrosoft のコメントを参照してください:"accessTokenAcceptedVersion": null"signInAudience": "AzureADMyOrg"
この設定は、IdentityExperienceFramework アプリの作成時に使用されたSupported account types 設定に対応しています。
Keycloakの設定
GitLabはHTTPSを使用するOpenIDプロバイダと連携します。HTTPを使うKeycloakサーバーを設定することもできますが、GitLabはHTTPSを使うKeycloakサーバーとしか通信できません。
トークンに署名するために対称鍵暗号化アルゴリズム(例えばHS256やHS358)の代わりに公開鍵暗号化アルゴリズム(例えばRSA256やRSA512)を使用するようにKeycloakを設定します。公開鍵暗号化アルゴリズムは次のとおりです:
- 設定が簡単。
- 秘密鍵の漏洩はセキュリティに深刻な影響を与えるため、より安全。
- Keycloakの管理コンソールを開きます。
- Realm Settings > Tokens > Default Signature Algorithmを選択します。
- 署名アルゴリズムを設定します。
Linuxパッケージインストール用の設定ブロック例:
gitlab_rails['omniauth_providers'] = [
{
name: "openid_connect", # do not change this parameter
label: "Keycloak", # optional label for login button, defaults to "Openid Connect"
args: {
name: "openid_connect",
scope: ["openid", "profile", "email"],
response_type: "code",
issuer: "https://keycloak.example.com/realms/myrealm",
client_auth_method: "query",
discovery: true,
uid_field: "preferred_username",
pkce: true,
client_options: {
identifier: "<YOUR CLIENT ID>",
secret: "<YOUR CLIENT SECRET>",
redirect_uri: "https://gitlab.example.com/users/auth/openid_connect/callback"
}
}
}
]
対称鍵アルゴリズムによるKeycloakの設定
GitLab 14.2で導入されました。
共通鍵暗号化を使うには:
-
Keycloakデータベースからシークレットキーを抽出します。Keycloakはこの値をウェブインターフェースでは公開しません。ウェブインターフェースに表示されるクライアントシークレットはOAuth 2.0のクライアントシークレットであり、JSONウェブトークンに署名するために使用されるシークレットとは異なります。
例えば、KeycloakのバックエンドデータベースとしてPostgreSQLを使用する場合:
- データベースコンソールにサインインします。
-
次の SQL クエリを実行してキーを抽出します:
$ psql -U keycloak psql (13.3 (Debian 13.3-1.pgdg100+1)) Type "help" for help. keycloak=# SELECT c.name, value FROM component_config CC INNER JOIN component C ON(CC.component_id = C.id) WHERE C.realm_id = 'master' and provider_id = 'hmac-generated' AND CC.name = 'secret'; -[ RECORD 1 ]--------------------------------------------------------------------------------- name | hmac-generated value | lo6cqjD6Ika8pk7qc3fpFx9ysrhf7E62-sqGc8drp3XW-wr93zru8PFsQokHZZuJJbaUXvmiOftCZM3C4KW3-g -[ RECORD 2 ]--------------------------------------------------------------------------------- name | fallback-HS384 value | UfVqmIs--U61UYsRH-NYBH3_mlluLONpg_zN7CXEwkJcO9xdRNlzZfmfDLPtf2xSTMvqu08R2VhLr-8G-oZ47Aこの例では、HS256 (
hmac-generated) と HS384 (fallback-HS384) の二つの秘密鍵があります。最初のvalueを使って GitLab を設定します。
-
valueを標準の base64 に変換します。HS256トークンによる無効な署名の投稿で説明したように、valueは RFC 4648 のURL とファイル名の安全なアルファベットによる Base 64 エンコーディングのセクションでエンコードされています。これはRFC 2045で定義されている標準のbase64に変換する必要があります。以下のRubyスクリプトがこれを行います:require 'base64' value = "lo6cqjD6Ika8pk7qc3fpFx9ysrhf7E62-sqGc8drp3XW-wr93zru8PFsQokHZZuJJbaUXvmiOftCZM3C4KW3-g" Base64.encode64(Base64.urlsafe_decode64(value))この結果、以下の値が得られます:
lo6cqjD6Ika8pk7qc3fpFx9ysrhf7E62+sqGc8drp3XW+wr93zru8PFsQokH\nZZuJJbaUXvmiOftCZM3C4KW3+g==\n -
この base64 エンコードされたシークレットを
jwt_secret_base64で指定します。例えばgitlab_rails['omniauth_providers'] = [ { name: "openid_connect", # do not change this parameter label: "Keycloak", # optional label for login button, defaults to "Openid Connect" args: { name: "openid_connect", scope: ["openid", "profile", "email"], response_type: "code", issuer: "https://keycloak.example.com/auth/realms/myrealm", client_auth_method: "query", discovery: true, uid_field: "preferred_username", jwt_secret_base64: "<YOUR BASE64-ENCODED SECRET>", pkce: true, client_options: { identifier: "<YOUR CLIENT ID>", secret: "<YOUR CLIENT SECRET>", redirect_uri: "https://gitlab.example.com/users/auth/openid_connect/callback" } } } ]
JSON::JWS::VerificationFailed エラーが表示された場合は、シークレットの指定が間違っています。
カスドア
GitLabはHTTPSを使用するOpenIDプロバイダと連携しています。CasdoorでOpenIDを通してGitLabに接続するにはHTTPSを使用してください。
あなたのアプリのために、Casdoorで以下のステップを完了してください:
- クライアントIDとクライアントシークレットを取得します。
- GitLabのリダイレクトURLを追加します。例えば、GitLab のドメインが
gitlab.example.comの場合、Casdoor アプリがRedirect URI:https://gitlab.example.com/users/auth/openid_connect/callbackのようになっていることを確認します。
詳細はCasdoorのドキュメントを参照してください。
Linuxパッケージインストール時の設定例(ファイルパス:/etc/gitlab/gitlab.rb ):
gitlab_rails['omniauth_providers'] = [
{
name: "openid_connect", # do not change this parameter
label: "Casdoor", # optional label for login button, defaults to "Openid Connect"
args: {
name: "openid_connect",
scope: ["openid", "profile", "email"],
response_type: "code",
issuer: "https://<CASDOOR_HOSTNAME>",
client_auth_method: "query",
discovery: true,
uid_field: "sub",
client_options: {
identifier: "<YOUR CLIENT ID>",
secret: "<YOUR CLIENT SECRET>",
redirect_uri: "https://gitlab.example.com/users/auth/openid_connect/callback"
}
}
}
]
セルフ・コンパイル・インストールの設定例 (ファイル・パス:config/gitlab.yml):
- { name: 'openid_connect', # do not change this parameter
label: 'Casdoor', # optional label for login button, defaults to "Openid Connect"
args: {
name: 'openid_connect',
scope: ['openid','profile','email'],
response_type: 'code',
issuer: 'https://<CASDOOR_HOSTNAME>',
discovery: true,
client_auth_method: 'query',
uid_field: 'sub',
client_options: {
identifier: '<YOUR CLIENT ID>',
secret: '<YOUR CLIENT SECRET>',
redirect_uri: 'https://gitlab.example.com/users/auth/openid_connect/callback'
}
}
}
複数のOpenID Connectプロバイダーの設定
アプリケーションで複数の OpenID Connect(OIDC) プロバイダを使用するように設定できます。そのためには、設定ファイルでstrategy_class を明示的に設定します。
これは、以下のいずれかのシナリオで行う必要があります:
- OpenID Connectプロトコルへのマイグレーション。
- さまざまな認証レベルの提供
以下の設定例では、2FA を使用するオプションと 2FA を使用しないオプションという、異なるレベルの認証を提供する方法を示しています。
Linuxパッケージ・インストールの場合:
gitlab_rails['omniauth_providers'] = [
{
name: "openid_connect",
label: "Provider name", # optional label for login button, defaults to "Openid Connect"
icon: "<custom_provider_icon>",
args: {
name: "openid_connect",
strategy_class: "OmniAuth::Strategies::OpenIDConnect",
scope: ["openid","profile","email"],
response_type: "code",
issuer: "<your_oidc_url>",
discovery: true,
client_auth_method: "query",
uid_field: "<uid_field>",
send_scope_to_token_endpoint: "false",
pkce: true,
client_options: {
identifier: "<your_oidc_client_id>",
secret: "<your_oidc_client_secret>",
redirect_uri: "<your_gitlab_url>/users/auth/openid_connect/callback"
}
}
},
{
name: "openid_connect_2fa",
label: "Provider name 2FA", # optional label for login button, defaults to "Openid Connect"
icon: "<custom_provider_icon>",
args: {
name: "openid_connect_2fa",
strategy_class: "OmniAuth::Strategies::OpenIDConnect",
scope: ["openid","profile","email"],
response_type: "code",
issuer: "<your_oidc_url>",
discovery: true,
client_auth_method: "query",
uid_field: "<uid_field>",
send_scope_to_token_endpoint: "false",
pkce: true,
client_options: {
identifier: "<your_oidc_client_id>",
secret: "<your_oidc_client_secret>",
redirect_uri: "<your_gitlab_url>/users/auth/openid_connect_2fa/callback"
}
}
}
]
セルフコンパイルによるインストールの場合:
- { name: 'openid_connect',
label: 'Provider name', # optional label for login button, defaults to "Openid Connect"
icon: '<custom_provider_icon>',
args: {
name: 'openid_connect',
strategy_class: "OmniAuth::Strategies::OpenIDConnect",
scope: ['openid','profile','email'],
response_type: 'code',
issuer: '<your_oidc_url>',
discovery: true,
client_auth_method: 'query',
uid_field: '<uid_field>',
send_scope_to_token_endpoint: false,
pkce: true,
client_options: {
identifier: '<your_oidc_client_id>',
secret: '<your_oidc_client_secret>',
redirect_uri: '<your_gitlab_url>/users/auth/openid_connect/callback'
}
}
}
- { name: 'openid_connect_2fa',
label: 'Provider name 2FA', # optional label for login button, defaults to "Openid Connect"
icon: '<custom_provider_icon>',
args: {
name: 'openid_connect_2fa',
strategy_class: "OmniAuth::Strategies::OpenIDConnect",
scope: ['openid','profile','email'],
response_type: 'code',
issuer: '<your_oidc_url>',
discovery: true,
client_auth_method: 'query',
uid_field: '<uid_field>',
send_scope_to_token_endpoint: false,
pkce: true,
client_options: {
identifier: '<your_oidc_client_id>',
secret: '<your_oidc_client_secret>',
redirect_uri: '<your_gitlab_url>/users/auth/openid_connect_2fa/callback'
}
}
}
この使用例では、企業ディレクトリ内の既存の既知の識別子に基づいて、異なるプロバイダ間でextern_uid を同期したい場合があります。
これを行うには、uid_field を設定します。 次のコード例では、この方法を示しています:
def sync_missing_provider(self, user: User, extern_uid: str)
existing_identities = []
for identity in user.identities:
existing_identities.append(identity.get("provider"))
local_extern_uid = extern_uid.lower()
for provider in ("openid_connect_2fa", "openid_connect"):
identity = [
identity
for identity in user.identities
if identity.get("provider") == provider
and identity.get("extern_uid").lower() != local_extern_uid
]
if provider not in existing_identities or identity:
if identity and identity[0].get("extern_uid") != "":
logger.error(f"Found different identity for provider {provider} for user {user.id}")
continue
else:
logger.info(f"Add identity 'provider': {provider}, 'extern_uid': {extern_uid} for user {user.id}")
user.provider = provider
user.extern_uid = extern_uid
user = self.save_user(user)
return user
詳細はGitLab API ユーザーメソッドのドキュメント を参照ください。
OIDC グループメンバーシップに基づいたユーザーの設定
GitLab 15.10 で導入されました。
OIDCグループメンバーシップを設定することができます:
GitLabはサインインするたびにこれらのグループをチェックし、必要に応じてユーザー属性を更新します。この機能では、ユーザーを自動的にGitLabグループに追加することはできません。
必須グループ
アイデンティティ・プロバイダ(IdP)は、OIDCレスポンスでグループ情報をGitLabに渡す必要があります。このレスポンスを使ってユーザーに特定のグループのメンバーであることを要求するには、GitLabを識別するように設定します:
-
groups_attribute設定を使用して、OIDC レスポンスでグループを探す場所。 -
required_groups設定を使用して、サインインに必要なグループメンバーシップ。
required_groups を設定しないか、設定を空のままにすると、OIDC を通じて IdP によって認証されたユーザーであれば誰でも GitLab を使用できます。
-
/etc/gitlab/gitlab.rbを編集します:gitlab_rails['omniauth_providers'] = [ { name: "openid_connect", label: "Provider name", args: { name: "openid_connect", scope: ["openid","profile","email"], response_type: "code", issuer: "<your_oidc_url>", discovery: true, client_auth_method: "query", uid_field: "<uid_field>", client_options: { identifier: "<your_oidc_client_id>", secret: "<your_oidc_client_secret>", redirect_uri: "<your_gitlab_url>/users/auth/openid_connect/callback", gitlab: { groups_attribute: "groups", required_groups: ["Developer"] } } } } ] -
ファイルを保存し、変更を有効にするためにGitLab を再設定してください。
-
/home/git/gitlab/config/gitlab.ymlを編集します:production: &base omniauth: providers: - { name: 'openid_connect', label: 'Provider name', args: { name: 'openid_connect', scope: ['openid','profile','email'], response_type: 'code', issuer: '<your_oidc_url>', discovery: true, client_auth_method: 'query', uid_field: '<uid_field>', client_options: { identifier: '<your_oidc_client_id>', secret: '<your_oidc_client_secret>', redirect_uri: '<your_gitlab_url>/users/auth/openid_connect/callback', gitlab: { groups_attribute: "groups", required_groups: ["Developer"] } } } } -
ファイルを保存し、変更を有効にするためにGitLab を再設定してください。
外部グループ
IdPはOIDCレスポンスでグループ情報をGitLabに渡す必要があります。このレスポンスを使用して、グループメンバーシップに基づいてユーザーを外部ユーザーとして識別するには、GitLabを識別するように設定します:
-
groups_attribute設定を使用して、OIDC レスポンスでグループを探す場所。 -
external_groups設定を使用して、どのグループ・メンバーシップでユーザーを内部ユーザーとして識別するか。
-
/etc/gitlab/gitlab.rbを編集します:gitlab_rails['omniauth_providers'] = [ { name: "openid_connect", label: "Provider name", args: { name: "openid_connect", scope: ["openid","profile","email"], response_type: "code", issuer: "<your_oidc_url>", discovery: true, client_auth_method: "query", uid_field: "<uid_field>", client_options: { identifier: "<your_oidc_client_id>", secret: "<your_oidc_client_secret>", redirect_uri: "<your_gitlab_url>/users/auth/openid_connect/callback", gitlab: { groups_attribute: "groups", external_groups: ["Freelancer"] } } } } ] -
ファイルを保存し、変更を有効にするためにGitLab を再設定してください。
-
/home/git/gitlab/config/gitlab.ymlを編集します:production: &base omniauth: providers: - { name: 'openid_connect', label: 'Provider name', args: { name: 'openid_connect', scope: ['openid','profile','email'], response_type: 'code', issuer: '<your_oidc_url>', discovery: true, client_auth_method: 'query', uid_field: '<uid_field>', client_options: { identifier: '<your_oidc_client_id>', secret: '<your_oidc_client_secret>', redirect_uri: '<your_gitlab_url>/users/auth/openid_connect/callback', gitlab: { groups_attribute: "groups", external_groups: ["Freelancer"] } } } } -
ファイルを保存し、変更を有効にするためにGitLab を再設定してください。
監査役グループ
IdP は、OIDC レスポンスでグループ情報を GitLab に渡す必要があります。このレスポンスを使用して、グループメンバーシップに基づいてユーザーを監査役として割り当てるには、GitLabを識別するように設定します:
-
groups_attribute設定を使用して、OIDC レスポンスでグループを探す場所。 -
auditor_groups設定を使用して、どのグループ・メンバーシップがユーザーに監査役アクセスを許可するか。
-
/etc/gitlab/gitlab.rbを編集します:gitlab_rails['omniauth_providers'] = [ { name: "openid_connect", label: "Provider name", args: { name: "openid_connect", scope: ["openid","profile","email","groups"], response_type: "code", issuer: "<your_oidc_url>", discovery: true, client_auth_method: "query", uid_field: "<uid_field>", client_options: { identifier: "<your_oidc_client_id>", secret: "<your_oidc_client_secret>", redirect_uri: "<your_gitlab_url>/users/auth/openid_connect/callback", gitlab: { groups_attribute: "groups", auditor_groups: ["Auditor"] } } } } ] -
ファイルを保存し、変更を有効にするためにGitLab を再設定してください。
-
/home/git/gitlab/config/gitlab.ymlを編集します:production: &base omniauth: providers: - { name: 'openid_connect', label: 'Provider name', args: { name: 'openid_connect', scope: ['openid','profile','email','groups'], response_type: 'code', issuer: '<your_oidc_url>', discovery: true, client_auth_method: 'query', uid_field: '<uid_field>', client_options: { identifier: '<your_oidc_client_id>', secret: '<your_oidc_client_secret>', redirect_uri: '<your_gitlab_url>/users/auth/openid_connect/callback', gitlab: { groups_attribute: "groups", auditor_groups: ["Auditor"] } } } } -
ファイルを保存し、変更を有効にするためにGitLab を再設定してください。
管理者グループ
IdP は、OIDC レスポンスで GitLab にグループ情報を渡す必要があります。グループメンバーシップに基づいてユーザーを管理者として割り当てるためにこのレスポンスを使用するには、GitLabを識別するように設定します:
-
groups_attribute設定を使用して、OIDC レスポンスでグループを探す場所。 -
admin_groups設定を使用して、どのグループ・メンバーシップがユーザーに管理者アクセス権を付与するか。
-
/etc/gitlab/gitlab.rbを編集します:gitlab_rails['omniauth_providers'] = [ { name: "openid_connect", label: "Provider name", args: { name: "openid_connect", scope: ["openid","profile","email"], response_type: "code", issuer: "<your_oidc_url>", discovery: true, client_auth_method: "query", uid_field: "<uid_field>", client_options: { identifier: "<your_oidc_client_id>", secret: "<your_oidc_client_secret>", redirect_uri: "<your_gitlab_url>/users/auth/openid_connect/callback", gitlab: { groups_attribute: "groups", admin_groups: ["Admin"] } } } } ] -
ファイルを保存し、変更を有効にするためにGitLab を再設定してください。
-
/home/git/gitlab/config/gitlab.ymlを編集します:production: &base omniauth: providers: - { name: 'openid_connect', label: 'Provider name', args: { name: 'openid_connect', scope: ['openid','profile','email'], response_type: 'code', issuer: '<your_oidc_url>', discovery: true, client_auth_method: 'query', uid_field: '<uid_field>', client_options: { identifier: '<your_oidc_client_id>', secret: '<your_oidc_client_secret>', redirect_uri: '<your_gitlab_url>/users/auth/openid_connect/callback', gitlab: { groups_attribute: "groups", admin_groups: ["Admin"] } } } } -
ファイルを保存し、変更を有効にするためにGitLab を再設定してください。
トラブルシューティング
-
discoveryがtrueに設定されていることを確認してください。falseに設定した場合は、OpenID を動作させるために必要なすべての URL とキーを指定する必要があります。 -
システム時計を確認し、時刻が正しく同期されていることを確認します。
-
OmniAuth OpenID Connect のドキュメントに記載されているように、
issuerがディスカバリ URL のベース URL に対応していることを確認してください。例えば、https://accounts.google.comは URLhttps://accounts.google.com/.well-known/openid-configurationに使用されます。 -
client_auth_methodが定義されていない場合、またはbasicに設定されている場合、OpenID Connect クライアントは HTTP 基本認証を使用して OAuth 2.0 アクセストークンを送信します。userinfoエンドポイントを取得する際に 401 エラーが表示される場合は、OpenID Web サーバーの設定を確認してください。例えば、oauth2-server-phpの場合、Apache に設定パラメータを追加する必要があるかもしれません。