Tier: 基础版, 专业版, 旗舰版
Offering: 私有化部署
本页面描述了如何为极狐GitLab私有化部署设置实例范围的 SAML 单点登录(SSO)。
您可以配置极狐GitLab充当 SAML 服务提供者(SP)。这允许极狐GitLab从 SAML 身份提供者(IdP)消耗断言,例如 Okta,以验证用户。
要在 JihuLab.com 上设置 SAML,请参阅 GitLab.com 群组的 SAML SSO 。
有关以下内容的更多信息:
配置极狐GitLab中的 SAML 支持#
Linux package (Omnibus) Helm chart (Kubernetes) Docker Self-compiled (source)
确保极狐GitLab已 配置为使用 HTTPS 。
配置 通用设置 以添加 saml 作为单点登录提供者。这启用即时
帐户预配功能,适用于没有现有极狐GitLab帐户的用户。
要允许您的用户使用 SAML 注册而无需手动创建帐户,请编辑 /etc/gitlab/gitlab.rb :
gitlab_rails [ 'omniauth_allow_single_sign_on' ] = [ 'saml' ]
gitlab_rails [ 'omniauth_block_auto_created_users' ] = false
可选。您应自动将首次 SAML 登录与现有极狐GitLab用户连接,如果他们的电子邮件地址匹配。要做到这一点,请在 /etc/gitlab/gitlab.rb 中添加以下设置:
gitlab_rails [ 'omniauth_auto_link_saml_user' ] = true
只有极狐GitLab帐户的主要电子邮件地址会与 SAML 响应中的电子邮件进行匹配。
或者,用户可以通过 为现有用户启用 OmniAuth 手动将他们的 SAML 身份链接到现有的极狐GitLab帐户。
配置以下属性,以便您的 SAML 用户无法更改它们:
NameID 。
使用 omniauth_auto_link_saml_user 时的 Email 。
如果用户可以更改这些属性,他们可以以其他授权用户的身份登录。
请参阅您的 SAML IdP 文档以了解如何使这些属性不可更改。
编辑 /etc/gitlab/gitlab.rb 并添加提供者配置:
1 gitlab_rails [ 'omniauth_providers' ] = [
2 {
3 name : "saml" ,
4 label : "Provider name" , # optional label for login button, defaults to "Saml"
5 args : {
6 assertion_consumer_service_url : "https://gitlab.example.com/users/auth/saml/callback" ,
7 idp_cert_fingerprint : "2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6" ,
8 idp_sso_target_url : "https://login.example.com/idp" ,
9 issuer : "https://gitlab.example.com" ,
10 name_identifier_format : "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"
11 }
12 }
13 ]
参数 描述 assertion_consumer_service_url 极狐GitLab HTTPS 端点(将 /users/auth/saml/callback 附加到极狐GitLab安装的 HTTPS URL)。 idp_cert_fingerprint 您的 IdP 值。要从证书生成 SHA256 指纹,请参阅 计算指纹 。 idp_sso_target_url 您的 IdP 值。 issuer 更改为唯一名称,用于向 IdP 标识应用程序。 name_identifier_format 您的 IdP 值。
保存文件并重新配置极狐GitLab:
sudo gitlab-ctl reconfigure
确保极狐GitLab已 配置为使用 HTTPS 。
配置 通用设置 以添加 saml 作为单点登录提供者。这启用即时
帐户预配功能,适用于没有现有极狐GitLab帐户的用户。
导出 Helm 值:
helm get values gitlab > gitlab_values.yaml
要允许您的用户使用 SAML 注册而无需手动创建帐户,请编辑 gitlab_values.yaml :
1 global :
2 appConfig :
3 omniauth :
4 enabled : true
5 allowSingleSignOn : [ 'saml' ]
6 blockAutoCreatedUsers : false
可选。您可以通过在 gitlab_values.yaml 中添加以下设置,自动将 SAML 用户与现有极狐GitLab用户链接,如果他们的电子邮件地址匹配:
global :
appConfig :
omniauth :
autoLinkSamlUser : true
或者,用户可以通过 为现有用户启用 OmniAuth 手动将他们的 SAML 身份链接到现有的极狐GitLab帐户。
配置以下属性,以便您的 SAML 用户无法更改它们:
NameID 。
使用 omniauth_auto_link_saml_user 时的 Email 。
如果用户可以更改这些属性,他们可以以其他授权用户的身份登录。
请参阅您的 SAML IdP 文档以了解如何使这些属性不可更改。
将以下内容放入名为 saml.yaml 的文件中,用作 Kubernetes 密钥 :
1 name : 'saml'
2 label : 'Provider name' # optional label for login button, defaults to "Saml"
3 args :
4 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback'
5 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6'
6 idp_sso_target_url : 'https://login.example.com/idp'
7 issuer : 'https://gitlab.example.com'
8 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
参数 描述 assertion_consumer_service_url 极狐GitLab HTTPS 端点(将 /users/auth/saml/callback 附加到极狐GitLab安装的 HTTPS URL)。 idp_cert_fingerprint 您的 IdP 值。要从证书生成 SHA256 指纹,请参阅 计算指纹 。 idp_sso_target_url 您的 IdP 值。 issuer 更改为唯一名称,用于向 IdP 标识应用程序。 name_identifier_format 您的 IdP 值。
创建 Kubernetes 密钥:
kubectl create secret generic -n < namespace > gitlab-saml --from-file = provider = saml.yaml
编辑 gitlab_values.yaml 并添加提供者配置:
global :
appConfig :
omniauth :
providers :
- secret : gitlab - saml
保存文件并应用新值:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
确保极狐GitLab已 配置为使用 HTTPS 。
配置 通用设置 以添加 saml 作为单点登录提供者。这启用即时
帐户预配功能,适用于没有现有极狐GitLab帐户的用户。
要允许您的用户使用 SAML 注册而无需手动创建帐户,请编辑 docker-compose.yml :
1 version : "3.6"
2 services :
3 gitlab :
4 environment :
5 GITLAB_OMNIBUS_CONFIG : |
6 gitlab_rails['omniauth_allow_single_sign_on'] = ['saml']
7 gitlab_rails['omniauth_block_auto_created_users'] = false
可选。您可以通过在 docker-compose.yml 中添加以下设置,自动将 SAML 用户与现有极狐GitLab用户链接,如果他们的电子邮件地址匹配:
1 version : "3.6"
2 services :
3 gitlab :
4 environment :
5 GITLAB_OMNIBUS_CONFIG : |
6 gitlab_rails['omniauth_auto_link_saml_user'] = true
或者,用户可以通过 为现有用户启用 OmniAuth 手动将他们的 SAML 身份链接到现有的极狐GitLab帐户。
配置以下属性,以便您的 SAML 用户无法更改它们:
NameID 。
使用 omniauth_auto_link_saml_user 时的 Email 。
如果用户可以更改这些属性,他们可以以其他授权用户的身份登录。
请参阅您的 SAML IdP 文档以了解如何使这些属性不可更改。
编辑 docker-compose.yml 并添加提供者配置:
1 version : "3.6"
2 services :
3 gitlab :
4 environment :
5 GITLAB_OMNIBUS_CONFIG : |
6 gitlab_rails['omniauth_providers'] = [
7 {
8 name: "saml",
9 label: "Provider name", # optional label for login button, defaults to "Saml"
10 args: {
11 assertion_consumer_service_url: "https://gitlab.example.com/users/auth/saml/callback",
12 idp_cert_fingerprint: "2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6",
13 idp_sso_target_url: "https://login.example.com/idp",
14 issuer: "https://gitlab.example.com",
15 name_identifier_format: "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"
16 }
17 }
18 ]
参数 描述 assertion_consumer_service_url 极狐GitLab HTTPS 端点(将 /users/auth/saml/callback 附加到极狐GitLab安装的 HTTPS URL)。 idp_cert_fingerprint 您的 IdP 值。要从证书生成 SHA256 指纹,请参阅 计算指纹 。 idp_sso_target_url 您的 IdP 值。 issuer 更改为唯一名称,用于向 IdP 标识应用程序。 name_identifier_format 您的 IdP 值。
保存文件并重新启动极狐GitLab:
确保极狐GitLab已 配置为使用 HTTPS 。
配置 通用设置 以添加 saml 作为单点登录提供者。这启用即时
帐户预配功能,适用于没有现有极狐GitLab帐户的用户。
要允许您的用户使用 SAML 注册而无需手动创建帐户,请编辑 /home/git/gitlab/config/gitlab.yml :
production : &base
omniauth :
enabled : true
allow_single_sign_on : [ "saml" ]
block_auto_created_users : false
可选。您可以通过在 /home/git/gitlab/config/gitlab.yml 中添加以下设置,自动将 SAML 用户与现有极狐GitLab用户链接,如果他们的电子邮件地址匹配:
production : &base
omniauth :
auto_link_saml_user : true
或者,用户可以通过 为现有用户启用 OmniAuth 手动将他们的 SAML 身份链接到现有的极狐GitLab帐户。
配置以下属性,以便您的 SAML 用户无法更改它们:
NameID 。
使用 omniauth_auto_link_saml_user 时的 Email 。
如果用户可以更改这些属性,他们可以以其他授权用户的身份登录。
请参阅您的 SAML IdP 文档以了解如何使这些属性不可更改。
编辑 /home/git/gitlab/config/gitlab.yml 并添加提供者配置:
1 omniauth :
2 providers :
3 - {
4 name : 'saml' ,
5 label : 'Provider name' , # optional label for login button, defaults to "Saml"
6 args : {
7 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
8 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
9 idp_sso_target_url : 'https://login.example.com/idp' ,
10 issuer : 'https://gitlab.example.com' ,
11 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
12 }
13 }
参数 描述 assertion_consumer_service_url 极狐GitLab HTTPS 端点(将 /users/auth/saml/callback 附加到极狐GitLab安装的 HTTPS URL)。 idp_cert_fingerprint 您的 IdP 值。要从证书生成 SHA256 指纹,请参阅 计算指纹 。 idp_sso_target_url 您的 IdP 值。 issuer 更改为唯一名称,用于向 IdP 标识应用程序。 name_identifier_format 您的 IdP 值。
保存文件并重新启动极狐GitLab:
# For systems running systemd
sudo systemctl restart gitlab.target
# For systems running SysV init
sudo service gitlab restart
在您的 SAML IdP 中注册极狐GitLab#
在您的 SAML IdP 中注册极狐GitLab SP,使用 issuer 中指定的应用程序名称。
要向 IdP 提供配置信息,请为应用程序构建元数据 URL。要为极狐GitLab构建元数据 URL,请将 users/auth/saml/metadata 附加到极狐GitLab安装的 HTTPS URL。例如:
https://gitlab.example.com/users/auth/saml/metadata
至少 IdP 必须 提供一个声明,包含用户的电子邮件地址
使用 email 或 mail 。有关其他可用声明的更多信息,请参阅
配置断言 。
在登录页面下方应该有一个 SAML 图标,位于常规登录表单下方。
选择图标以开始身份验证过程。如果身份验证成功,
您将返回到极狐GitLab并登录。
在您的 IdP 上配置 SAML#
要在您的 IdP 上配置 SAML 应用程序,您至少需要以下信息:
有关示例配置,请参阅 设置身份提供者 。
您的 IdP 可能需要其他配置。有关更多信息,请参阅
在您的 IdP 上为 SAML 应用程序进行额外配置 。
配置极狐GitLab以使用多个 SAML IdP#
您可以配置极狐GitLab以使用多个 SAML IdP,如果:
每个提供者都有一个唯一的名称设置,与 args 中的名称设置匹配。
提供者的名称用于:
在 OmniAuth 配置中基于提供者名称的属性。例如,
allowBypassTwoFactor 、allowSingleSignOn 和 syncProfileFromProvider 。
用于作为额外身份与每个现有用户关联。
assertion_consumer_service_url 与提供者名称匹配。
因为它无法从提供者名称推断,所以必须显式设置 strategy_class 。
当您配置多个 SAML IdP 时,为确保 SAML 群组链接正常工作,您必须配置所有 SAML IdP 以在 SAML 响应中包含群组属性。有关更多信息,请参阅 SAML 群组链接 。
要设置多个 SAML IdP:
Linux package (Omnibus) Helm chart (Kubernetes) Docker Self-compiled (source)
编辑 /etc/gitlab/gitlab.rb :
1 gitlab_rails [ 'omniauth_providers' ] = [
2 {
3 name : 'saml' , # This must match the following name configuration parameter
4 label : 'Provider 1' # Differentiate the two buttons and providers in the UI
5 args : {
6 name : 'saml' , # This is mandatory and must match the provider name
7 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' , # URL must match the name of the provider
8 strategy_class : 'OmniAuth::Strategies::SAML' ,
9 # Include all required arguments similar to a single provider
10 } ,
11 } ,
12 {
13 name : 'saml_2' , # This must match the following name configuration parameter
14 label : 'Provider 2' # Differentiate the two buttons and providers in the UI
15 args : {
16 name : 'saml_2' , # This is mandatory and must match the provider name
17 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml_2/callback' , # URL must match the name of the provider
18 strategy_class : 'OmniAuth::Strategies::SAML' ,
19 # Include all required arguments similar to a single provider
20 } ,
21 }
22 ]
要允许您的用户使用 SAML 注册而无需手动创建一个帐户,请添加以下值到您的配置:
gitlab_rails [ 'omniauth_allow_single_sign_on' ] = [ 'saml' , 'saml_2' ]
保存文件并重新配置极狐GitLab:
sudo gitlab-ctl reconfigure
将以下内容放入名为 saml.yaml 的文件中,用作第一个 SAML 提供者的 Kubernetes 密钥 :
1 name : 'saml' # At least one provider must be named 'saml'
2 label : 'Provider 1' # Differentiate the two buttons and providers in the UI
3 args :
4 name : 'saml' # This is mandatory and must match the provider name
5 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' # URL must match the name of the provider
6 strategy_class : 'OmniAuth::Strategies::SAML' # Mandatory
7 # Include all required arguments similar to a single provider
将以下内容放入名为 saml_2.yaml 的文件中,用作第二个 SAML 提供者的 Kubernetes 密钥 :
1 name : 'saml_2'
2 label : 'Provider 2' # Differentiate the two buttons and providers in the UI
3 args :
4 name : 'saml_2' # This is mandatory and must match the provider name
5 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml_2/callback' # URL must match the name of the provider
6 strategy_class : 'OmniAuth::Strategies::SAML' # Mandatory
7 # Include all required arguments similar to a single provider
可选。通过遵循相同的步骤设置额外的 SAML 提供者。
创建 Kubernetes 密钥:
kubectl create secret generic -n < namespace > gitlab-saml \
--from-file = saml = saml.yaml \
--from-file = saml_2 = saml_2.yaml
导出 Helm 值:
helm get values gitlab > gitlab_values.yaml
编辑 gitlab_values.yaml :
1 global :
2 appConfig :
3 omniauth :
4 providers :
5 - secret : gitlab - saml
6 key : saml
7 - secret : gitlab - saml
8 key : saml_2
要允许您的用户使用 SAML 注册而无需手动创建一个帐户,请添加以下值到您的配置:
global :
appConfig :
omniauth :
allowSingleSignOn : [ 'saml' , 'saml_2' ]
保存文件并应用新值:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
编辑 docker-compose.yml :
1 version : "3.6"
2 services :
3 gitlab :
4 environment :
5 GITLAB_OMNIBUS_CONFIG : |
6 gitlab_rails['omniauth_allow_single_sign_on'] = ['saml', 'saml1']
7 gitlab_rails['omniauth_providers'] = [
8 {
9 name: 'saml', # This must match the following name configuration parameter
10 label: 'Provider 1' # Differentiate the two buttons and providers in the UI
11 args: {
12 name: 'saml', # This is mandatory and must match the provider name
13 assertion_consumer_service_url: 'https://gitlab.example.com/users/auth/saml/callback', # URL must match the name of the provider
14 strategy_class: 'OmniAuth::Strategies::SAML',
15 # Include all required arguments similar to a single provider
16 },
17 },
18 {
19 name: 'saml_2', # This must match the following name configuration parameter
20 label: 'Provider 2' # Differentiate the two buttons and providers in the UI
21 args: {
22 name: 'saml_2', # This is mandatory and must match the provider name
23 assertion_consumer_service_url: 'https://gitlab.example.com/users/auth/saml_2/callback', # URL must match the name of the provider
24 strategy_class: 'OmniAuth::Strategies::SAML',
25 # Include all required arguments similar to a single provider
26 },
27 }
28 ]
要允许您的用户使用 SAML 注册而无需手动创建一个帐户,请添加以下值到您的配置:
1 version : "3.6"
2 services :
3 gitlab :
4 environment :
5 GITLAB_OMNIBUS_CONFIG : |
6 gitlab_rails['omniauth_allow_single_sign_on'] = ['saml', 'saml_2']
保存文件并重新启动极狐GitLab:
编辑 /home/git/gitlab/config/gitlab.yml :
1 production : &base
2 omniauth :
3 providers :
4 - {
5 name : 'saml' , # This must match the following name configuration parameter
6 label : 'Provider 1' # Differentiate the two buttons and providers in the UI
7 args : {
8 name : 'saml' , # This is mandatory and must match the provider name
9 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' , # URL must match the name of the provider
10 strategy_class : 'OmniAuth::Strategies::SAML' ,
11 # Include all required arguments similar to a single provider
12 } ,
13 }
14 - {
15 name : 'saml_2' , # This must match the following name configuration parameter
16 label : 'Provider 2' # Differentiate the two buttons and providers in the UI
17 args : {
18 name : 'saml_2' , # This is mandatory and must match the provider name
19 strategy_class : 'OmniAuth::Strategies::SAML' ,
20 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml_2/callback' , # URL must match the name of the provider
21 # Include all required arguments similar to a single provider
22 } ,
23 }
要允许您的用户使用 SAML 注册而无需手动创建一个帐户,请添加以下值到您的配置:
production : &base
omniauth :
allow_single_sign_on : [ "saml" , "saml_2" ]
保存文件并重新启动极狐GitLab:
# For systems running systemd
sudo systemctl restart gitlab.target
# For systems running SysV init
sudo service gitlab restart
设置身份提供者#
极狐GitLab对 SAML 的支持意味着您可以通过广泛的 IdP 登录到极狐GitLab。
极狐GitLab提供以下内容来设置 Okta 和 Google Workspace IdP,仅供指导使用。如果您对配置这些 IdP 有任何疑问,请联系您的提供者支持。
设置 Okta#
在 Okta 管理员部分选择 应用程序 。
在应用程序屏幕上,选择 创建应用程序集成 ,然后在下一个屏幕上选择 SAML 2.0 。
可选。从极狐GitLab Press 选择并添加一个徽标。
您必须裁剪并调整徽标大小。
完成 SAML 一般配置。输入:
"Single sign-on URL" :使用断言消费者服务 URL。
"Audience URI" :使用发行者。
NameID 。
断言 。
在反馈部分中,输入您是客户,并创建一个
用于内部使用的应用程序。
在新应用程序的配置文件顶部,选择 SAML 2.0 配置指南 。
注意 身份识别提供商 SSO URL 。使用此 URL 作为
在极狐GitLab配置文件中的 idp_sso_target_url 。
在退出 Okta 之前,确保您添加了您的用户和群组(如果有)。
设置 Microsoft Entra ID#
登录到 Microsoft Entra 管理中心。
创建非库应用程序。
为该应用程序配置 SSO。
您的 gitlab.rb 文件中的以下设置对应于 Microsoft Entra ID 字段:
gitlab.rb 设置Microsoft Entra ID 字段 issuer 标识符(实体 ID) assertion_consumer_service_url 回复 URL(断言消费者服务 URL) idp_sso_target_url 登录 URL idp_cert_fingerprint 指纹
设置以下属性:
唯一用户标识符(名称 ID) 为 user.objectID 。
额外声明 为 支持的属性 。
有关更多信息,请参阅 示例配置页面 。
设置其他 IdP#
一些 IdP 拥有关于如何在 SAML 配置中将其用作 IdP 的文档。例如:
Active Directory Federation Services (ADFS)
Auth0
如果您对在 SAML 配置中配置您的 IdP 有任何疑问,请联系
您的提供者支持。
配置断言#
Offering: JihuLab.com, 私有化部署
History
Microsoft Azure/Entra ID 属性支持在极狐GitLab 16.7 中引入。
字段 支持的默认键 邮件 (必填) email 、mail 、http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress 、http://schemas.microsoft.com/ws/2008/06/identity/claims/emailaddress 全名 name 、http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name 、http://schemas.microsoft.com/ws/2008/06/identity/claims/name 名字 first_name 、firstname 、firstName 、http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname 、http://schemas.microsoft.com/ws/2008/06/identity/claims/givenname 姓氏 last_name 、lastname 、lastName 、http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname 、http://schemas.microsoft.com/ws/2008/06/identity/claims/surname
当极狐GitLab从 SAML SSO 提供者接收到 SAML 响应时,极狐GitLab会在属性 name 字段中查找以下值:
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname"
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname"
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"
firstname
lastname
email
您必须在属性 Name 字段中正确包含这些值,以便极狐GitLab可以解析 SAML 响应。例如,极狐GitLab可以解析以下 SAML 响应片段:
由于 Name 属性设置为之前表中所需值之一,因此这是可以接受的。
1 < Attribute Name = " http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname " >
2 < AttributeValue > Alvin </ AttributeValue >
3 </ Attribute >
4 < Attribute Name = " http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname " >
5 < AttributeValue > Test </ AttributeValue >
6 </ Attribute >
7 < Attribute Name = " http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress " >
8 < AttributeValue > alvintest@example.com </ AttributeValue >
9 </ Attribute >
由于 Name 属性匹配之前表中的值,因此这是可以接受的。
1 < Attribute Name = " firstname " >
2 < AttributeValue > Alvin </ AttributeValue >
3 </ Attribute >
4 < Attribute Name = " lastname " >
5 < AttributeValue > Test </ AttributeValue >
6 </ Attribute >
7 < Attribute Name = " email " >
8 < AttributeValue > alvintest@example.com </ AttributeValue >
9 </ Attribute >
但是,极狐GitLab无法解析以下 SAML 响应片段:
由于 Name 属性中的值不是之前表中的支持值,因此不会被接受。
1 < Attribute Name = " http://schemas.xmlsoap.org/ws/2005/05/identity/claims/firstname " >
2 < AttributeValue > Alvin </ AttributeValue >
3 </ Attribute >
4 < Attribute Name = " http://schemas.xmlsoap.org/ws/2005/05/identity/claims/lastname " >
5 < AttributeValue > Test </ AttributeValue >
6 </ Attribute >
7 < Attribute Name = " http://schemas.xmlsoap.org/ws/2005/05/identity/claims/mail " >
8 < AttributeValue > alvintest@example.com </ AttributeValue >
9 </ Attribute >
由于 FriendlyName 有支持值,但 Name 属性没有,因此会失败。
1 < Attribute FriendlyName = " firstname " Name = " urn:oid:2.5.4.42 " >
2 < AttributeValue > Alvin </ AttributeValue >
3 </ Attribute >
4 < Attribute FriendlyName = " lastname " Name = " urn:oid:2.5.4.4 " >
5 < AttributeValue > Test </ AttributeValue >
6 </ Attribute >
7 < Attribute FriendlyName = " email " Name = " urn:oid:0.9.2342.19200300.100.1.3 " >
8 < AttributeValue > alvintest@example.com </ AttributeValue >
9 </ Attribute >
请参阅 attribute_statements :
根据 SAML 群组成员身份配置用户#
您可以:
极狐GitLab在每次 SAML 登录时检查这些群组,并根据需要更新用户属性。
此功能 不能 允许您自动将用户添加到极狐GitLab
群组 。
对这些群组的支持取决于:
前提条件:
您必须告诉极狐GitLab在哪里查找群组信息。为此,请确保
您的 IdP 服务器在常规 SAML 响应中发送特定的 AttributeStatement 。例如:
1 < saml: AttributeStatement >
2 < saml: Attribute Name = " Groups " >
3 < saml: AttributeValue xsi: type = " xs:string " > Developers </ saml: AttributeValue >
4 < saml: AttributeValue xsi: type = " xs:string " > Freelancers </ saml: AttributeValue >
5 < saml: AttributeValue xsi: type = " xs:string " > Admins </ saml: AttributeValue >
6 < saml: AttributeValue xsi: type = " xs:string " > Auditors </ saml: AttributeValue >
7 </ saml: Attribute >
8 </ saml: AttributeStatement >
属性名称必须包含用户所属的群组。
要告诉极狐GitLab在哪里找到这些群组,请将 groups_attribute:
元素添加到您的 SAML 设置中。此属性区分大小写。
必需群组#
您的 IdP 在 SAML 响应中将群组信息传递给极狐GitLab。要使用此
响应,请配置极狐GitLab以识别:
使用 groups_attribute 设置在 SAML 响应中查找群组的位置。
使用群组设置获取有关群组或用户的信息。
使用 required_groups 设置来配置极狐GitLab,以识别登录所需的群组成员资格。
如果您没有设置 required_groups 或将其设置为空,则任何具有适当身份验证的人都可以使用该服务。
如果 groups_attribute 中指定的属性不正确或缺失,则所有用户都将被阻止。
Linux package (Omnibus) Helm chart (Kubernetes) Docker Self-compiled (source)
编辑 /etc/gitlab/gitlab.rb :
1 gitlab_rails [ 'omniauth_providers' ] = [
2 { name : 'saml' ,
3 label : 'Our SAML Provider' ,
4 groups_attribute : 'Groups' ,
5 required_groups : [ 'Developers' , 'Freelancers' , 'Admins' , 'Auditors' ] ,
6 args : {
7 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
8 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
9 idp_sso_target_url : 'https://login.example.com/idp' ,
10 issuer : 'https://gitlab.example.com' ,
11 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
12 }
13 }
14 ]
保存文件并重新配置极狐GitLab:
sudo gitlab-ctl reconfigure
将以下内容放入名为 saml.yaml 的文件中,用作 Kubernetes Secret :
1 name : 'saml'
2 label : 'Our SAML Provider'
3 groups_attribute : 'Groups'
4 required_groups : [ 'Developers' , 'Freelancers' , 'Admins' , 'Auditors' ]
5 args :
6 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback'
7 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6'
8 idp_sso_target_url : 'https://login.example.com/idp'
9 issuer : 'https://gitlab.example.com'
10 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
创建 Kubernetes Secret:
kubectl create secret generic -n < namespace > gitlab-saml --from-file = provider = saml.yaml
导出 Helm 值:
helm get values gitlab > gitlab_values.yaml
编辑 gitlab_values.yaml :
global :
appConfig :
omniauth :
providers :
- secret : gitlab - saml
保存文件并应用新值:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
编辑 docker-compose.yml :
1 version : "3.6"
2 services :
3 gitlab :
4 environment :
5 GITLAB_OMNIBUS_CONFIG : |
6 gitlab_rails['omniauth_providers'] = [
7 { name: 'saml',
8 label: 'Our SAML Provider',
9 groups_attribute: 'Groups',
10 required_groups: ['Developers', 'Freelancers', 'Admins', 'Auditors'],
11 args: {
12 assertion_consumer_service_url: 'https://gitlab.example.com/users/auth/saml/callback',
13 idp_cert_fingerprint: '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6',
14 idp_sso_target_url: 'https://login.example.com/idp',
15 issuer: 'https://gitlab.example.com',
16 name_identifier_format: 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
17 }
18 }
19 ]
保存文件并重启极狐GitLab:
编辑 /home/git/gitlab/config/gitlab.yml :
1 production : &base
2 omniauth :
3 providers :
4 - { name : 'saml' ,
5 label : 'Our SAML Provider' ,
6 groups_attribute : 'Groups' ,
7 required_groups : [ 'Developers' , 'Freelancers' , 'Admins' , 'Auditors' ] ,
8 args : {
9 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
10 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
11 idp_sso_target_url : 'https://login.example.com/idp' ,
12 issuer : 'https://gitlab.example.com' ,
13 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
14 }
15 }
保存文件并重启极狐GitLab:
# For systems running systemd
sudo systemctl restart gitlab.target
# For systems running SysV init
sudo service gitlab restart
外部群组#
您的 IdP 在 SAML 响应中将群组信息传递给极狐GitLab。要使用此响应,需配置极狐GitLab来识别:
使用 groups_attribute 设置以确定在 SAML 响应中查找群组的位置。
使用群组设置来获取有关群组或用户的信息。
基于 external_groups 设置,SAML 可以自动将用户识别为外部用户 。
如果 groups_attribute 中指定的属性不正确或缺失,则用户将作为标准用户访问。
配置示例:
Linux package (Omnibus) Helm chart (Kubernetes) Docker Self-compiled (source)
编辑 /etc/gitlab/gitlab.rb :
1 gitlab_rails [ 'omniauth_providers' ] = [
2
3 { name : 'saml' ,
4 label : 'Our SAML Provider' ,
5 groups_attribute : 'Groups' ,
6 external_groups : [ 'Freelancers' ] ,
7 args : {
8 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
9 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
10 idp_sso_target_url : 'https://login.example.com/idp' ,
11 issuer : 'https://gitlab.example.com' ,
12 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
13 }
14 }
15 ]
保存文件并重新配置极狐GitLab:
sudo gitlab-ctl reconfigure
将以下内容放入名为 saml.yaml 的文件中,用作 Kubernetes Secret :
1 name : 'saml'
2 label : 'Our SAML Provider'
3 groups_attribute : 'Groups'
4 external_groups : [ 'Freelancers' ]
5 args :
6 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback'
7 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6'
8 idp_sso_target_url : 'https://login.example.com/idp'
9 issuer : 'https://gitlab.example.com'
10 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
创建 Kubernetes Secret:
kubectl create secret generic -n < namespace > gitlab-saml --from-file = provider = saml.yaml
导出 Helm 值:
helm get values gitlab > gitlab_values.yaml
编辑 gitlab_values.yaml :
global :
appConfig :
omniauth :
providers :
- secret : gitlab - saml
保存文件并应用新值:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
编辑 docker-compose.yml :
1 version : "3.6"
2 services :
3 gitlab :
4 environment :
5 GITLAB_OMNIBUS_CONFIG : |
6 gitlab_rails['omniauth_providers'] = [
7 { name: 'saml',
8 label: 'Our SAML Provider',
9 groups_attribute: 'Groups',
10 external_groups: ['Freelancers'],
11 args: {
12 assertion_consumer_service_url: 'https://gitlab.example.com/users/auth/saml/callback',
13 idp_cert_fingerprint: '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6',
14 idp_sso_target_url: 'https://login.example.com/idp',
15 issuer: 'https://gitlab.example.com',
16 name_identifier_format: 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
17 }
18 }
19 ]
保存文件并重启极狐GitLab:
编辑 /home/git/gitlab/config/gitlab.yml :
1 production : &base
2 omniauth :
3 providers :
4 - { name : 'saml' ,
5 label : 'Our SAML Provider' ,
6 groups_attribute : 'Groups' ,
7 external_groups : [ 'Freelancers' ] ,
8 args : {
9 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
10 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
11 idp_sso_target_url : 'https://login.example.com/idp' ,
12 issuer : 'https://gitlab.example.com' ,
13 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
14 }
15 }
保存文件并重启极狐GitLab:
# For systems running systemd
sudo systemctl restart gitlab.target
# For systems running SysV init
sudo service gitlab restart
管理员群组#
您的 IdP 会在 SAML 响应中传递群组信息给极狐GitLab。要使用此响应,请配置极狐GitLab以识别:
使用 groups_attribute 设置来确定在 SAML 响应中查找群组的位置。
使用群组设置来获取有关群组或用户的信息。
使用 admin_groups 设置来配置极狐GitLab,以识别哪些群组授予用户管理员访问权限。
如果 groups_attribute 中指定的属性不正确或缺失,用户将失去管理员访问权限。
示例配置:
Linux 软件包 (Omnibus) Helm chart (Kubernetes) Docker 自编译 (源代码)
编辑 /etc/gitlab/gitlab.rb :
1 gitlab_rails [ 'omniauth_providers' ] = [
2 { name : 'saml' ,
3 label : 'Our SAML Provider' ,
4 groups_attribute : 'Groups' ,
5 admin_groups : [ 'Admins' ] ,
6 args : {
7 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
8 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
9 idp_sso_target_url : 'https://login.example.com/idp' ,
10 issuer : 'https://gitlab.example.com' ,
11 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
12 }
13 }
14 ]
保存文件并重新配置极狐GitLab:
sudo gitlab-ctl reconfigure
将以下内容放入名为 saml.yaml 的文件中,用作 Kubernetes Secret :
1 name : 'saml'
2 label : 'Our SAML Provider'
3 groups_attribute : 'Groups'
4 admin_groups : [ 'Admins' ]
5 args :
6 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback'
7 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6'
8 idp_sso_target_url : 'https://login.example.com/idp'
9 issuer : 'https://gitlab.example.com'
10 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
创建 Kubernetes Secret:
kubectl create secret generic -n < namespace > gitlab-saml --from-file = provider = saml.yaml
导出 Helm 值:
helm get values gitlab > gitlab_values.yaml
编辑 gitlab_values.yaml :
global :
appConfig :
omniauth :
providers :
- secret : gitlab - saml
保存文件并应用新值:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
编辑 docker-compose.yml :
1 version : "3.6"
2 services :
3 gitlab :
4 environment :
5 GITLAB_OMNIBUS_CONFIG : |
6 gitlab_rails['omniauth_providers'] = [
7 { name: 'saml',
8 label: 'Our SAML Provider',
9 groups_attribute: 'Groups',
10 admin_groups: ['Admins'],
11 args: {
12 assertion_consumer_service_url: 'https://gitlab.example.com/users/auth/saml/callback',
13 idp_cert_fingerprint: '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6',
14 idp_sso_target_url: 'https://login.example.com/idp',
15 issuer: 'https://gitlab.example.com',
16 name_identifier_format: 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
17 }
18 }
19 ]
保存文件并重启极狐GitLab:
编辑 /home/git/gitlab/config/gitlab.yml :
1 production : &base
2 omniauth :
3 providers :
4 - { name : 'saml' ,
5 label : 'Our SAML Provider' ,
6 groups_attribute : 'Groups' ,
7 admin_groups : [ 'Admins' ] ,
8 args : {
9 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
10 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
11 idp_sso_target_url : 'https://login.example.com/idp' ,
12 issuer : 'https://gitlab.example.com' ,
13 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
14 }
15 }
保存文件并重启极狐GitLab:
# 对于运行 systemd 的系统
sudo systemctl restart gitlab.target
# 对于运行 SysV init 的系统
sudo service gitlab restart
审计员群组#
您的 IdP 会在 SAML 响应中传递群组信息给极狐GitLab。要使用此响应,请配置极狐GitLab以识别:
使用 groups_attribute 设置来确定在 SAML 响应中查找群组的位置。
使用群组设置来获取有关群组或用户的信息。
使用 auditor_groups 设置来配置极狐GitLab,以识别哪些群组包含具有审计员访问权限 的用户。
如果 groups_attribute 中指定的属性不正确或缺失,用户将失去审计员访问权限。
示例配置:
Linux 软件包 (Omnibus) Helm chart (Kubernetes) Docker 自编译 (源代码)
编辑 /etc/gitlab/gitlab.rb :
1 gitlab_rails [ 'omniauth_providers' ] = [
2 { name : 'saml' ,
3 label : 'Our SAML Provider' ,
4 groups_attribute : 'Groups' ,
5 auditor_groups : [ 'Auditors' ] ,
6 args : {
7 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
8 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
9 idp_sso_target_url : 'https://login.example.com/idp' ,
10 issuer : 'https://gitlab.example.com' ,
11 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
12 }
13 }
14 ]
保存文件并重新配置极狐GitLab:
sudo gitlab-ctl reconfigure
将以下内容放入名为 saml.yaml 的文件中,用作 Kubernetes Secret :
1 name : 'saml'
2 label : 'Our SAML Provider'
3 groups_attribute : 'Groups'
4 auditor_groups : [ 'Auditors' ]
5 args :
6 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback'
7 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6'
8 idp_sso_target_url : 'https://login.example.com/idp'
9 issuer : 'https://gitlab.example.com'
10 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
创建 Kubernetes Secret:
kubectl create secret generic -n < namespace > gitlab-saml --from-file = provider = saml.yaml
导出 Helm 值:
helm get values gitlab > gitlab_values.yaml
编辑 gitlab_values.yaml :
global :
appConfig :
omniauth :
providers :
- secret : gitlab - saml
保存文件并应用新值:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
编辑 docker-compose.yml :
1 version : "3.6"
2 services :
3 gitlab :
4 environment :
5 GITLAB_OMNIBUS_CONFIG : |
6 gitlab_rails['omniauth_providers'] = [
7 { name: 'saml',
8 label: 'Our SAML Provider',
9 groups_attribute: 'Groups',
10 auditor_groups: ['Auditors'],
11 args: {
12 assertion_consumer_service_url: 'https://gitlab.example.com/users/auth/saml/callback',
13 idp_cert_fingerprint: '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6',
14 idp_sso_target_url: 'https://login.example.com/idp',
15 issuer: 'https://gitlab.example.com',
16 name_identifier_format: 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
17 }
18 }
19 ]
保存文件并重启极狐GitLab:
编辑 /home/git/gitlab/config/gitlab.yml :
1 production : &base
2 omniauth :
3 providers :
4 - { name : 'saml' ,
5 label : 'Our SAML Provider' ,
6 groups_attribute : 'Groups' ,
7 auditor_groups : [ 'Auditors' ] ,
8 args : {
9 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
10 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
11 idp_sso_target_url : 'https://login.example.com/idp' ,
12 issuer : 'https://gitlab.example.com' ,
13 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
14 }
15 }
保存文件并重启极狐GitLab:
# 对于运行 systemd 的系统
sudo systemctl restart gitlab.target
# 对于运行 SysV init 的系统
sudo service gitlab restart
自动管理 SAML 群组同步#
有关自动管理极狐GitLab群组成员的信息,请参阅 SAML 群组同步 。
绕过双因素认证#
History
在极狐GitLab 16.1 中引入,使用名为 by_pass_two_factor_current_session 的功能标志 ,以绕过 2FA 执行。
在极狐GitLab 17.8 中启用。
要配置 SAML 认证方法以在每次会话中计入双因素认证 (2FA),请在 upstream_two_factor_authn_contexts 列表中注册该方法。
确保您的 IdP 返回 AuthnContext 。例如:
< saml: AuthnStatement >
< saml: AuthnContext >
< saml: AuthnContextClassRef > urn:oasis:names:tc:SAML:2.0:ac:classes:MediumStrongCertificateProtectedTransport </ saml: AuthnContextClassRef >
</ saml: AuthnContext >
</ saml: AuthnStatement >
编辑您的安装配置以在 upstream_two_factor_authn_contexts 列表中注册 SAML 认证方法。您必须输入来自 SAML 响应的 AuthnContext 。
编辑 /etc/gitlab/gitlab.rb :
1 gitlab_rails [ 'omniauth_providers' ] = [
2 { name : 'saml' ,
3 label : 'Our SAML Provider' ,
4 args : {
5 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
6 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
7 idp_sso_target_url : 'https://login.example.com/idp' ,
8 issuer : 'https://gitlab.example.com' ,
9 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent' ,
10 upstream_two_factor_authn_contexts :
11 %w(
12 urn:oasis:names:tc:SAML:2.0:ac:classes:CertificateProtectedTransport
13 urn:oasis:names:tc:SAML:2.0:ac:classes:SecondFactorOTPSMS
14 urn:oasis:names:tc:SAML:2.0:ac:classes:SecondFactorIGTOKEN
15 ) ,
16 }
17 }
18 ]
保存文件并重新配置极狐GitLab:
sudo gitlab-ctl reconfigure
将以下内容放入名为 saml.yaml 的文件中,用作 Kubernetes Secret :
1 name : 'saml'
2 label : 'Our SAML Provider'
3 args :
4 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback'
5 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6'
6 idp_sso_target_url : 'https://login.example.com/idp'
7 issuer : 'https://gitlab.example.com'
8 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
9 upstream_two_factor_authn_contexts :
10 - 'urn:oasis:names:tc:SAML:2.0:ac:classes:CertificateProtectedTransport'
11 - 'urn:oasis:names:tc:SAML:2.0:ac:classes:SecondFactorOTPSMS'
12 - 'urn:oasis:names:tc:SAML:2.0:ac:classes:SecondFactorIGTOKEN'
创建 Kubernetes Secret:
kubectl create secret generic -n < namespace > gitlab-saml --from-file = provider = saml.yaml
导出 Helm 值:
helm get values gitlab > gitlab_values.yaml
编辑 gitlab_values.yaml :
global :
appConfig :
omniauth :
providers :
- secret : gitlab - saml
保存文件并应用新值:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
验证响应签名#
IdP 必须对 SAML 响应进行签名,以确保断言未被篡改。这可以防止用户冒充和权限升级,当需要特定群组成员时。
使用 idp_cert_fingerprint #
您可以使用 idp_cert_fingerprint 配置响应签名验证。以下是一个配置示例:
{{< tabs >}}
{{< tab title="Linux package (Omnibus)" >}}
编辑 /etc/gitlab/gitlab.rb :
1 gitlab_rails [ 'omniauth_providers' ] = [
2 { name : 'saml' ,
3 label : 'Our SAML Provider' ,
4 args : {
5 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
6 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
7 idp_sso_target_url : 'https://login.example.com/idp' ,
8 issuer : 'https://gitlab.example.com' ,
9 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
10 }
11 }
12 ]
保存文件并重新配置极狐GitLab:
sudo gitlab-ctl reconfigure
将以下内容放入一个名为 saml.yaml 的文件中,以便用作 Kubernetes Secret :
1 name : 'saml'
2 label : 'Our SAML Provider'
3 args :
4 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback'
5 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6'
6 idp_sso_target_url : 'https://login.example.com/idp'
7 issuer : 'https://gitlab.example.com'
8 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
创建 Kubernetes Secret:
kubectl create secret generic -n < namespace > gitlab-saml --from-file = provider = saml.yaml
导出 Helm 值:
helm get values gitlab > gitlab_values.yaml
编辑 gitlab_values.yaml :
global :
appConfig :
omniauth :
providers :
- secret : gitlab - saml
保存文件并应用新值:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
编辑 docker-compose.yml :
1 version : "3.6"
2 services :
3 gitlab :
4 environment :
5 GITLAB_OMNIBUS_CONFIG : |
6 gitlab_rails['omniauth_providers'] = [
7 { name: 'saml',
8 label: 'Our SAML Provider',
9 args: {
10 assertion_consumer_service_url: 'https://gitlab.example.com/users/auth/saml/callback',
11 idp_cert_fingerprint: '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6',
12 idp_sso_target_url: 'https://login.example.com/idp',
13 issuer: 'https://gitlab.example.com',
14 name_identifier_format: 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
15 }
16 }
17 ]
保存文件并重启极狐GitLab:
编辑 /home/git/gitlab/config/gitlab.yml :
1 production : &base
2 omniauth :
3 providers :
4 - { name : 'saml' ,
5 label : 'Our SAML Provider' ,
6 args : {
7 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
8 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
9 idp_sso_target_url : 'https://login.example.com/idp' ,
10 issuer : 'https://gitlab.example.com' ,
11 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
12 }
13 }
保存文件并重启极狐GitLab:
# 对于运行 systemd 的系统
sudo systemctl restart gitlab.target
# 对于运行 SysV init 的系统
sudo service gitlab restart
使用 idp_cert #
如果您的 IdP 不支持使用 idp_cert_fingerprint 进行配置,您可以直接使用 idp_cert 配置极狐GitLab。以下是一个配置示例:
Linux package (Omnibus) Helm chart (Kubernetes) Docker Self-compiled (source)
编辑 /etc/gitlab/gitlab.rb :
1 gitlab_rails [ 'omniauth_providers' ] = [
2 { name : 'saml' ,
3 label : 'Our SAML Provider' ,
4 args : {
5 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
6 idp_cert : ' - - - - - BEGIN CERTIFICATE - - - - -
7 < redacted >
8 - - - - - END CERTIFICATE - - - - - ' ,
9 idp_sso_target_url : 'https://login.example.com/idp' ,
10 issuer : 'https://gitlab.example.com' ,
11 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
12 }
13 }
14 ]
保存文件并重新配置极狐GitLab:
sudo gitlab-ctl reconfigure
将以下内容放入一个名为 saml.yaml 的文件中,以便用作 Kubernetes Secret :
1 name : 'saml'
2 label : 'Our SAML Provider'
3 args :
4 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback'
5 idp_cert : |
6 -----BEGIN CERTIFICATE-----
7 <redacted>
8 -----END CERTIFICATE-----
9 idp_sso_target_url : 'https://login.example.com/idp'
10 issuer : 'https://gitlab.example.com'
11 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
创建 Kubernetes Secret:
kubectl create secret generic -n < namespace > gitlab-saml --from-file = provider = saml.yaml
导出 Helm 值:
helm get values gitlab > gitlab_values.yaml
编辑 gitlab_values.yaml :
global :
appConfig :
omniauth :
providers :
- secret : gitlab - saml
保存文件并应用新值:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
编辑 docker-compose.yml :
1 version : "3.6"
2 services :
3 gitlab :
4 environment :
5 GITLAB_OMNIBUS_CONFIG : |
6 gitlab_rails['omniauth_providers'] = [
7 { name: 'saml',
8 label: 'Our SAML Provider',
9 args: {
10 assertion_consumer_service_url: 'https://gitlab.example.com/users/auth/saml/callback',
11 idp_cert: '-----BEGIN CERTIFICATE-----
12 <redacted>
13 -----END CERTIFICATE-----',
14 idp_sso_target_url: 'https://login.example.com/idp',
15 issuer: 'https://gitlab.example.com',
16 name_identifier_format: 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
17 }
18 }
19 ]
保存文件并重启极狐GitLab:
编辑 /home/git/gitlab/config/gitlab.yml :
1 production : &base
2 omniauth :
3 providers :
4 - { name : 'saml' ,
5 label : 'Our SAML Provider' ,
6 args : {
7 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
8 idp_cert : ' --- - - BEGIN CERTIFICATE --- - -
9 <redacted >
10 --- - - END CERTIFICATE --- - - ' ,
11 idp_sso_target_url : 'https://login.example.com/idp' ,
12 issuer : 'https://gitlab.example.com' ,
13 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
14 }
15 }
保存文件并重启极狐GitLab:
# 对于运行 systemd 的系统
sudo systemctl restart gitlab.target
# 对于运行 SysV init 的系统
sudo service gitlab restart
如果您错误地配置了响应签名验证,您可能会看到如下错误信息:
有关解决这些错误的更多信息,请参阅 故障排除 SAML 指南 。
自定义 SAML 设置#
重定向用户到 SAML 服务器进行认证#
您可以在极狐GitLab 配置中添加 auto_sign_in_with_provider 设置,以自动重定向到您的 SAML 服务器进行认证。这消除了在实际登录之前选择元素的要求。
Linux package (Omnibus) Helm chart (Kubernetes) Docker Self-compiled (source)
编辑 /etc/gitlab/gitlab.rb :
gitlab_rails [ 'omniauth_auto_sign_in_with_provider' ] = 'saml'
保存文件并重新配置极狐GitLab:
sudo gitlab-ctl reconfigure
导出 Helm 值:
helm get values gitlab > gitlab_values.yaml
编辑 gitlab_values.yaml :
global :
appConfig :
omniauth :
autoSignInWithProvider : 'saml'
保存文件并应用新值:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
编辑 docker-compose.yml :
1 version : "3.6"
2 services :
3 gitlab :
4 environment :
5 GITLAB_OMNIBUS_CONFIG : |
6 gitlab_rails['omniauth_auto_sign_in_with_provider'] = 'saml'
保存文件并重启极狐GitLab:
编辑 /home/git/gitlab/config/gitlab.yml :
production : &base
omniauth_auto_sign_in_with_provider : 'saml'
保存文件并重启极狐GitLab:
# 对于运行 systemd 的系统
sudo systemctl restart gitlab.target
# 对于运行 SysV init 的系统
sudo service gitlab restart
编辑 docker-compose.yml :
1 version : "3.6"
2 services :
3 gitlab :
4 environment :
5 GITLAB_OMNIBUS_CONFIG : |
6 gitlab_rails['omniauth_auto_sign_in_with_provider'] = 'saml'
保存文件并重启极狐GitLab:
{{< /tab >}}
{{< tab title="Self-compiled (source)" >}}
编辑 /home/git/gitlab/config/gitlab.yml :
production : &base
omniauth :
auto_sign_in_with_provider : 'saml'
保存文件并重启极狐GitLab:
# 对于运行 systemd 的系统
sudo systemctl restart gitlab.target
# 对于运行 SysV init 的系统
sudo service gitlab restart
{{< /tab >}}
{{< /tabs >}}
每次登录尝试都会重定向到 SAML 服务器,因此您无法使用本地凭据登录。确保至少有一个 SAML 用户拥有管理员访问权限。
要绕过自动登录设置,请在登录 URL 中附加 ?auto_sign_in=false ,例如:https://gitlab.example.com/users/sign_in?auto_sign_in=false 。
映射 SAML 响应属性名称#
版本: 基础版,专业版,旗舰版
提供: 私有化部署
您可以使用 attribute_statements 将 SAML 响应中的属性名称映射到 OmniAuth info hash 中的条目。
仅使用此设置来映射属于 OmniAuth info hash 模式的属性。
例如,如果您的 SAMLResponse 包含一个名为 EmailAddress 的属性,请指定 { email: ['EmailAddress'] } 以将属性映射到 info hash 中的相应键。还支持 URI 命名的属性,例如 { email: ['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress'] } 。
使用此设置告诉极狐GitLab 在哪里查找创建帐户所需的某些属性。例如,如果您的 IdP 将用户的电子邮件地址作为 EmailAddress 发送而不是 email ,请在配置中设置它以告知极狐GitLab:
Linux package (Omnibus) Helm chart (Kubernetes) Docker Self-compiled (source)
编辑 /etc/gitlab/gitlab.rb :
1 gitlab_rails [ 'omniauth_providers' ] = [
2 { name : 'saml' ,
3 label : 'Our SAML Provider' ,
4 args : {
5 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
6 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
7 idp_sso_target_url : 'https://login.example.com/idp' ,
8 issuer : 'https://gitlab.example.com' ,
9 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent' ,
10 attribute_statements : { email : [ 'EmailAddress' ] }
11 }
12 }
13 ]
保存文件并重新配置极狐GitLab:
sudo gitlab-ctl reconfigure
将以下内容放入一个名为 saml.yaml 的文件中,用作 Kubernetes Secret :
1 name : 'saml'
2 label : 'Our SAML Provider'
3 args :
4 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback'
5 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6'
6 idp_sso_target_url : 'https://login.example.com/idp'
7 issuer : 'https://gitlab.example.com'
8 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
9 attribute_statements :
10 email : [ 'EmailAddress' ]
创建 Kubernetes Secret:
kubectl create secret generic -n < namespace > gitlab-saml --from-file = provider = saml.yaml
导出 Helm 值:
helm get values gitlab > gitlab_values.yaml
编辑 gitlab_values.yaml :
global :
appConfig :
omniauth :
providers :
- secret : gitlab - saml
保存文件并应用新值:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
编辑 docker-compose.yml :
1 version : "3.6"
2 services :
3 gitlab :
4 environment :
5 GITLAB_OMNIBUS_CONFIG : |
6 gitlab_rails['omniauth_providers'] = [
7 { name: 'saml',
8 label: 'Our SAML Provider',
9 args: {
10 assertion_consumer_service_url: 'https://gitlab.example.com/users/auth/saml/callback',
11 idp_cert_fingerprint: '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6',
12 idp_sso_target_url: 'https://login.example.com/idp',
13 issuer: 'https://gitlab.example.com',
14 name_identifier_format: 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent',
15 attribute_statements: { email: ['EmailAddress'] }
16 }
17 }
18 ]
保存文件并重启极狐GitLab:
编辑 /home/git/gitlab/config/gitlab.yml :
1 production : &base
2 omniauth :
3 providers :
4 - { name : 'saml' ,
5 label : 'Our SAML Provider' ,
6 args : {
7 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
8 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
9 idp_sso_target_url : 'https://login.example.com/idp' ,
10 issuer : 'https://gitlab.example.com' ,
11 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent' ,
12 attribute_statements : { email : [ 'EmailAddress' ] }
13 }
14 }
保存文件并重启极狐GitLab:
# 对于运行 systemd 的系统
sudo systemctl restart gitlab.target
# 对于运行 SysV init 的系统
sudo service gitlab restart
设置用户名#
默认情况下,SAML 响应中电子邮件地址的本地部分用于生成用户的极狐GitLab 用户名。
在 attribute_statements 中配置 username 或 nickname 以指定一个或多个包含用户所需用户名的属性:
Linux package (Omnibus) Helm chart (Kubernetes) Docker Self-compiled (source)
编辑 /etc/gitlab/gitlab.rb :
1 gitlab_rails [ 'omniauth_providers' ] = [
2 { name : 'saml' ,
3 label : 'Our SAML Provider' ,
4 args : {
5 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
6 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
7 idp_sso_target_url : 'https://login.example.com/idp' ,
8 issuer : 'https://gitlab.example.com' ,
9 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent' ,
10 attribute_statements : { nickname : [ 'username' ] }
11 }
12 }
13 ]
保存文件并重新配置极狐GitLab:
sudo gitlab-ctl reconfigure
将以下内容放入一个名为 saml.yaml 的文件中,用作 Kubernetes Secret :
1 name : 'saml'
2 label : 'Our SAML Provider'
3 args :
4 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback'
5 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6'
6 idp_sso_target_url : 'https://login.example.com/idp'
7 issuer : 'https://gitlab.example.com'
8 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
9 attribute_statements :
10 nickname : [ 'username' ]
创建 Kubernetes Secret:
kubectl create secret generic -n < namespace > gitlab-saml --from-file = provider = saml.yaml
导出 Helm 值:
helm get values gitlab > gitlab_values.yaml
编辑 gitlab_values.yaml :
global :
appConfig :
omniauth :
providers :
- secret : gitlab - saml
保存文件并应用新值:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
编辑 docker-compose.yml :
1 version : "3.6"
2 services :
3 gitlab :
4 environment :
5 GITLAB_OMNIBUS_CONFIG : |
6 gitlab_rails['omniauth_providers'] = [
7 { name: 'saml',
8 label: 'Our SAML Provider',
9 groups_attribute: 'Groups',
10 required_groups: ['Developers', 'Freelancers', 'Admins', 'Auditors'],
11 args: {
12 assertion_consumer_service_url: 'https://gitlab.example.com/users/auth/saml/callback',
13 idp_cert_fingerprint: '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6',
14 idp_sso_target_url: 'https://login.example.com/idp',
15 issuer: 'https://gitlab.example.com',
16 name_identifier_format: 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent',
17 attribute_statements: { nickname: ['username'] }
18 }
19 }
20 ]
保存文件并重启极狐GitLab:
编辑 /home/git/gitlab/config/gitlab.yml :
1 production : &base
2 omniauth :
3 providers :
4 - { name : 'saml' ,
5 label : 'Our SAML Provider' ,
6 groups_attribute : 'Groups' ,
7 required_groups : [ 'Developers' , 'Freelancers' , 'Admins' , 'Auditors' ] ,
8 args : {
9 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
10 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
11 idp_sso_target_url : 'https://login.example.com/idp' ,
12 issuer : 'https://gitlab.example.com' ,
13 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent' ,
14 attribute_statements : { nickname : [ 'username' ] }
15 }
16 }
保存文件并重启极狐GitLab:
# 对于运行 systemd 的系统
sudo systemctl restart gitlab.target
# 对于运行 SysV init 的系统
sudo service gitlab restart
这也将 SAML 响应中的 username 属性设置为极狐GitLab 中的用户名。
映射个人资料属性#
History
在极狐GitLab 17.8 中引入了 job_title 和 organization 属性。
要从您的 SAML 提供商同步个人资料信息,必须配置 attribute_statements 来映射这些属性。
支持的个人资料属性有:
这些属性没有默认映射,除非明确配置,否则不会同步。
Linux package (Omnibus) Helm chart (Kubernetes) Docker Self-compiled (source)
配置 OmniAuth 以同步所需属性 。
编辑 /etc/gitlab/gitlab.rb :
1 gitlab_rails [ 'omniauth_providers' ] = [
2 { name : 'saml' ,
3 label : 'Our SAML Provider' ,
4 args : {
5 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
6 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
7 idp_sso_target_url : 'https://login.example.com/idp' ,
8 issuer : 'https://gitlab.example.com' ,
9 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent' ,
10 attribute_statements : {
11 organization : [ 'organization' ] ,
12 job_title : [ 'job_title' ]
13 }
14 }
15 }
16 ]
保存文件并重新配置极狐GitLab:
sudo gitlab-ctl reconfigure
配置 OmniAuth 以同步所需属性 。
将以下 YAML 内容保存到名为 saml.yaml 的文件中,以用作 Kubernetes Secret :
1 name : 'saml'
2 label : 'Our SAML Provider'
3 args :
4 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback'
5 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6'
6 idp_sso_target_url : 'https://login.example.com/idp'
7 issuer : 'https://gitlab.example.com'
8 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
9 attribute_statements :
10 organization : [ 'organization' ]
11 job_title : [ 'job_title' ]
创建 Kubernetes Secret:
kubectl create secret generic -n < namespace > gitlab-saml --from-file = provider = saml.yaml
导出 Helm 值:
helm get values gitlab > gitlab_values.yaml
编辑 gitlab_values.yaml :
global :
appConfig :
omniauth :
providers :
- secret : gitlab - saml
保存文件并应用新值:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
配置 OmniAuth 以同步所需属性 。
编辑 docker-compose.yml :
1 version : "3.6"
2 services :
3 gitlab :
4 environment :
5 GITLAB_OMNIBUS_CONFIG : |
6 gitlab_rails['omniauth_providers'] = [
7 { name: 'saml',
8 label: 'Our SAML Provider',
9 args: {
10 assertion_consumer_service_url: 'https://gitlab.example.com/users/auth/saml/callback',
11 idp_cert_fingerprint: '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6',
12 idp_sso_target_url: 'https://login.example.com/idp',
13 issuer: 'https://gitlab.example.com',
14 name_identifier_format: 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent',
15 attribute_statements: {
16 organization: ['organization'],
17 job_title: ['job_title']
18 }
19 }
20 }
21 ]
保存文件并重启极狐GitLab:
配置 OmniAuth 以同步所需属性 。
编辑 /home/git/gitlab/config/gitlab.yml :
1 production : &base
2 omniauth :
3 providers :
4 - { name : 'saml' ,
5 label : 'Our SAML Provider' ,
6 args : {
7 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
8 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
9 idp_sso_target_url : 'https://login.example.com/idp' ,
10 issuer : 'https://gitlab.example.com' ,
11 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent' ,
12 attribute_statements : {
13 organization : [ 'organization' ] ,
14 job_title : [ 'job_title' ]
15 }
16 }
17 }
保存文件并重启极狐GitLab:
# For systems running systemd
sudo systemctl restart gitlab.target
# For systems running SysV init
sudo service gitlab restart
允许时钟漂移#
IdP 的时钟可能会略微领先于您的系统时钟。要允许少量时钟漂移,请在设置中使用 allowed_clock_drift 。您必须以秒和秒的小数形式输入参数的值。给定的值被添加到验证响应的当前时间。
Linux package (Omnibus) Helm chart (Kubernetes) Docker Self-compiled (source)
编辑 /etc/gitlab/gitlab.rb :
1 gitlab_rails [ 'omniauth_providers' ] = [
2 { name : 'saml' ,
3 label : 'Our SAML Provider' ,
4 groups_attribute : 'Groups' ,
5 required_groups : [ 'Developers' , 'Freelancers' , 'Admins' , 'Auditors' ] ,
6 args : {
7 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
8 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
9 idp_sso_target_url : 'https://login.example.com/idp' ,
10 issuer : 'https://gitlab.example.com' ,
11 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent' ,
12 allowed_clock_drift : 1 # for one second clock drift
13 }
14 }
15 ]
保存文件并重新配置极狐GitLab:
sudo gitlab-ctl reconfigure
将以下内容放在名为 saml.yaml 的文件中,以用作 Kubernetes Secret :
1 name : 'saml'
2 label : 'Our SAML Provider'
3 groups_attribute : 'Groups'
4 required_groups : [ 'Developers' , 'Freelancers' , 'Admins' , 'Auditors' ]
5 args :
6 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback'
7 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6'
8 idp_sso_target_url : 'https://login.example.com/idp'
9 issuer : 'https://gitlab.example.com'
10 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
11 allowed_clock_drift : 1 # for one second clock drift
创建 Kubernetes Secret:
kubectl create secret generic -n < namespace > gitlab-saml --from-file = provider = saml.yaml
导出 Helm 值:
helm get values gitlab > gitlab_values.yaml
编辑 gitlab_values.yaml :
global :
appConfig :
omniauth :
providers :
- secret : gitlab - saml
保存文件并应用新值:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
编辑 docker-compose.yml :
1 version : "3.6"
2 services :
3 gitlab :
4 environment :
5 GITLAB_OMNIBUS_CONFIG : |
6 gitlab_rails['omniauth_providers'] = [
7 { name: 'saml',
8 label: 'Our SAML Provider',
9 groups_attribute: 'Groups',
10 required_groups: ['Developers', 'Freelancers', 'Admins', 'Auditors'],
11 args: {
12 assertion_consumer_service_url: 'https://gitlab.example.com/users/auth/saml/callback',
13 idp_cert_fingerprint: '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6',
14 idp_sso_target_url: 'https://login.example.com/idp',
15 issuer: 'https://gitlab.example.com',
16 name_identifier_format: 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent',
17 allowed_clock_drift: 1 # for one second clock drift
18 }
19 }
20 ]
保存文件并重启极狐GitLab:
编辑 /home/git/gitlab/config/gitlab.yml :
1 production : &base
2 omniauth :
3 providers :
4 - { name : 'saml' ,
5 label : 'Our SAML Provider' ,
6 groups_attribute : 'Groups' ,
7 required_groups : [ 'Developers' , 'Freelancers' , 'Admins' , 'Auditors' ] ,
8 args : {
9 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
10 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
11 idp_sso_target_url : 'https://login.example.com/idp' ,
12 issuer : 'https://gitlab.example.com' ,
13 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent' ,
14 allowed_clock_drift : 1 # for one second clock drift
15 }
16 }
保存文件并重启极狐GitLab:
# For systems running systemd
sudo systemctl restart gitlab.target
# For systems running SysV init
sudo service gitlab restart
为 uid 指定唯一属性(可选)#
默认情况下,用户的 uid 被设置为 SAML 响应中的 NameID 属性。要为 uid 指定不同的属性,可以设置 uid_attribute 。
在将 uid 设置为唯一属性之前,请确保已配置以下属性,以便您的 SAML 用户无法更改它们:
NameID 。
Email 当与 omniauth_auto_link_saml_user 一起使用时。
如果用户可以更改这些属性,他们可以以其他授权用户的身份登录。请参阅您的 SAML IdP 文档以了解如何使这些属性不可更改。在以下示例中,SAML 响应中的 uid 属性值被设置为 uid_attribute 。
Linux package (Omnibus) Helm chart (Kubernetes) Docker Self-compiled (source)
编辑 /etc/gitlab/gitlab.rb :
1 gitlab_rails [ 'omniauth_providers' ] = [
2 { name : 'saml' ,
3 label : 'Our SAML Provider' ,
4 args : {
5 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
6 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
7 idp_sso_target_url : 'https://login.example.com/idp' ,
8 issuer : 'https://gitlab.example.com' ,
9 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent' ,
10 uid_attribute : 'uid'
11 }
12 }
13 ]
保存文件并重新配置极狐GitLab:
sudo gitlab-ctl reconfigure
将以下内容放在名为 saml.yaml 的文件中,以用作 Kubernetes Secret :
1 name : 'saml'
2 label : 'Our SAML Provider'
3 groups_attribute : 'Groups'
4 required_groups : [ 'Developers' , 'Freelancers' , 'Admins' , 'Auditors' ]
5 args :
6 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback'
7 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6'
8 idp_sso_target_url : 'https://login.example.com/idp'
9 issuer : 'https://gitlab.example.com'
10 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
11 uid_attribute : 'uid'
创建 Kubernetes Secret:
kubectl create secret generic -n < namespace > gitlab-saml --from-file = provider = saml.yaml
导出 Helm 值:
helm get values gitlab > gitlab_values.yaml
编辑 gitlab_values.yaml :
global :
appConfig :
omniauth :
providers :
- secret : gitlab - saml
保存文件并应用新值:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
编辑 docker-compose.yml :
1 version : "3.6"
2 services :
3 gitlab :
4 environment :
5 GITLAB_OMNIBUS_CONFIG : |
6 gitlab_rails['omniauth_providers'] = [
7 { name: 'saml',
8 label: 'Our SAML Provider',
9 groups_attribute: 'Groups',
10 required_groups: ['Developers', 'Freelancers', 'Admins', 'Auditors'],
11 args: {
12 assertion_consumer_service_url: 'https://gitlab.example.com/users/auth/saml/callback',
13 idp_cert_fingerprint: '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6',
14 idp_sso_target_url: 'https://login.example.com/idp',
15 issuer: 'https://gitlab.example.com',
16 name_identifier_format: 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent',
17 uid_attribute: 'uid'
18 }
19 }
20 ]
保存文件并重启极狐GitLab:
编辑 /home/git/gitlab/config/gitlab.yml :
1 production : &base
2 omniauth :
3 providers :
4 - { name : 'saml' ,
5 label : 'Our SAML Provider' ,
6 groups_attribute : 'Groups' ,
7 required_groups : [ 'Developers' , 'Freelancers' , 'Admins' , 'Auditors' ] ,
8 args : {
9 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
10 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
11 idp_sso_target_url : 'https://login.example.com/idp' ,
12 issuer : 'https://gitlab.example.com' ,
13 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent' ,
14 uid_attribute : 'uid'
15 }
16 }
保存文件并重启极狐GitLab:
# For systems running systemd
sudo systemctl restart gitlab.target
# For systems running SysV init
sudo service gitlab restart
编辑 /home/git/gitlab/config/gitlab.yml :
1 production : &base
2 omniauth :
3 providers :
4 - { name : 'saml' ,
5 label : 'Our SAML Provider' ,
6 groups_attribute : 'Groups' ,
7 required_groups : [ 'Developers' , 'Freelancers' , 'Admins' , 'Auditors' ] ,
8 args : {
9 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
10 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
11 idp_sso_target_url : 'https://login.example.com/idp' ,
12 issuer : 'https://gitlab.example.com' ,
13 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent' ,
14 uid_attribute : 'uid'
15 }
16 }
保存文件并重启极狐GitLab:
# 对于使用 systemd 的系统
sudo systemctl restart gitlab.target
# 对于使用 SysV init 的系统
sudo service gitlab restart
{{< /tab >}}
{{< /tabs >}}
断言加密(可选)#
极狐GitLab 要求与 SAML 2.0 一起使用 TLS 加密。有时,极狐GitLab 需要额外的断言加密。例如,如果您:
在负载均衡器处提前终止 TLS 加密。
在断言中包含您不希望出现在日志中的敏感细节。
大多数组织不需要在这一层上进行额外加密。
您的 IdP 使用极狐GitLab 的公用证书加密断言。极狐GitLab 使用其私钥解密 EncryptedAssertion 。
此集成使用 certificate 和 private_key 设置来进行断言加密和请求签名。
SAML 集成支持 EncryptedAssertion 。要加密您的断言,请在 SAML 设置中定义极狐GitLab 实例的私钥和公用证书。
定义密钥和证书时,将密钥文件中的所有换行符替换为 \n 。这使得密钥文件成为一个长字符串,没有换行符。
Linux 软件包 (Omnibus) Helm chart (Kubernetes) Docker 自编译 (source)
编辑 /etc/gitlab/gitlab.rb :
1 gitlab_rails [ 'omniauth_providers' ] = [
2 { name : 'saml' ,
3 label : 'Our SAML Provider' ,
4 groups_attribute : 'Groups' ,
5 required_groups : [ 'Developers' , 'Freelancers' , 'Admins' , 'Auditors' ] ,
6 args : {
7 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
8 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
9 idp_sso_target_url : 'https://login.example.com/idp' ,
10 issuer : 'https://gitlab.example.com' ,
11 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent' ,
12 certificate : '-----BEGIN CERTIFICATE-----\n<redacted>\n-----END CERTIFICATE-----' ,
13 private_key : '-----BEGIN PRIVATE KEY-----\n<redacted>\n-----END PRIVATE KEY-----'
14 }
15 }
16 ]
保存文件并重新配置极狐GitLab:
sudo gitlab-ctl reconfigure
将以下内容放入名为 saml.yaml 的文件中,以用作Kubernetes Secret :
1 name : 'saml'
2 label : 'Our SAML Provider'
3 groups_attribute : 'Groups'
4 required_groups : [ 'Developers' , 'Freelancers' , 'Admins' , 'Auditors' ]
5 args :
6 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback'
7 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6'
8 idp_sso_target_url : 'https://login.example.com/idp'
9 issuer : 'https://gitlab.example.com'
10 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
11 certificate : '-----BEGIN CERTIFICATE-----\n<redacted>\n-----END CERTIFICATE-----'
12 private_key : '-----BEGIN PRIVATE KEY-----\n<redacted>\n-----END PRIVATE KEY-----'
创建 Kubernetes Secret:
kubectl create secret generic -n < namespace > gitlab-saml --from-file = provider = saml.yaml
导出 Helm 值:
helm get values gitlab > gitlab_values.yaml
编辑 gitlab_values.yaml :
global :
appConfig :
omniauth :
providers :
- secret : gitlab - saml
保存文件并应用新值:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
编辑 docker-compose.yml :
1 version : "3.6"
2 services :
3 gitlab :
4 environment :
5 GITLAB_OMNIBUS_CONFIG : |
6 gitlab_rails['omniauth_providers'] = [
7 { name: 'saml',
8 label: 'Our SAML Provider',
9 groups_attribute: 'Groups',
10 required_groups: ['Developers', 'Freelancers', 'Admins', 'Auditors'],
11 args: {
12 assertion_consumer_service_url: 'https://gitlab.example.com/users/auth/saml/callback',
13 idp_cert_fingerprint: '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6',
14 idp_sso_target_url: 'https://login.example.com/idp',
15 issuer: 'https://gitlab.example.com',
16 name_identifier_format: 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent',
17 certificate: '-----BEGIN CERTIFICATE-----\n<redacted>\n-----END CERTIFICATE-----',
18 private_key: '-----BEGIN PRIVATE KEY-----\n<redacted>\n-----END PRIVATE KEY-----'
19 }
20 }
21 ]
保存文件并重启极狐GitLab:
编辑 /home/git/gitlab/config/gitlab.yml :
1 production : &base
2 omniauth :
3 providers :
4 - { name : 'saml' ,
5 label : 'Our SAML Provider' ,
6 groups_attribute : 'Groups' ,
7 required_groups : [ 'Developers' , 'Freelancers' , 'Admins' , 'Auditors' ] ,
8 args : {
9 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
10 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
11 idp_sso_target_url : 'https://login.example.com/idp' ,
12 issuer : 'https://gitlab.example.com' ,
13 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent' ,
14 certificate : '-----BEGIN CERTIFICATE-----\n<redacted>\n-----END CERTIFICATE-----' ,
15 private_key : '-----BEGIN PRIVATE KEY-----\n<redacted>\n-----END PRIVATE KEY-----'
16 }
17 }
保存文件并重启极狐GitLab:
# 对于使用 systemd 的系统
sudo systemctl restart gitlab.target
# 对于使用 SysV init 的系统
sudo service gitlab restart
签署 SAML 认证请求(可选)#
您可以配置极狐GitLab 以签署 SAML 认证请求。此配置是可选的,因为极狐GitLab SAML 请求使用 SAML 重定向绑定。
要实现签署:
为您的极狐GitLab 实例创建一个私钥和公用证书对,以用于 SAML。
在配置的 security 部分配置签署设置。例如:
编辑 /etc/gitlab/gitlab.rb :
1 gitlab_rails [ 'omniauth_providers' ] = [
2 { name : 'saml' ,
3 label : 'Our SAML Provider' ,
4 args : {
5 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
6 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
7 idp_sso_target_url : 'https://login.example.com/idp' ,
8 issuer : 'https://gitlab.example.com' ,
9 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent' ,
10 certificate : '-----BEGIN CERTIFICATE-----\n<redacted>\n-----END CERTIFICATE-----' ,
11 private_key : '-----BEGIN PRIVATE KEY-----\n<redacted>\n-----END PRIVATE KEY-----' ,
12 security : {
13 authn_requests_signed : true , # 启用对 AuthNRequest 的签名
14 want_assertions_signed : true , # 启用签署断言的要求
15 want_assertions_encrypted : false , # 启用对加密断言的要求
16 metadata_signed : false , # 启用对元数据的签名
17 signature_method : 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256' ,
18 digest_method : 'http://www.w3.org/2001/04/xmlenc#sha256' ,
19 }
20 }
21 }
22 ]
保存文件并重新配置极狐GitLab:
sudo gitlab-ctl reconfigure
将以下内容放入名为 saml.yaml 的文件中,以用作Kubernetes Secret :
1 name : 'saml'
2 label : 'Our SAML Provider'
3 args :
4 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback'
5 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6'
6 idp_sso_target_url : 'https://login.example.com/idp'
7 issuer : 'https://gitlab.example.com'
8 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
9 certificate : '-----BEGIN CERTIFICATE-----\n<redacted>\n-----END CERTIFICATE-----'
10 private_key : '-----BEGIN PRIVATE KEY-----\n<redacted>\n-----END PRIVATE KEY-----'
11 security :
12 authn_requests_signed : true # 启用对 AuthNRequest 的签名
13 want_assertions_signed : true # 启用签署断言的要求
14 want_assertions_encrypted : false # 启用对加密断言的要求
15 metadata_signed : false # 启用对元数据的签名
16 signature_method : 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256'
17 digest_method : 'http://www.w3.org/2001/04/xmlenc#sha256'
创建 Kubernetes Secret:
kubectl create secret generic -n < namespace > gitlab-saml --from-file = provider = saml.yaml
导出 Helm 值:
helm get values gitlab > gitlab_values.yaml
编辑 gitlab_values.yaml :
global :
appConfig :
omniauth :
providers :
- secret : gitlab - saml
保存文件并应用新值:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
编辑 docker-compose.yml :
1 version : "3.6"
2 services :
3 gitlab :
4 environment :
5 GITLAB_OMNIBUS_CONFIG : |
6 gitlab_rails['omniauth_providers'] = [
7 { name: 'saml',
8 label: 'Our SAML Provider',
9 args: {
10 assertion_consumer_service_url: 'https://gitlab.example.com/users/auth/saml/callback',
11 idp_cert_fingerprint: '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6',
12 idp_sso_target_url: 'https://login.example.com/idp',
13 issuer: 'https://gitlab.example.com',
14 name_identifier_format: 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent',
15 certificate: '-----BEGIN CERTIFICATE-----\n<redacted>\n-----END CERTIFICATE-----',
16 private_key: '-----BEGIN PRIVATE KEY-----\n<redacted>\n-----END PRIVATE KEY-----',
17 security: {
18 authn_requests_signed: true, # 启用对 AuthNRequest 的签名
19 want_assertions_signed: true, # 启用签署断言的要求
20 want_assertions_encrypted: false, # 启用对加密断言的要求
21 metadata_signed: false, # 启用对元数据的签名
22 signature_method: 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256',
23 digest_method: 'http://www.w3.org/2001/04/xmlenc#sha256',
24 }
25 }
26 }
27 ]
保存文件并重启极狐GitLab:
编辑 /home/git/gitlab/config/gitlab.yml :
1 production : &base
2 omniauth :
3 providers :
4 - { name : 'saml' ,
5 label : 'Our SAML Provider' ,
6 args : {
7 assertion_consumer_service_url : 'https://gitlab.example.com/users/auth/saml/callback' ,
8 idp_cert_fingerprint : '2f:cb:19:57:68:c3:9e:9a:94:ce:c2:c2:e3:2c:59:c0:aa:d7:a3:36:5c:10:89:2e:81:16:b5:d8:3d:40:96:b6' ,
9 idp_sso_target_url : 'https://login.example.com/idp' ,
10 issuer : 'https://gitlab.example.com' ,
11 name_identifier_format : 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent' ,
12 certificate : '-----BEGIN CERTIFICATE-----\n<redacted>\n-----END CERTIFICATE-----' ,
13 private_key : '-----BEGIN PRIVATE KEY-----\n<redacted>\n-----END PRIVATE KEY-----' ,
14 security : {
15 authn_requests_signed : true , # 启用对 AuthNRequest 的签名
16 want_assertions_signed : true , # 启用签署断言的要求
17 want_assertions_encrypted : false , # 启用对加密断言的要求
18 metadata_signed : false , # 启用对元数据的签名
19 signature_method : 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256' ,
20 digest_method : 'http://www.w3.org/2001/04/xmlenc#sha256' ,
21 }
22 }
23 }
保存文件并重启极狐GitLab:
# 对于使用 systemd 的系统
sudo systemctl restart gitlab.target
# 对于使用 SysV init 的系统
sudo service gitlab restart
极狐GitLab 然后:
使用提供的私钥签署请求。
在元数据中包括配置的公共 x500 证书,以便您的 IdP 验证接收到的请求的签名。
SAML 重定向绑定不同于 SAML POST 绑定。在 POST 绑定中,
需要签名以防止中间人篡改请求。
通过 SAML 创建用户的密码生成#
极狐GitLab 为通过 SAML 创建的用户生成并设置密码 。
通过 SSO 或 SAML 认证的用户不应使用密码通过 HTTPS 进行 Git 操作。这些用户可以选择:
为现有用户链接 SAML 身份#
管理员可以配置极狐GitLab 以自动将 SAML 用户与现有的极狐GitLab 用户链接。有关更多信息,请参阅在极狐GitLab 中配置 SAML 支持 。
用户可以手动将其 SAML 身份链接到现有的极狐GitLab 帐户。有关更多信息,请参阅为现有用户启用 OmniAuth 。
在极狐GitLab 私有化部署上配置群组 SAML SSO#
等级:专业版、旗舰版
提供:极狐GitLab 私有化部署、极狐GitLab 专用
如果您必须允许通过多个 SAML IdP 访问您的极狐GitLab 私有化部署实例,请使用群组 SAML SSO。
要配置群组 SAML SSO:
Linux 软件包 (Omnibus) Helm chart (Kubernetes) Docker 自编译 (source)
确保极狐GitLab 已使用 HTTPS 配置 。
编辑 /etc/gitlab/gitlab.rb 以启用 OmniAuth 和 group_saml 提供者:
gitlab_rails [ 'omniauth_enabled' ] = true
gitlab_rails [ 'omniauth_providers' ] = [ { name : 'group_saml' } ]
保存文件并重新配置极狐GitLab:
sudo gitlab-ctl reconfigure
确保极狐GitLab 已使用 HTTPS 配置 。
将以下内容放入名为 group_saml.yaml 的文件中,以用作
Kubernetes Secret :
创建 Kubernetes Secret:
kubectl create secret generic -n < namespace > gitlab-group-saml --from-file = provider = group_saml.yaml
导出 Helm 值:
helm get values gitlab > gitlab_values.yaml
编辑 gitlab_values.yaml 以启用 OmniAuth 和 group_saml 提供者:
1 global :
2 appConfig :
3 omniauth :
4 enabled : true
5 providers :
6 - secret : gitlab - group - saml
保存文件并应用新值:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
确保极狐GitLab 已使用 HTTPS 配置 。
编辑 docker-compose.yml 以启用 OmniAuth 和 group_saml 提供者:
1 version : "3.6"
2 services :
3 gitlab :
4 environment :
5 GITLAB_OMNIBUS_CONFIG : |
6 gitlab_rails['omniauth_enabled'] = true
7 gitlab_rails['omniauth_providers'] = [{ name: 'group_saml' }]
保存文件并重启极狐GitLab:
确保极狐GitLab 已使用 HTTPS 配置 。
编辑 /home/git/gitlab/config/gitlab.yml 以启用 OmniAuth 和 group_saml 提供者:
production : &base
omniauth :
enabled : true
providers :
- { name : 'group_saml' }
保存文件并重启极狐GitLab:
# 对于使用 systemd 的系统
sudo systemctl restart gitlab.target
# 对于使用 SysV init 的系统
sudo service gitlab restart
作为多租户解决方案,与推荐的实例范围的 SAML 相比,极狐GitLab 私有化部署上的群组 SAML 是有限的。使用实例范围的 SAML 来利用:
为您的 IdP 上的 SAML 应用程序进行额外配置#
在 IdP 上配置 SAML 应用程序时,您的 IdP 可能需要额外的配置,例如以下内容:
字段 值 备注 SAML 配置文件 Web 浏览器 SSO 配置文件 极狐GitLab 使用 SAML 通过浏览器登录用户。没有直接向 IdP 发出的请求。 SAML 请求绑定 HTTP 重定向 极狐GitLab(SP)重定向用户到您的 IdP,带有 base64 编码的 SAMLRequest HTTP 参数。 SAML 响应绑定 HTTP POST 指定您的 IdP 发送 SAML 令牌的方式。包括 SAMLResponse ,用户的浏览器提交回极狐GitLab。 签署 SAML 响应 必需 防止篡改。 响应中的 X.509 证书 必需 签署响应并根据提供的指纹检查响应。 指纹算法 SHA-1 极狐GitLab 使用证书的 SHA-1 哈希值来签署 SAML 响应。 签名算法 SHA-1/SHA-256/SHA-384/SHA-512 确定响应的签名方式。也称为摘要方法,可以在 SAML 响应中指定。 加密 SAML 断言 可选 在您的身份提供商、用户浏览器和极狐GitLab 之间使用 TLS。 签署 SAML 断言 可选 验证 SAML 断言的完整性。激活时,签署整个响应。 检查 SAML 请求签名 可选 检查 SAML 响应上的签名。 默认 RelayState 可选 指定用户在通过您的 IdP 成功通过 SAML 登录后应该到达的基本 URL 的子路径。 NameID 格式 持久 请参阅 NameID 格式详情 。 其他 URL 可选 可能包括发行者、标识符或断言消费者服务 URL 在某些提供商的其他字段中。
有关示例配置,请参阅特定提供者的说明 。
使用 Geo 配置 SAML#
要使用 SAML 配置 Geo,请参阅配置实例范围的 SAML 。
有关更多信息,请参阅使用单点登录(SSO)的 Geo 。
术语表#
术语 描述 身份提供者 (IdP) 管理您的用户身份的服务,例如 Okta 或 OneLogin。 服务提供者 (SP) 从 SAML IdP(如 Okta)获取断言来认证用户。您可以将极狐GitLab 配置为 SAML 2.0 SP。 断言 关于用户身份的信息,例如他们的姓名或角色。也称为声明或属性。 单点登录 (SSO) 认证方案的名称。 断言消费者服务 URL 极狐GitLab 上用户在成功通过 IdP 认证后重定向的回调。 发行者 极狐GitLab 向 IdP 标识自己的方式。也称为“依赖方信任标识符”。 证书指纹 通过检查服务器是否使用正确的证书签署通信,确认 SAML 通信的安全性。也称为证书指纹。
故障排除#
请参阅我们的故障排除 SAML 指南 。