OpenID Connect을 인증 공급자로 사용하기

Tier: Free, Premium, Ultimate Offering: Self-managed

OpenID Connect를 OmniAuth 제공자로 사용하여 GitLab을 클라이언트 응용 프로그램으로 사용할 수 있습니다.

OpenID Connect OmniAuth 제공자를 활성화하려면 OpenID Connect 제공자에 응용 프로그램을 등록해야 합니다. OpenID Connect 제공자는 클라이언트의 세부 정보와 시크릿을 제공하여 사용하도록 합니다.

  1. GitLab 서버에서 구성 파일을 엽니다.

    Linux 패키지 설치의 경우:

    sudo editor /etc/gitlab/gitlab.rb
    

    자체 컴파일 설치의 경우:

    cd /home/git/gitlab
    sudo -u git -H editor config/gitlab.yml
    
  2. 공통 설정을 구성하여 openid_connect을 단일 로그인 공급자로 추가합니다. 이를 통해 기존 GitLab 계정이 없는 사용자를 위해 실시간 계정 설정이 가능해집니다.

  3. 제공자 구성을 추가합니다.

    Linux 패키지 설치의 경우:

    gitlab_rails['omniauth_providers'] = [
      {
        name: "openid_connect", # 이 매개변수를 변경하지 마세요
        label: "공급자 이름", # 로그인 버튼의 선택적 레이블, 기본값은 "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"
          }
        }
      }
    ]
    

    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'
       }
     }
    }
    
    note
    OIDC와 여러 신원 제공자를 함께 사용하는 자세한 내용은 이슈 5992를 참조하세요.

    자체 컴파일 설치의 경우:

      - { name: 'openid_connect', # 이 매개변수를 변경하지 마세요
          label: '공급자 이름', # 로그인 버튼의 선택적 레이블, 기본값은 "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'
            }
          }
        }
    
    note
    각 구성 옵션에 대한 자세한 내용은 OmniAuth OpenID Connect 사용 설명서OpenID Connect Core 1.0 사양을 참조하세요.
  4. 제공자 구성에 대해 제공자의 값들을 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>.
    • discoverytrue로 설정된 경우, OpenID Connect 제공자는 기본값이 false<your_oidc_url>/.well-known/openid-configuration을 사용하여 자동으로 클라이언트 옵션을 발견하려고 시도합니다.
    • client_auth_method (선택적)은 OpenID Connect 제공자와의 클라이언트 인증에 사용되는 방법을 지정합니다.
      • 지원되는 값은:
        • basic - HTTP 기본 인증.
        • jwt_bearer - JWT 기반 인증 (개인 키 및 클라이언트 시크릿 서명).
        • mtls - 상호 TLS 또는 X.509 인증서 유효성 검사.
        • 다른 값 중 하나는 요청 본문에 클라이언트 ID 및 시크릿을 게시합니다.
      • 지정하지 않은 경우, 이 값은 기본값으로 basic을 사용합니다.
    • <uid_field> (선택적)은 user_info.raw_attributes에서 uid의 값으로 정의하는 필드 이름입니다 (예: preferred_username). 이 값을 제공하지 않거나 구성된 값이 user_info.raw_attributes 세부 정보에서 누락된 경우, uidsub 필드를 사용합니다.
    • send_scope_to_token_endpoint은 기본적으로 true이므로 scope 매개변수는 일반적으로 토큰 엔드포인트에 포함됩니다. 그러나 OpenID Connect 제공자가 이러한 요청에서 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으로 리디렉션하는 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입니다.
  5. 구성 파일을 저장합니다.
  6. 변경 사항이 적용되려면:

    • Linux 패키지를 사용하여 GitLab을 설치한 경우, GitLab 재구성을 실행합니다.
    • GitLab 설치를 자체 컴파일한 경우, GitLab 재시작을 실행합니다.

로그인 페이지에서 일반 로그인 양식 아래에 OpenID Connect 옵션이 표시됩니다. 이 옵션을 선택하여 인증 프로세스를 시작합니다. OpenID Connect 제공자는 확인이 필요한 경우 GitLab 애플리케이션에 로그인하도록 요청합니다. 그러면 GitLab로 리디렉션되어 로그인됩니다.

예시 구성

다음 구성은 Linux 패키지 설치 시 OpenID를 다양한 제공업체와 함께 설정하는 방법을 설명합니다.

Google 구성

자세한 내용은 Google 문서를 참조하세요:

gitlab_rails['omniauth_providers'] = [
  {
    name: "openid_connect", # 이 매개변수를 변경하지 마세요
    label: "Google OpenID", # 선택 사항. 로그인 버튼의 기본 레이블은 "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 identity platform (v2) endpoints를 사용합니다. 시작하려면 Azure Portal에 로그인하세요. 앱에 대해 다음 정보가 필요합니다:

  • 테넌트 ID. 이미 가지고 있을 수 있습니다. 자세한 내용은 Microsoft Azure Tenant 문서를 참조하세요.
  • 클라이언트 ID와 클라이언트 시크릿. 앱에 대한 테넌트 ID, 클라이언트 ID 및 클라이언트 시크릿을 얻으려면 Microsoft Quickstart Register an Application 문서의 지침을 따르세요.

Linux 패키지 설치를 위한 예시 구성 블록:

gitlab_rails['omniauth_providers'] = [
  {
    name: "openid_connect", # 이 매개변수를 변경하지 마세요
    label: "Azure OIDC", # 선택 사항. 로그인 버튼의 기본 레이블은 "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 Portal에 로그인하세요. 앱에 대해 다음 정보가 필요합니다:

  • 테넌트 ID. 이미 가지고 있을 수 있습니다. 자세한 내용은 Microsoft Azure Tenant 문서를 참조하세요.
  • 클라이언트 ID와 클라이언트 시크릿. 앱에 대한 클라이언트 ID 및 클라이언트 시크릿을 얻으려면 Microsoft tutorial 문서의 지침을 따르세요.
  • 사용자 플로우 또는 정책 이름. Microsoft tutorial 문서의 지침에 따라 사용자 플로우 또는 정책 이름을 얻으세요.

앱 구성:

  1. 앱 ‘리디렉션 URI’ 설정. 예를 들어 GitLab 도메인이 gitlab.example.com인 경우, 앱 ‘리디렉션 URI’를 https://gitlab.example.com/users/auth/openid_connect/callback로 설정합니다.

  2. ID 토큰 사용 설정.

  3. 다음 API 권한을 앱에 추가합니다:

    • openid
    • offline_access

사용자 정의 정책 구성

Azure B2C는 유저 로그인의 비즈니스 로직을 정의하는 두 가지 방법을 제공합니다(https://learn.microsoft.com/en-us/azure/active-directory-b2c/user-flow-overview):

유저 흐름은 email 클레임을 전송하지 않습니다. 따라서 기본 사용자 플로우는 allow_single_sign_on 또는 auto_link_user 매개변수를 사용하지 않습니다. 기본 Azure B2C 정책으로는 GitLab이 email 주소로 새 계정을 만들거나 기존 계정과 연결할 수 없습니다.

먼저 사용자 정책을 만드세요.

Microsoft의 지침은 사용자 정책 스타터 팩SocialAndLocalAccounts를 사용하지만 LocalAccounts은 로컬 Active Directory 계정에 대해 인증합니다. 정책을 업로드하기 전에 다음을 수행하세요:

  1. email 클레임을 내보내려면 SignUpOrSignin.xml을 수정하세요. 다음 줄:

    <OutputClaim ClaimTypeReferenceId="email" />
    

    다음으로 바꿉니다:

    <OutputClaim ClaimTypeReferenceId="signInNames.emailAddress" PartnerClaimType="email" />
    
  2. B2C와의 OIDC discovery를 위해 발행자가 OIDC 사양과 호환되도록 정책을 구성하세요. 토큰 호환성 설정을 참조하세요. JwtIssuer에서 TrustFrameworkBase.xmlIssuanceClaimPatternAuthorityWithTfp로 설정하세요:

    <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>
            ...
    
  3. 정책을 업로드. 기존 정책을 업데이트하는 경우 기존 파일을 덮어쓰세요.

  4. 발행자 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로 표시됩니다.

    끝에 슬래시를 포함하세요.

  5. OIDC discovery 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
    

    예를 들어 도메인example.b2clogin.com이고 테넌트 ID가 fc40c736-476c-4da1-b489-ee48cee84386인 경우 다음과 같이 발행자를 추출하기 위해 curljq를 사용할 수 있습니다:

    $ 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/"
    
  6. signup_signin에 대한 사용자 정책을 사용하는 발행자 URL을 구성하세요. 예를 들어, 다음은 Linux 패키지 설치를 위해 b2c_1a_signup_signin에 대한 사용자 정책으로 구성된 예입니다:

    gitlab_rails['omniauth_providers'] = [
    {
      name: "openid_connect", # 이 매개변수를 변경하지 마세요
      label: "Azure B2C OIDC", # 선택 사항. 로그인 버튼의 기본 레이블은 "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와 일치하도록 확인하세요.
  • 앱에 https://jwt.ms를 리디렉트 URI로 추가하고 사용자 정책 테스터를 사용하세요. 페이로드에 사용자의 이메일 액세스와 일치하는 email이 포함되도록 확인하세요.
  • 사용자 정책을 활성화한 후 사용자가 로그인을 시도한 후 “잘못된 사용자 이름 또는 비밀번호”가 표시될 수 있습니다. 이는 IdentityExperienceFramework 앱의 구성 문제일 수 있습니다. Microsoft 코멘트에서 해당 앱 매니페스트에 다음 설정이 포함되어 있는지 확인해야 한다고 제안합니다:

    • "accessTokenAcceptedVersion": null
    • "signInAudience": "AzureADMyOrg"

    이 구성은 IdentityExperienceFramework 앱 생성 시 사용한 지원 계정 유형 설정에 해당합니다.

Keycloak 구성

GitLab은 HTTPS를 사용하는 OpenID 제공자와 작동합니다. Keycloak 서버를 HTTP를 사용하는 것으로 설정할 수는 있지만, GitLab은 HTTPS를 사용하는 Keycloak 서버와만 통신할 수 있습니다.

Keycloak을 공개 키 암호화 알고리즘(예: RSA256 또는 RSA512)을 사용하도록 구성하세요. 공개 키 암호화 알고리즘은 다음과 같습니다:

  • 구성하기 쉽습니다.
  • 개인 키 누출이 심각한 보안 문제를 야기하기 때문에 더 안전합니다.
  1. Keycloak 관리 콘솔을 엽니다.
  2. 렐름 설정 > 토큰 > 기본 서명 알고리즘을 선택하세요.
  3. 서명 알고리즘을 구성하세요.

리눅스 패키지 설치용 예제 구성 블록:

gitlab_rails['omniauth_providers'] = [
  {
    name: "openid_connect", # 이 매개변수는 변경하지 마세요
    label: "Keycloak", # 로그인 버튼에 대한 선택적 레이블, 기본값은 "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에서 소개되었습니다.
caution
다음 지침은 완성을 위해 포함되었으며 절대로 대칭 키 암호화를 사용하지 마세요.

대칭 키 암호화를 사용하려면:

  1. Keycloak 데이터베이스에서 비밀 키를 추출합니다. Keycloak은 웹 인터페이스에서이 값을 노출하지 않습니다. 웹 인터페이스에 표시되는 클라이언트 비밀은 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)를 위한 것입니다. 우리는 이 값을 구성에 사용합니다.

  2. 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
    
  3. 이 base64로 인코딩된 비밀을 jwt_secret_base64에 지정하세요. 예를 들어:

    gitlab_rails['omniauth_providers'] = [
      {
        name: "openid_connect", # 이 매개변수는 변경하지 마세요
        label: "Keycloak", # 로그인 버튼에 대한 선택적 레이블, 기본값은 "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 오류가 나타나면, 올바른 비밀을 지정하지 않았을 가능성이 있습니다.

Casdoor

GitLab은 HTTPS를 사용하는 OpenID 제공자와 작동합니다. Casdoor를 통해 OpenID를 사용하여 GitLab에 연결하려면 HTTPS를 사용하세요.

앱을 위해 Casdoor에서 다음 단계를 완료하세요:

  1. 클라이언트 ID 및 클라이언트 비밀 값을 가져옵니다.
  2. 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", # 이 매개변수를 변경하지 마십시오
      label: "Casdoor", # 로그인 버튼의 선택 사항 라벨, 기본값은 "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', # 이 매개변수를 변경하지 마십시오
      label: 'Casdoor', # 로그인 버튼의 선택 사항 라벨, 기본값은 "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를 명시적으로 설정해야 합니다.

다음 시나리오 중 하나에 해당하는 경우에 이렇게 해야 합니다:

note
이 기능은 OIDC 그룹 멤버십에 따라 사용자 구성과 호환되지 않습니다. 자세한 내용은 issue 408248를 참조하세요.

다음 예제 구성은 2FA를 적용한 인증 수준을 제공하는 방법을 보여줍니다.

Linux 패키지 설치용:

gitlab_rails['omniauth_providers'] = [
  {
    name: "openid_connect",
    label: "Provider name", # 로그인 버튼의 선택 사항 라벨, 기본값은 "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", # 로그인 버튼의 선택 사항 라벨, 기본값은 "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', # 로그인 버튼의 선택 사항 라벨, 기본값은 "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', # 로그인 버튼의 선택 사항 라벨, 기본값은 "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 그룹 멤버십에 기반한 사용자 구성

Tier: Premium, Ultimate Offering: GitLab.com, Self-managed, GitLab Dedicated

OIDC 그룹 멤버십을 다음과 같이 구성할 수 있습니다:

  • 특정 그룹의 구성원으로 사용자를 필요로 함.
  • 그룹 멤버십에 따라 사용자에게 외부, 관리자 또는 감사자 역할을 할당함.

GitLab은 각 로그인 시에 이러한 그룹을 확인하고 사용자 속성을 필요에 따라 업데이트합니다. 이 기능은 사용자를 자동으로 GitLab 그룹에 추가하는 것을 허용하지 않습니다.

필요 그룹

당신의 식별 공급자(IdP)는 OIDC 응답에서 그룹 정보를 GitLab에 전달해야 합니다. 특정 그룹의 구성원으로 사용자를 필요로 하는 경우 이 응답을 사용하려면 다음을 구성하세요:

  • groups_attribute 설정을 사용하여 OIDC 응답에서 그룹을 찾을 위치.
  • required_groups 설정을 사용하여 로그인에 필요한 그룹 멤버십을 식별.

required_groups를 설정하지 않거나 설정을 비워 둔 경우 OIDC를 통해 인증된 모든 사용자가 GitLab을 사용할 수 있습니다.

Linux 패키지(Omnibus)
  1. /etc/gitlab/gitlab.rb 파일을 편집하세요:

    gitlab_rails['omniauth_providers'] = [
      {
        name: "openid_connect",
        label: "공급자 이름",
        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"]
            }
          }
        }
      }
    ]
    
  2. 파일을 저장하고 변경 사항이 적용되도록 GitLab 다시 구성하세요.

직접 컴파일(Self-compiled, 소스)
  1. /home/git/gitlab/config/gitlab.yml 파일을 편집하세요:

    production: &base
      omniauth:
        providers:
         - { name: 'openid_connect',
             label: '공급자 이름',
          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"]
              }
            }
          }
        }
    
  2. 파일을 저장하고 변경 사항이 적용되도록 GitLab 다시 구성하세요.

외부 그룹

당신의 식별 공급자(IdP)는 OIDC 응답에서 그룹 정보를 GitLab에 전달해야 합니다. 그룹 멤버십에 따라 사용자를 외부 사용자로 식별하려면 다음을 구성하세요:

  • groups_attribute 설정을 사용하여 OIDC 응답에서 그룹을 찾을 위치.
  • external_groups 설정을 사용하여 사용자를 외부 사용자로 식별하는 데 사용할 그룹 멤버십 식별.
Linux 패키지(Omnibus)
  1. /etc/gitlab/gitlab.rb 파일을 편집하세요:

    gitlab_rails['omniauth_providers'] = [
      {
        name: "openid_connect",
        label: "공급자 이름",
        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"]
            }
          }
        }
      }
    ]
    
  2. 파일을 저장하고 변경 사항이 적용되도록 GitLab 다시 구성하세요.

직접 컴파일(Self-compiled, 소스)
  1. /home/git/gitlab/config/gitlab.yml 파일을 편집하세요:

    production: &base
      omniauth:
        providers:
         - { name: 'openid_connect',
             label: '공급자 이름',
          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"]
              }
            }
          }
        }
    
  2. 파일을 저장하고 변경 사항이 적용되도록 GitLab 다시 구성하세요.

감사자 그룹

Tier: Premium, Ultimate Offering: Self-managed

당신의 식별 공급자(IdP)는 OIDC 응답에서 그룹 정보를 GitLab에 전달해야 합니다. 그룹 멤버십에 따라 사용자를 감사자로 지정하려면 다음을 구성하세요:

  • groups_attribute 설정을 사용하여 OIDC 응답에서 그룹을 찾을 위치.
  • auditor_groups 설정을 사용하여 사용자가 감사자 액세스를 부여하는 데 사용할 그룹 멤버십 식별.
Linux 패키지(Omnibus)
  1. /etc/gitlab/gitlab.rb 파일을 편집하세요:

    gitlab_rails['omniauth_providers'] = [
      {
        name: "openid_connect",
        label: "공급자 이름",
        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"]
            }
          }
        }
      }
    ]
    
  2. 파일을 저장하고 변경 사항이 적용되도록 GitLab 다시 구성하세요.

직접 컴파일(Self-compiled, 소스)
  1. /home/git/gitlab/config/gitlab.yml 파일을 편집하세요:

    production: &base
      omniauth:
        providers:
         - { name: 'openid_connect',
             label: '공급자 이름',
          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"]
              }
            }
          }
        }
    
  2. 파일을 저장하고 변경 사항이 적용되도록 GitLab 다시 구성하세요.

관리자 그룹

당신의 IdP는 그룹 정보를 OIDC 응답에 GitLab에 전달해야 합니다. 사용자를 그룹 멤버십에 따라 관리자로 지정하는 데에 이 응답을 사용하려면 다음을 구성하세요:

  • OIDC 응답에서 그룹을 찾을 위치를 groups_attribute 설정을 사용하여 지정합니다.
  • 어떤 그룹 멤버십이 사용자에게 관리자 액세스를 부여하는지 admin_groups 설정을 사용하여 지정합니다.
Linux 패키지 (Omnibus)
  1. /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"]
            }
          }
        }
      }
    ]
    
  2. 파일을 저장하고 GitLab을 다시 구성하여 변경 사항을 적용합니다.

직접 컴파일한 경우 (소스)
  1. /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"]
              }
            }
          }
        }
    
  2. 파일을 저장하고 GitLab을 다시 구성하여 변경 사항을 적용합니다.

문제 해결

  1. discoverytrue로 설정되어 있는지 확인하세요. false로 설정한 경우 OpenID가 작동하는 데 필요한 모든 URL 및 키를 지정해야 합니다.

  2. 시스템 시계가 제대로 동기화되었는지 확인하세요.

  3. OmniAuth OpenID Connect 문서에 언급된 대로 issuer가 Discovery URL의 기본 URL에 해당하는지 확인하세요. 예를 들어 https://accounts.google.comhttps://accounts.google.com/.well-known/openid-configuration와 같이 사용됩니다.

  4. OpenID Connect 클라이언트는 client_auth_method가 정의되지 않았거나 basic로 설정된 경우 OAuth 2.0 액세스 토큰을 보내기 위해 HTTP 기본 인증을 사용합니다. client_auth_method가 정의되지 않았거나 basic로 설정된 경우 userinfo 엔드포인트를 검색할 때 401 오류가 발생하는 경우 OpenID 웹 서버 구성을 확인하세요. 예를 들어, oauth2-server-php에 대해 Apache에 구성 매개변수를 추가해야 할 수 있습니다. (https://github.com/bshaffer/oauth2-server-php/issues/926#issuecomment-387502778)