从版本 2.8.92 开始,Semaphore 支持通过 OpenID 进行身份验证。 在本文中,我们将介绍如何设置 Ansible Semaphore 通过 GitLab 验证用户。
通过 OpenID 配置身份验证首先需要设置提供者本身,在我们的例子中是 GitLab。
1. 在 GitLab 中创建应用
为了启用通过 GitLab 的身份验证,您需要在 GitLab 的账户设置中创建一个应用。
- 转到您的 GitLab 账户设置中的 Applications 部分: https://gitlab.com/-/profile/applications
- 填写必填字段:
- 重定向 URL:
http://localhost:3000/api/auth/oidc/gitlab/redirect
。 - Scopes(权限范围):
openid
,profile
,email
。 - 点击 保存应用 后,您会看到如下界面:
- 将密钥复制并保存到某处(配置 Semaphore 时需要),然后点击 继续。
- 应用已就绪。


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" 按钮。