SAML 2.0 身份认证
BookStack 可配置为使用基于 SAML 2.0 的身份认证提供商,使用户能够在 BookStack 内登录、注销和自行注册。这将替代 BookStack 默认的电子邮件和密码身份认证机制。启用后,BookStack 会尝试根据已存储的外部 ID 属性将 SAML 用户与现有 BookStack 用户进行匹配;如果未找到匹配项,BookStack 将自动注册该用户,从而提供无缝的访问体验。
BookStack 配置
要设置基于 SAML 2.0 的身份认证,请在你的 .env 文件中添加或修改以下变量:
# Set authentication method to be saml2
AUTH_METHOD=saml2
# Control if BookStack automatically initiates login via your SAML system if it's the only authentication method.
# Prevents the need for the user to click the "Login with x" button on the login page.
# Setting this to true enables auto-initiation.
AUTH_AUTO_INITIATE=false
# Set the display name to be shown on the login button.
# (Login with <name>)
SAML2_NAME=SSO
# Name of the attribute which provides the user's email address
SAML2_EMAIL_ATTRIBUTE=email
# Name of the attribute to use as an ID for the SAML user.
SAML2_EXTERNAL_ID_ATTRIBUTE=uid
# Name of the attribute(s) to use for the user's display name
# Can have multiple attributes listed, separated with a '|' in which
# case those values will be joined with a space.
# Example: SAML2_DISPLAY_NAME_ATTRIBUTES=firstName|lastName
# Defaults to the ID value if not found.
SAML2_DISPLAY_NAME_ATTRIBUTES=username
# Identity Provider entityID URL
SAML2_IDP_ENTITYID=https://example.com/saml2/idp/metadata.php
# Auto-load metadata from the IDP
# Setting this to true negates the need to specify the next three options
SAML2_AUTOLOAD_METADATA=false
# Identity Provider single-sign-on service URL
# Not required if using the autoload option above.
SAML2_IDP_SSO=https://example.com/saml2/idp/SSOService.php
# Identity Provider single-logout-service URL
# Not required if using the autoload option above.
# Not required if your identity provider does not support SLS.
SAML2_IDP_SLO=https://example.com/saml2/idp/SingleLogoutService.php
# Identity Provider x509 public certificate data.
# Not required if using the autoload option above.
SAML2_IDP_x509=<cert_data>
# Identity Provider AuthnContext
# Setting this to true (The default) and exact AuthnContext of
# 'urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport' will be used.
# Setting this to false will provide no AuthnContext to the IDP.
# Alternatively you can set this to a space separated list of values. For example:
# SAML2_IDP_AUTHNCONTEXT="urn:oasis:names:tc:SAML:2.0:ac:classes:Password urn:federation:authentication:windows"
SAML2_IDP_AUTHNCONTEXT=true
# Service Provider Certificate & Key (Optional)
# Providing these will provide key data within BookStack's metadata endpoint
# while implicitly enabling signing on Authn and Logout requests.
# This is often required to support Single Logout Service in an ADFS environment.
SAML2_SP_x509=<cert_data>
SAML2_SP_x509_KEY=<key_data>
BookStack 中的用户将通过 SAML2_EXTERNAL_ID_ATTRIBUTE 与 SAML 用户关联。如果该 ID 的值在身份提供商中发生变化,管理员可以在用户个人资料中修改“External Authentication ID”字段,以在 BookStack 中更新该值。
身份提供商配置
你可能需要向身份提供商提供 BookStack 服务提供商的某些详细信息。以下是你可能需要的 URL 路径。此处仅显示相对路径,因此需要将其附加到 BookStack 基础 URL 之后。
/saml2/metadata- 元数据端点 (GET)/saml2/acs- 断言消费服务端点 (POST)/saml2/sls- 单点注销服务端点 (GET)
BookStack 使用以下格式/绑定与 IdP 通信:
- NameIDFormat:
urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress - Login/ACS 绑定:
urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST - Logout/SLO 绑定:
urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect
以下是为 SimpleSAMLphp IdP 配置 BookStack 服务提供商的最小示例:
$metadata['http://bookstack.local/saml2/metadata'] = [
'AssertionConsumerService' => 'http://bookstack.local/saml2/acs',
'SingleLogoutService' => 'http://bookstack.local/saml2/sls',
'NameIDFormat' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress',
];
调试
为帮助设置或配置 BookStack 使用你的 SAML 系统,以下几个额外的 .env 选项可提供更详细的信息:
# Enable the BookStack general debug mode, Provides more error insight.
# Note, Can leak sensitive details so only use in private, secure environments.
APP_DEBUG=true
# Option to dump out SAML 2.0 user details as JSON.
# Only for debugging purposes since it will prevent login.
SAML2_DUMP_USER_DETAILS=false
# Option to override settings passed to the underlying onelogin library
# used by BookStack. For development, debugging and testing only.
# Options provided will be recursively merged into other default & dynamic options.
# Defaults found within app/Config/saml2.php, under the 'onelogin' key.
SAML2_ONELOGIN_OVERRIDES=<json_format_data>
SAML 组同步
BookStack 能够将 SAML 用户组与 BookStack 角色进行同步。默认情况下,将根据 SAML 组名称匹配 BookStack 角色显示名称,且忽略大小写。
启用 SAML 身份认证后,编辑角色时可以看到“External Authentication IDs”字段,可通过该字段覆盖上述默认行为。如果填写了该字段,将使用其中的名称进行匹配,并忽略角色显示名称。可以使用逗号分隔多个名称进行匹配。如果需要使用字面逗号字符进行映射,可以使用反斜杠(\,)对逗号进行转义。
将 SAML 组与角色名称或“External Authentication IDs”值进行匹配时,BookStack 会将 SAML 组名称标准化为小写,并将空格替换为连字符。例如,要匹配名为“United Kingdom”的 SAML 组,可以使用“united-kingdom”作为“External Authentication IDs”值。
此功能要求 SAML 服务器能够在查询时提供用户组。你需要使用 SAML2_GROUP_ATTRIBUTE 选项指定属性,如下所示。请注意,可以使用上文调试部分所示的 SAML2_DUMP_USER_DETAILS 选项,输出 BookStack 从你的 IdP 获取的属性值。
启用组同步需要将以下设置添加到你的 .env 文件中:
# Enable SAML group sync.
SAML2_USER_TO_GROUPS=true
# Set the attribute from which BookStack will read groups names from.
SAML2_GROUP_ATTRIBUTE=groups
# Remove the user from roles that don't match SAML groups upon login.
# Note: While this is enabled the "Default Registration Role", editable within the
# BookStack settings view, will be considered a matched role and assigned to the user.
SAML2_REMOVE_FROM_GROUPS=true
谢谢你的反馈!