참고 사이트 : https://edenmal.moe/post/2018/GitLab-Keycloak-SAML-2-0-OmniAuth-Provider/
사전 조건 : Docker 환경 구성
터미널에서 아래 명령어 입력
docker run -p 8080:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin quay.io/keycloak/keycloak:11.0.0 |
기본 8080 포트 구성. 포트 변경 필요시 해당 부분 변경 <container port>:<host port>
Key | Value |
---|---|
Client ID * |
|
Client Protocol | saml |
Client SAML Endpoint |
|
Key | Value |
---|---|
Client ID |
|
Name |
|
Description |
|
Enabled | ON |
Consent Required | OFF |
Login Theme | base |
Client Protocol | saml |
Include AuthnStatement | ON |
Include OneTimeUse Condition | OFF |
Sign Documents | ON |
Optimize REDIRECT signing key lookup | OFF |
Sign Assertions | ON |
Signature Algorithm | RSA_SHA26 |
SAML Signature Key Name | KEY_ID |
Canonicalization Method | EXCLUSIVE |
Encrypt Assertions | OFF |
Client Signature Required | ON |
Force POST Binding | ON |
Front Channel Logout | ON |
Force Name ID Format | OFF |
Name ID Format | persistant |
Root URL |
|
Valid Redirect URIs |
|
Base URL |
|
Master SAML Processing URL |
|
IDP Initiated SSO URL Name |
|
IDP Initiated SSO Relay State |
####Fine Grain SAML Endpoint Configuration:
Key | Value |
---|---|
Assertion Consumer Service POST Binding URL |
|
Assertion Consumer Service Redirect Binding URL | |
Logout Service POST Binding URL | |
Logout Service Redirect Binding URL |
Role 이름 | Composite |
---|---|
gitlab.example.com:access | false |
gitlab.example.com:external | false |
Create 버튼 클릭하여 아래와 같이 생성
Name: name
Mapper Type: User Property
Property: Username
Friendly Name: Username
SAML Attribute Name: name
SAML Attribute NameFormat: Basic
Name: email
Mapper Type: User Property
Property: Email
Friendly Name: Email
SAML Attribute Name: email
SAML Attribute NameFormat: Basic
Name: first_name
Mapper Type: User Property
Property: FirstName
Friendly Name: First Name
SAML Attribute Name: first_name
SAML Attribute NameFormat: Basic
Name: last_name
Mapper Type: User Property
Property: LastName
Friendly Name: Last Name
SAML Attribute Name: name
SAML Attribute NameFormat: Basic
Name: roles
Mapper Type: Role list
Role attribute name: roles
Friendly Name: Roles
SAML Attribute NameFormat: Basic
Single Role Attribute: On
-----BEGIN CERTIFICATE-----로 시작하고 -----END CERTIFICATE-----로 끝나는 형식으로 입력
Gitlab에서 지원하는 알고리즘은 sha1이므로 해당 알고리즘 선택 후 fingerprint 생성
fingerprint 는 GitLab의 gitlab.rb에 등록되어야 함
### OmniAuth Settings ###! Docs: https://docs.gitlab.com/ee/integration/omniauth.html ... gitlab_rails['omniauth_enabled'] = true gitlab_rails['omniauth_allow_single_sign_on'] = ['saml'] gitlab_rails['omniauth_block_auto_created_users'] = false gitlab_rails['omniauth_auto_link_saml_user'] = true gitlab_rails['omniauth_providers'] = [ { "name" => "saml", "label" => "Get Auth", ###<보여지는 버튼 이름> "groups_attribute" => "roles", "external_groups" => ['<roles tab에 구성한 external 이름'], "args" => { assertion_consumer_service_url: '<gitlab url>/users/auth/saml/callback', idp_cert_fingerprint: '생성한 fingerprint', idp_sso_target_url: '<keycloak url>/auth/realms/<realm 이름>/protocol/saml/clients/<client의 id>', allowed_clock_drift: 5, issuer: '<client 이름>', attribute_statements: { first_name: ['first_name'], last_name: ['last_name'], name: ['name'], username: ['name'], email: ['email'] }, name_identifier_format: 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent' } } ] |
$ gitlab-ctl reconfigure |
Sign in with 버튼을 클릭할 경우 Realm 로그인 창이 나타나고 계정을 입력하여 로그인 (테마를 base로 하지 않고 keycloak로 선택할 경우 아래와 같은 화면이 나타남)
모든 로그인 시도는 SAML 서버로 리디렉션되므로 로컬 자격 증명을 사용하여 로그인 불가. 하나 이상의 SAML 사용자에게 관리자 권한이 있는지 확인 필요.
1. /etc/gitlab/gitlab.rb 파일 수정
gitlab_rails['omniauth_auto_sign_in_with_provider'] = 'saml' |
2. 변경 사항 재적용
gitlab-ctl reconfigure |