【GitLab EE 】指南
⚠️ 免责声明
由于需要一些镜像等 GitLab 高级功能,以下内容涉及 GitLab EE 版本破解。这些破解方法来自官方文档的历史遗留或开源项目。仅供个人研究学习使用,企业环境请务必付费购买正版授权。
- 已经在 GitLab EE 18.5 上验证可行
使用 Ruby 生成许可证
1. 安装 Ruby
安装完 GitLab EE 之后,需要安装 Ruby(版本需 2.3 或以上):
yum install ruby
2. 安装依赖 gem
gem install gitlab-license
3. 创建生成脚本 (license.rb)
创建一个名为 license.rb 的文件,并填入以下内容:
require "openssl"
require "gitlab/license"
key_pair = OpenSSL::PKey::RSA.generate(2048)
File.open("license_key", "w") { |f| f.write(key_pair.to_pem) }
public_key = key_pair.public_key
File.open("license_key.pub", "w") { |f| f.write(public_key.to_pem) }
private_key = OpenSSL::PKey::RSA.new File.read("license_key")
Gitlab::License.encryption_key = private_key
license = Gitlab::License.new
license.licensee = {
"Name" => "none",
"Company" => "none",
"Email" => "example@test.com",
}
license.starts_at = Date.new(2020, 1, 1) # 开始时间
license.expires_at = Date.new(2050, 1, 1) # 结束时间
license.notify_admins_at = Date.new(2049, 12, 1)
license.notify_users_at = Date.new(2049, 12, 1)
license.block_changes_at = Date.new(2050, 1, 1)
license.restrictions = {
active_user_count: 10000,
}
puts "License:"
puts license
data = license.export
puts "Exported license:"
puts data
File.open("GitLabBV.gitlab-license", "w") { |f| f.write(data) }
public_key = OpenSSL::PKey::RSA.new File.read("license_key.pub")
Gitlab::License.encryption_key = public_key
data = File.read("GitLabBV.gitlab-license")
$license = Gitlab::License.import(data)
puts "Imported license:"
puts $license
unless $license
raise "The license is invalid."
end
if $license.restricted?(:active_user_count)
active_user_count = 10000
if active_user_count > $license.restrictions[:active_user_count]
raise "The active user count exceeds the allowed amount!"
end
end
if $license.notify_admins?
puts "The license is due to expire on #{$license.expires_at}."
end
if $license.notify_users?
puts "The license is due to expire on #{$license.expires_at}."
end
module Gitlab
class GitAccess
def check(cmd, changes = nil)
if $license.block_changes?
return build_status_object(false, "License expired")
end
end
end
end
puts "This instance of GitLab Enterprise Edition is licensed to:"
$license.licensee.each do |key, value|
puts "#{key}: #{value}"
end
if $license.expired?
puts "The license expired on #{$license.expires_at}"
elsif $license.will_expire?
puts "The license will expire on #{$license.expires_at}"
else
puts "The license will never expire."
end4. 执行生成
ruby license.rb执行后会生成三个文件:GitLabBV.gitlab-license、license_key 和 license_key.pub。
5. 替换公钥与导入 License
- 用生成的
license_key.pub替换系统文件:
/opt/gitlab/embedded/service/gitlab-rails/.license_encryption_key.pub - 重启 GitLab:
gitlab-ctl restart - 进入 GitLab 管理后台
/admin/license,上传GitLabBV.gitlab-license文件。
6. 修改等级 (可选)
修改代码以强制开启 Ultimate 计划:
# 文件路径: /opt/gitlab/embedded/service/gitlab-rails/ee/app/models/license.rb
def plan
- restricted_attr(:plan).presence || STARTER_PLAN
+ restricted_attr(:plan).presence || ULTIMATE_PLAN
end使用 Docker 方式生成 (GitLab-License-Generator)
由于原 GitHub 仓库可能被 DMCA 删除,建议使用以下方式手动运行。
Docker 快速运行
docker run --rm -it \
-v "./license:/license-generator/build" \
-e LICENSE_NAME="Tim Cook" \
-e LICENSE_COMPANY="Apple Computer, Inc." \
-e LICENSE_EMAIL="tcook@apple.com" \
-e LICENSE_PLAN="ultimate" \
-e LICENSE_USER_COUNT="2147483647" \
-e LICENSE_EXPIRE_YEAR="2500" \
ghcr.io/lakr233/gitlab-license-generator:main手动构建与运行
如果镜像不可用,可以手动操作:
- 进入 GitLab 容器或具备 Ruby 环境的机器。
- 安装依赖:
apt update && apt install ruby-full gem install bundler gem install gitlab-license - 克隆代码并修改
src/scan.features.rb(代码过长,请参考上文 Ruby 部分或原仓库)。 - 运行生成脚本:
chmod +x src/scan.features.rb LICENSE_PLAN="ultimate" LICENSE_EXPIRE_YEAR="2500" ./make.sh
应用 Docker 生成的许可证
将生成的 build/public.key 挂载或复制到容器中:
Docker Compose 方式:
volumes:
- "./build/public.key:/opt/gitlab/embedded/service/gitlab-rails/.license_encryption_key.pub"重启容器后,进入后台上传 result.gitlab-license 即可。
关闭 Service Ping (可选)
为了隐私,建议关闭 GitLab 的使用情况统计:
- 编辑配置:
sudo nano /etc/gitlab/gitlab.rb - 添加或修改:
gitlab_rails['usage_ping_enabled'] = false - 重载配置:
sudo gitlab-ctl reconfigure sudo gitlab-ctl restart
参考资料:
GitLab-License-Generator |
原文链接
【GitLab EE 】指南
https://blog.jiang.in/archives/9294bfe0-c96c-481f-a121-db1d8594f0f1