约 4 分钟阅读
DevOps

Gitlab Enterprise Edition 企业版自签许可证

由于本地测试Gitlab企业版功能,这里采用自签名方式安装且证书。

Gitlab Enterprise Edition 企业版自签许可证
SYSTEM更新于 May 17, 2024
224 次阅读约 4 分钟阅读
专栏系列Gitlab 指南
本文目录大纲

背景

本文安装gitlab-ee企业版自签license。旨在学习GitOps相关操作方法。

安装步骤

安装ruby环境

安装gem包依赖

SH
gem install gitlab-license

# 以下缺少的时候安装
gem install gitlab
gem install openssl

创建脚本文件

vim gitlab_ee_license.rb

RUBY
require 'openssl'
require 'gitlab/license'

# Generate a key pair. You should do this only once.
key_pair = OpenSSL::PKey::RSA.generate(2048)

# Write it to a file to use in the license generation application.
File.open("license_key", "w") { |f| f.write(key_pair.to_pem) }

# Extract the public key.
public_key = key_pair.public_key
# Write it to a file to ship along with the main application.
File.open("license_key.pub", "w") { |f| f.write(public_key.to_pem) }

# In the license generation application, load the private key from a file.
private_key = OpenSSL::PKey::RSA.new File.read("license_key")
Gitlab::License.encryption_key = private_key

# Build a new license.
license = Gitlab::License.new

# License information to be rendered as a table in the admin panel.
# E.g.: "This instance of GitLab Enterprise Edition is licensed to:"
# Specific keys don't matter, but there needs to be at least one.
license.licensee = {
	"Name"    => "Google",
	"Company" => "Google.Inc",
	"Email"   => "Administrator@gmail.com"
}

# The date the license starts. 
# Required.
license.starts_at         = Date.new(2021, 4, 24) # license 开始生效时间
# The date the license expires. 
# Not required, to allow lifetime licenses.
license.expires_at        = Date.new(2039, 4, 23) # license 到期时间

# The below dates are hardcoded in the license so that you can play with the
# period after which there are "repercussions" to license expiration.

# The date admins will be notified about the license's pending expiration. 
# Not required.
license.notify_admins_at  = Date.new(2036, 3, 23) # license 管理员过期提醒时间

# The date regular users will be notified about the license's pending expiration.
# Not required.
license.notify_users_at   = Date.new(2036, 3, 23) # license 普通用户过期提醒时间

# The date "changes" like code pushes, issue or merge request creation 
# or modification and project creation will be blocked.
# Not required.
license.block_changes_at  = Date.new(2036, 5, 7) 

# Restrictions bundled with this license.
# Not required, to allow unlimited-user licenses for things like educational organizations.
license.restrictions  = {
	# The maximum allowed number of active users.
	# Not required.
	active_user_count: 10000  # license 人数配额
	
	# We don't currently have any other restrictions, but we might in the future.
}

puts "License:"
puts license

# Export the license, which encrypts and encodes it.
data = license.export

puts "Exported license:"
puts data

# Write the license to a file to send to a customer.
File.open("GitLabBV.gitlab-license", "w") { |f| f.write(data) }

# In the customer's application, load the public key from a file.
public_key = OpenSSL::PKey::RSA.new File.read("license_key.pub")
Gitlab::License.encryption_key = public_key

# Read the license from a file.
data = File.read("GitLabBV.gitlab-license")  # 生成license存储文件名

# Import the license, which decodes and decrypts it.
$license = Gitlab::License.import(data)

puts "Imported license:"
puts $license

# Quit if the license is invalid
unless $license
	raise "The license is invalid."
end

# Quit if the active user count exceeds the allowed amount:
if $license.restricted?(:active_user_count)
	active_user_count = 1000
	if active_user_count > $license.restrictions[:active_user_count]
		raise "The active user count exceeds the allowed amount!"
	end
end

# Show admins a message if the license is about to expire.
if $license.notify_admins?
	puts "The license is due to expire on #{$license.expires_at}."
end

# Show users a message if the license is about to expire.
if $license.notify_users?
	puts "The license is due to expire on #{$license.expires_at}."
end

# Block pushes when the license expired two weeks ago.
module Gitlab
	class GitAccess
		# ...
		def check(cmd, changes = nil)
			if $license.block_changes?
				return build_status_object(false, "License expired")
			end
	
			# Do other Git access verification
			# ...
		end
		# ...
	end
end

# Show information about the license in the admin panel.
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."
end

执行脚本:

SH
$ ruby gitlab_ee_license.rb
License:
#<Gitlab::License:0x0000000001434ee0>
Exported license:
eyJkYXRhIjoiT1JrbGg5TU9hKzVPZ2RsMVRSZDBKbDRFUEdDVU5lMzBzbmdB
TWZxYnhJREp6OXBMMjZVdDdG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==
Imported license:
#<Gitlab::License:0x00000000018afe98>
This instance of GitLab Enterprise Edition is licensed to:
Name: tester
Company: Google Inc
Email: test@163.com
The license will expire on 2026-04-23

并且生成了文件

SH
-rw-r--r--. 1 root root 1131 Feb 22 08:35 GitLabBV.gitlab-license
-rw-r--r--. 1 root root 1675 Feb 22 08:35 license_key
-rw-r--r--. 1 root root  451 Feb 22 08:35 license_key.pub

替换公钥

  1. 先将 license_key.pub 的内容替换到 /opt/gitlab/embedded/service/gitlab-rails/.license_encryption_key.pub.

  2. 修改 gitlab-ee 等级为 ULTIMATE_PLAN

    SH
    $ vim /opt/gitlab/embedded/service/gitlab-rails/ee/app/models/license.rb
    # 找到下面这部分中的内容
    def plan
    	restricted_attr(:plan).presence || STARTER_PLAN  ## 将STARTER_PLAN 修改为 ULTIMATE_PLAN
    end
  3. 重启 gitlab-ctl restart.

  4. 导入授权文件:

    • 14.0 以前版本:菜单->管理员->订阅->许可证上传
    • 14.0 之后版本:菜单->管理员->设置->通用->添加许可证处

关于国内的极狐版本

替换位置为jh文件夹下:

PLAINTEXT
/opt/gitlab/embedded/service/gitlab-rails/jh/.license_encryption_key.pub

附:一组公钥密钥

license_key.pub

PLAINTEXT
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqwEYvgLwuBJRCXAoAcp5
rLlaf30PXhcei6OrYY2O1ewjnY9cEJQPQItFQ9KoYj4wJVjFIiFzU1Z+A21EUzYQ
0gk4f4EoJVwTmY/+T3gidHWtZnI6yLrmsdFMO7inAV1jRhGjoFBEliPNtzzmknzx
WNJnVl6exnJMwTF4i5kOB0iJR7RrTikSVu2lgWnT+nl1pZfG2xpeKUYDSW89ZxNR
sVNW88REXNgaKw0X9AEV+83TPXjHgVMa2FHWuGTyvyywKsUPTvbh1VE3LC5jvP8f
gUdMJTcxxs7cF3PvbddQPQcNZcDs09q4TMqD7GgGEgZu3kaJuSqDHI5WVm7RSCek
XwIDAQAB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