在极狐GitLab 身份验证中如何使用 JWT?

极狐GitLab 是 GitLab 在中国的发行版,关于中文参考文档和资料有:

使用 JWT 作为身份验证提供者 (BASIC SELF)

要启用 JWT OmniAuth 提供者,您必须向 JWT 注册您的应用程序。JWT 为您提供一个用于使用的密钥。

1.在您的极狐GitLab 服务器上,打开配置文件。

对于 Linux 软件包安装:

swift 复制代码
sudo editor /etc/gitlab/gitlab.rb

对于自编译安装:

bash 复制代码
cd /home/git/gitlab
sudo -u git -H editor config/gitlab.yml

2.配置通用设置以添加 jwt 作为单点登录提供者。这为没有现有极狐GitLab 账户的用户启用即时账户配置。

3.添加提供者配置。

对于 Linux 软件包安装:

bash 复制代码
gitlab_rails['omniauth_providers'] = [
  { name: "jwt",
    label: "Provider name", # optional label for login button, defaults to "Jwt"
    args: {
      secret: "YOUR_APP_SECRET",
      algorithm: "HS256", # Supported algorithms: "RS256", "RS384", "RS512", "ES256", "ES384", "ES512", "HS256", "HS384", "HS512"
      uid_claim: "email",
      required_claims: ["name", "email"],
      info_map: { name: "name", email: "email" },
      auth_url: "https://example.com/",
      valid_within: 3600 # 1 hour
    }
  }
]

对于自编译安装:

bash 复制代码
- { name: 'jwt',
    label: 'Provider name', # optional label for login button, defaults to "Jwt"
    args: {
      secret: 'YOUR_APP_SECRET',
      algorithm: 'HS256', # Supported algorithms: 'RS256', 'RS384', 'RS512', 'ES256', 'ES384', 'ES512', 'HS256', 'HS384', 'HS512'
      uid_claim: 'email',
      required_claims: ['name', 'email'],
      info_map: { name: 'name', email: 'email' },
      auth_url: 'https://example.com/',
      valid_within: 3600 # 1 hour
    }
  }

WARNING:

不正确地配置这些设置可能导致实例不安全。

4.将 YOUR_APP_SECRET 更改为客户端密钥,并将 auth_url 设置为您的重定向 URL。

5.保存配置文件。

6.为了使更改生效,如果您:

  • 使用 Linux 软件包安装了极狐GitLab,请重新配置极狐GitLab。
  • 自编译了您的极狐GitLab 安装,请重启极狐GitLab。

在登录页面,现在应该在常规登录表单下方有一个 JWT 图标。选择该图标以开始身份验证过程。JWT 要求用户登录并授权极狐GitLab 应用程序。如果一切顺利,用户将被重定向到极狐GitLab 并登录。

相关推荐
尽兴-16 小时前
企业业务系统架构选型与渐进式演进
运维·系统架构·devops
酿情师1 天前
Gitlab 任意文件读取漏洞(CVE-2016-9086)
gitlab
MicrosoftReactor1 天前
技术速递|智能体构建智能体:基于 Microsoft Agent Framework 与 Foundry 的 Skill 优先架构蓝图
ai·架构·agent·智能体·mcp
牧艺2 天前
从 Tool Calling 到 MCP Server:把业务能力做成 Agent 可复用接口
agent·全栈·mcp
凡泰AI2 天前
如何借助MCP打通企业APP内部服务:从统一调用到小程序承接
小程序·uni-app·app·mpaas·mcp·小程序容器
至乐活着2 天前
Ansible自动化运维实战:从零部署高可用Nginx+静态网站集群
ansible·自动化运维·devops·playbook·配置管理
糖果罐子♡2 天前
TortoiseGit 首次上传本地工程至已初始化的GitLab仓库教程
gitlab
Byron Loong2 天前
【Git】如何检查 Ubuntu 系统上 gitLab 是否开启
git·ubuntu·gitlab
QN1幻化引擎3 天前
SFA 信号场注意力:用8KB参数换248x KV Cache压缩,边缘设备也能跑长序列
人工智能·算法·gitee·gitlab