跳到主内容

Sentry

Sentry 是一个错误跟踪和性能监控平台。其组织可以通过 SAML 2.0 身份提供商 (IdP) 让成员登录。使用 Casdoor 作为 IdP,成员可以使用其 Casdoor 账号登录 Sentry。

在 sentry.io 上,SAML2 需要 Business 或 Enterprise 计划。自托管 Sentry 从 20.6.0 版本开始内置了此功能,且功能 organizations:sso-basic 和 organizations:sso-saml2 默认开启。

准备 Sentry​

Sentry 根据 system.url-prefix 构建提供给 IdP 的 URL。在自托管 Sentry 上,在 sentry/config.yml 中将其设置为公开 URL,并使用用户打开的协议:

system.url-prefix: 'https://sentry.example.com'

修改后重启 Sentry。如果未设置此项,登录将失败,通常在用户从 Casdoor 返回后出现 HTTP 500 错误。

在 Casdoor 中创建应用​

示例中使用的 Sentry 组织 slug 为 my-org。请在组织设置的 URL 中查找您的 slug。

  1. 在 Casdoor 管理控制台中,打开您的用户所在的组织并添加一个应用,或打开现有的应用。

  2. 将 Sentry 的实体 ID 添加到 Redirect URLs。Sentry 使用其元数据 URL 作为其实体 ID:

    https://sentry.example.com/saml/metadata/my-org/
  3. 在 SAML 选项卡上,将 SAML reply URL 设置为 Sentry 的断言消费服务 (ACS) URL:

    https://sentry.example.com/saml/acs/my-org/
  4. 保持 Enable SAML assertion signature 和 Enable SAML C14N10 为关闭状态。此时 Casdoor 会对 SAML 响应进行签名,Sentry 会验证该签名。如果开启断言签名,Sentry 会拒绝响应并报错:Signature validation failed. SAML Response rejected。

  5. 保存后,点击 Copy SAML metadata URL。URL 的格式如下:

    https://door.example.com/api/saml/metadata?application=admin/<application-name>

在 Sentry 中配置 SAML2​

  1. 在 Sentry 中,转到组织的 Settings > Auth,并点击 SAML2 旁边的 Configure。

  2. 在 Metadata URL 选项卡上,在 Metadata URL 中输入来自 Casdoor 的元数据 URL,然后点击 Get metadata。

    如果 Sentry 无法访问 Casdoor,请在浏览器中打开元数据 URL,并将 XML 粘贴到 XML 选项卡的 Metadata XML 中。

  3. 映射 Casdoor 发送的属性:

    FieldValue
    IdP User IDName
    User EmailEmail
    First NameDisplayName
    Last Name(empty)

    Casdoor 在 Name 属性中发送用户名,在 DisplayName 中发送显示名。参见 User profile in the response。

  4. 保存。此时 Auth 页面会显示 SAML2 作为组织的提供商。要提醒现有成员将其账号与 Casdoor 关联,请从此页面发送提醒。

验证结果​

  1. 在私密浏览器窗口中打开 https://sentry.example.com/auth/login/my-org/ 并使用单点登录进行登录。
  2. 登录 Casdoor。Sentry 将打开组织,并以 Casdoor 用户身份登录。尚未成为成员的用户将在此首次登录时成为成员,并获得组织的默认角色。

故障排除​

SymptomCause and fix
SAML SSO failed, Signature validation failed. SAML Response rejectedTurn off Enable SAML assertion signature and Enable SAML C14N10 on the application. If it persists, fetch the metadata again: Sentry must have the certificate of the application's current Cert.
Failed to map SAML attributesAn attribute name in the mapping doesn't match. The message lists the attribute names that the response contains. Check that Disable SAML attributes is off.
Casdoor shows AssertionConsumerServiceURL: ... doesn't match the SAML reply URL or the allowed Redirect URI listSet SAML reply URL to the ACS URL of Sentry, with the organization slug and the trailing slash.
Sentry returns HTTP 500 after the sign-insystem.url-prefix isn't set or differs from the URL that users open. Fix it and restart Sentry.
Get metadata fails with a certificate errorSentry checks the TLS certificate of Casdoor. Serve Casdoor with a valid certificate, or paste the metadata XML instead.

另请参阅​