从版本 2.8.92 开始,Semaphore 支持通过 OpenID 进行身份验证。 在本文中,我们将探讨如何设置 Ansible Semaphore 以通过 GitLab 进行用户身份验证。

通过 OpenID 配置身份验证的第一步是设置提供者,在我们的案例中是 GitLab。

1. 在 GitLab 中创建应用

要通过 GitLab 启用身份验证,您需要在 GitLab 帐户设置中创建一个应用。

  1. 转到 GitLab 帐户设置中的应用程序部分: https://gitlab.com/-/profile/applications
  2. 填写必填字段:
    • 重定向 URLhttp://localhost:3000/api/auth/oidc/gitlab/redirect.
    • 范围openidprofileemail

    gitlab app create

  3. 点击 保存应用 后,您将看到以下屏幕:
  4. gitlab app config
  5. 复制并保存密钥(这将用于配置 Semaphore),然后点击 继续
  6. 应用已准备就绪。
  7. gitlab app list

2. 将 OpenID 设置添加到 Semaphore 的配置文件

如您所知,Semaphore 设置存储在配置文件中(通常是 config.json)以 JSON 格式。

我们需要向其中添加以下设置,以便 Semaphore 知道如何使用 GitLab 作为 OpenID 提供者:

"oidc_providers": {
   "gitlab": {
       "display_name": "GitLab",
       "provider_url": "https://gitlab.com",
       "client_id": "应用程序 ID",
       "client_secret": "密钥",
       "redirect_url": "http://localhost:4000/api/auth/oidc/gitlab/redirect"
   }
}

3. 使用 OpenID/GitLab 身份验证启动 Semaphore

在您保存了配置文件中的更改后,请使用新设置启动或重启 Semaphore。

您会在 Semaphore 登录页面上看到一个新的 "GitLab" 按钮。

semaphore login screen