使用 Shibboleth 作为身份验证提供程序
- Tier: Free, Premium, Ultimate
- Offering: GitLab Self-Managed, GitLab Dedicated
使用 GitLab SAML 集成 来集成特定的 Shibboleth 身份提供程序 (IdPs)。对于 Shibboleth 联邦支持(发现服务),请使用本文档。
要在 GitLab 中启用 Shibboleth 支持,请使用 Apache 而不是 NGINX。Apache 使用 mod_shib2 模块进行 Shibboleth 身份验证,并将属性作为头发送到 OmniAuth Shibboleth 提供程序。
您可以使用 Linux 包中捆绑的 NGINX,通过反向代理设置在不同的实例上运行 Shibboleth 服务提供程序。但是,如果您不这样做,捆绑的 NGINX 很难配置。
要启用 Shibboleth OmniAuth 提供程序,您必须:
启用 Shibboleth:
-
保护 OmniAuth Shibboleth 回调 URL:
<Location /users/auth/shibboleth/callback> AuthType shibboleth ShibRequestSetting requireSession 1 ShibUseHeaders On require valid-user </Location> Alias /shibboleth-sp /usr/share/shibboleth <Location /shibboleth-sp> Satisfy any </Location> <Location /Shibboleth.sso> SetHandler shib </Location> -
排除 Shibboleth URL 的重写。添加
RewriteCond %{REQUEST_URI} !/Shibboleth.sso和RewriteCond %{REQUEST_URI} !/shibboleth-sp。示例配置:# Apache equivalent of Nginx try files RewriteEngine on RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !/Shibboleth.sso RewriteCond %{REQUEST_URI} !/shibboleth-sp RewriteRule .* http://127.0.0.1:8080%{REQUEST_URI} [P,QSA] RequestHeader set X_FORWARDED_PROTO 'https' -
将 Shibboleth 添加到
/etc/gitlab/gitlab.rb作为 OmniAuth 提供程序。 用户属性从 Apache 反向代理发送到 GitLab,作为带有 Shibboleth 属性映射名称的头部。 因此args哈希的值应该是"HTTP_ATTRIBUTE"的形式。 哈希中的键是 OmniAuth::Strategies::Shibboleth 类 的参数,并由omniauth-shibboleth-reduxgem 文档记录(注意记录 GitLab 打包的 gem 版本)。文件应如下所示:
external_url 'https://gitlab.example.com' gitlab_rails['internal_api_url'] = 'https://gitlab.example.com' # disable Nginx nginx['enable'] = false gitlab_rails['omniauth_allow_single_sign_on'] = true gitlab_rails['omniauth_block_auto_created_users'] = false gitlab_rails['omniauth_providers'] = [ { "name" => "shibboleth", "label" => "Text for Login Button", "args" => { "shib_session_id_field" => "HTTP_SHIB_SESSION_ID", "shib_application_id_field" => "HTTP_SHIB_APPLICATION_ID", "uid_field" => 'HTTP_EPPN', "name_field" => 'HTTP_CN', "info_fields" => { "email" => 'HTTP_MAIL'} } } ]如果您的某些用户似乎通过 Shibboleth 和 Apache 进行了身份验证,但 GitLab 以包含"电子邮件无效"的 URI 拒绝其帐户,那么您的 Shibboleth 身份提供程序或属性权威可能正在断言多个电子邮件地址。在这种情况下,考虑将
multi_values参数设置为first。 -
使更改生效:
在登录页面上,常规登录表单下方现在应该有一个 使用 Shibboleth 登录 图标。选择该图标开始身份验证过程。您将被重定向到 Shibboleth 模块配置的相应 IdP 服务器。如果一切顺利,您将返回到 GitLab 并登录。