GitHub 를 OAuth 2.0 인증 공급자로 사용하기
GitLab v19.5Offering: GitLab Self-Managed
요약
GitLab 인스턴스를 GitHub.com 및 GitHub Enterprise와 통합할 수 있습니다. GitHub OmniAuth 공급자를 활성화하려면 GitHub에서 발급한 OAuth 2.0 클라이언트 ID와 클라이언트 시크릿이 필요합니다.
GitLab 인스턴스를 GitHub.com 및 GitHub Enterprise와 통합할 수 있습니다. GitHub에서 프로젝트를 가져오거나, GitHub 자격 증명으로 GitLab에 로그인할 수 있습니다.
GitHub에서 OAuth 앱 생성#
GitHub OmniAuth 공급자를 활성화하려면 GitHub에서 발급한 OAuth 2.0 클라이언트 ID와 클라이언트 시크릿이 필요합니다.
- GitHub에 로그인합니다.
- OAuth 앱을 생성하고 다음 정보를 입력합니다.
- GitLab 인스턴스의 URL. 예:
https://gitlab.example.com. - 인증 콜백 URL. 예:
https://gitlab.example.com/users/auth/github/callback. GitLab 인스턴스가 기본이 아닌 포트를 사용하는 경우 포트 번호를 포함합니다.
- GitLab 인스턴스의 URL. 예:
보안 취약점 확인#
일부 통합에서는 OAuth 2 은닉 리디렉션
취약점으로 GitLab 계정이 침해될 수 있습니다.
이 취약점을 완화하려면 GitLab 인스턴스 URL에 전체 /users/auth/github/callback
경로를 추가합니다.
다만 GitHub는 redirect_uri의 서브도메인 부분을 검증하지 않습니다.
따라서 웹사이트의 서브도메인에서 발생하는 서브도메인 탈취, XSS, 오픈 리디렉션이
은닉 리디렉션 공격을 가능하게 할 수 있습니다.
GitLab에서 GitHub OAuth 활성화#
-
공통 설정을 구성하여
github를 SSO(Single Sign-On) 공급자로 추가합니다. 이렇게 하면 기존 GitLab 계정이 없는 사용자에 대해 JIT(Just-In-Time) 계정 프로비저닝이 활성화됩니다. -
다음 정보를 사용해 GitLab 설정 파일을 수정합니다.
GitHub 설정 GitLab 설정 파일의 값 설명 Client ID YOUR_APP_IDOAuth 2.0 클라이언트 ID Client secret YOUR_APP_SECRETOAuth 2.0 클라이언트 시크릿 URL https://github.example.com/GitHub 배포 URL -
Linux 패키지 설치의 경우:
-
/etc/gitlab/gitlab.rb파일을 엽니다.GitHub.com의 경우 다음 섹션을 업데이트합니다.
gitlab_rails['omniauth_providers'] = [ { name: "github", # label: "Provider name", # optional label for login button, defaults to "GitHub" app_id: "YOUR_APP_ID", app_secret: "YOUR_APP_SECRET", args: { scope: "user:email" } } ]GitHub Enterprise의 경우 다음 섹션을 업데이트하고
https://github.example.com/를 사용 중인 GitHub URL로 바꿉니다.gitlab_rails['omniauth_providers'] = [ { name: "github", # label: "Provider name", # optional label for login button, defaults to "GitHub" app_id: "YOUR_APP_ID", app_secret: "YOUR_APP_SECRET", url: "https://github.example.com/", args: { scope: "user:email" } } ] -
파일을 저장하고 GitLab을 재구성합니다.
-
-
셀프 컴파일 설치의 경우:
-
config/gitlab.yml파일을 엽니다.GitHub.com의 경우 다음 섹션을 업데이트합니다.
- { name: 'github', # label: 'Provider name', # optional label for login button, defaults to "GitHub" app_id: 'YOUR_APP_ID', app_secret: 'YOUR_APP_SECRET', args: { scope: 'user:email' } }GitHub Enterprise의 경우 다음 섹션을 업데이트하고
https://github.example.com/를 사용 중인 GitHub URL로 바꿉니다.- { name: 'github', # label: 'Provider name', # optional label for login button, defaults to "GitHub" app_id: 'YOUR_APP_ID', app_secret: 'YOUR_APP_SECRET', url: "https://github.example.com/", args: { scope: 'user:email' } } -
파일을 저장하고 GitLab을 재시작합니다.
-
-
-
GitLab 로그인 페이지를 새로고침합니다. 로그인 폼 아래에 GitHub 아이콘이 표시됩니다.
-
아이콘을 선택합니다. GitHub에 로그인하고 GitLab 애플리케이션을 승인합니다.
문제 해결#
자체 서명 인증서를 사용하는 GitHub Enterprise에서 가져오기 실패#
자체 서명 인증서를 사용하는 GitHub Enterprise에서 프로젝트를 가져오면 가져오기가 실패합니다.
이 문제를 해결하려면 SSL 검증을 비활성화해야 합니다.
-
설정 파일에서
verify_ssl을false로 설정합니다.-
Linux 패키지 설치의 경우:
gitlab_rails['omniauth_providers'] = [ { name: "github", # label: "Provider name", # optional label for login button, defaults to "GitHub" app_id: "YOUR_APP_ID", app_secret: "YOUR_APP_SECRET", url: "https://github.example.com/", verify_ssl: false, args: { scope: "user:email" } } ] -
셀프 컴파일 설치의 경우:
- { name: 'github', # label: 'Provider name', # optional label for login button, defaults to "GitHub" app_id: 'YOUR_APP_ID', app_secret: 'YOUR_APP_SECRET', url: "https://github.example.com/", verify_ssl: false, args: { scope: 'user:email' } }
-
-
GitLab 서버에서 전역 Git
sslVerify옵션을false로 변경합니다.-
Linux 패키지 설치의 경우:
gitaly['configuration'] = { git: { config: [ { key: "http.sslVerify", value: "false" }, ], }, } -
셀프 컴파일 설치의 경우, Gitaly 설정(
gitaly.toml)을 수정합니다.[[git.config]] key = "http.sslVerify" value = "false"
-
-
Linux 패키지로 설치한 경우 GitLab을 재구성하고, 셀프 컴파일로 설치한 경우 GitLab을 재시작합니다.
GitHub Enterprise로 로그인 시 500 오류 발생#
이 오류는 GitLab 인스턴스와 GitHub Enterprise 간 네트워크 연결 문제로 발생할 수 있습니다.
연결 문제를 확인하려면 다음을 수행합니다.
-
GitLab 서버의
production.log에서 다음 오류를 확인합니다.Faraday::ConnectionFailed (execution expired) -
rails 콘솔을 시작하고 다음 명령을 실행합니다.
<github_url>을 사용 중인 GitHub Enterprise 인스턴스의 URL로 바꿉니다.uri = URI.parse("https://<github_url>") # replace `GitHub-URL` with the real one here http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = 1 response = http.request(Net::HTTP::Get.new(uri.request_uri)) -
비슷한
execution expired오류가 반환되면 연결 문제로 인한 오류임이 확인된 것입니다. GitLab 서버가 GitHub Enterprise 인스턴스에 접근할 수 있는지 확인합니다.
기존 GitLab 계정 없이 GitHub 계정으로 로그인하는 것은 허용되지 않음#
GitLab에 로그인하면 다음 오류가 표시됩니다.
Signing in using your GitHub account without a pre-existing
GitLab account is not allowed. Create a GitLab account first,
and then connect it to your GitHub account
이 문제를 해결하려면 GitLab에서 GitHub 로그인을 활성화해야 합니다.
- 오른쪽 위 모서리에서 아바타를 선택합니다.
- Edit profile을 선택합니다.
- 왼쪽 사이드바에서 Access > Password and authentication을 선택합니다.
- Service sign-in 섹션에서 Connect to GitHub을 선택합니다.