Аутентификация в Gitlab через Keycloak OIDC¶
GitLab предлагает множество способов аутентификации, и одним из них является OpenID Connect (OIDC) через Keycloak. Рассмотрим, как настроить аутентификацию GitLab через Keycloak OIDC, чтобы обеспечить безопасный и удобный вход пользователей.
Настройка GitLab¶
Для начала необходимо внести изменения в конфигурационный файл GitLab. Добавьте следующие строки:
gitlab_rails['omniauth_enabled'] = true
gitlab_rails['omniauth_auto_link_user'] = ['openid_connect']
gitlab_rails['onmiauth_allow_single_sign_on'] = ['openid_connect']
gitlab_rails['omniauth_block_auto_created_users'] = false
# gitlab_rails['onmiauth_auto_link_ldap_user'] = true
gitlab_rails['omniauth_providers'] = [
{
name: "openid_connect", # do not change this parameter
label: "Keycloak LOGIN", # optional label for login button, defaults to "Openid Connect"
args: {
name: "openid_connect",
scope: ["openid","profile","email","gitlab"],
response_type: "code",
issuer: "https://keycloak.<domain>/realms/truedev",
discovery: true,
client_auth_method: "query",
uid_field: "id",
send_scope_to_token_endpoint: "false",
pkce: true,
client_options: {
identifier: "gitlab",
secret: "0Ui................Sy",
redirect_uri: "https://gitlab.<domain>/users/auth/openid_connect/callback"
}
}
}
]
Во freeipa Достаточно установить User Federation - LDAP searching and updating - Edit mode * : READONLY
Настройка Keycloak¶
Перейдите в меню "Clients" и создайте новый клиент для GitLab. Воспользуйтесь предыдущими постами для базовой настройки.
Установите следующие параметры:
Go to 'Clients' menu, and 'Create' new client Gitlab (see previous post for basic setup)
Settings:
Client ID * : gitlab-saml (такой же как issuer в gitlab настройках SAML)
Root URL : https://gitlab.<domain>
Valid redirect URIs : https://gitlab.<domain>/users/auth/saml/callback
IDP-Initiated SSO URL name : gitlab.<domain>
Master SAML Processing URL : https://gitlab.<domain>/users/auth/saml/callback
Name ID format : persistent
Include AuthnStatement : On
Sign documents : On
Sign assertions : On
Advanced:
Assertion Consumer Service POST Binding URL : https://gitlab.<domain>/users/auth/saml/callback
Roles:
Create role: gitlab:external
Первый вход¶
Важно: первый вход должен быть выполнен через LDAP. В противном случае возникнет ошибка "Signing in using your SSO account without a pre-existing GitLab account is not allowed." После первого входа можно будет использовать OIDC, или включить его вручную.
References:¶
- https://docs.gitlab.com/ee/administration/auth/oidc.html
- https://docs.gitlab.com/ee/integration/omniauth.html
- https://forum.gitlab.com/t/how-to-grant-users-admin-rights-when-logging-in-via-keycloak-oidc/81417
- https://docs.gitlab.com/ee/administration/auth/oidc.html#configure-users-based-on-oidc-group-membership