[GH-ISSUE #2] Doesn't work for 15.9.0-pre #1

Open
opened 2026-02-26 12:39:38 +03:00 by kerem · 7 comments
Owner

Originally created by @alexey-sh on GitHub (Feb 15, 2023).
Original GitHub issue: https://github.com/CONIGUERO/gitlab-license/issues/2

This solves the issue

just from gdk directory:

ruby gen.rb
cp -f license_key.pub  gitlab/.license_encryption_key.pub
gdk restart

gen.rb

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"    => "Douwe Maan",
  "Company" => "GitLab B.V.",
  "Email"   => "douwe@gitlab.com"
}

# The date the license starts.
# Required.
license.starts_at         = Date.new(2022, 4, 24)
# The date the license expires.
# Not required, to allow lifetime licenses.
license.expires_at        = Date.new(2024, 4, 23)

# 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(2024, 4, 19)

# The date regular users will be notified about the license's pending expiration.
# Not required.
license.notify_users_at   = Date.new(2024, 4, 23)

# 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(2024, 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: 1000

  # 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")

# 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 = User.active.count
#   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
Originally created by @alexey-sh on GitHub (Feb 15, 2023). Original GitHub issue: https://github.com/CONIGUERO/gitlab-license/issues/2 This solves the issue just from gdk directory: ``` ruby gen.rb cp -f license_key.pub gitlab/.license_encryption_key.pub gdk restart ``` **gen.rb** ``` 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" => "Douwe Maan", "Company" => "GitLab B.V.", "Email" => "douwe@gitlab.com" } # The date the license starts. # Required. license.starts_at = Date.new(2022, 4, 24) # The date the license expires. # Not required, to allow lifetime licenses. license.expires_at = Date.new(2024, 4, 23) # 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(2024, 4, 19) # The date regular users will be notified about the license's pending expiration. # Not required. license.notify_users_at = Date.new(2024, 4, 23) # 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(2024, 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: 1000 # 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") # 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 = User.active.count # 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 ```
Author
Owner

@strickes commented on GitHub (May 11, 2023):

did you get it to work with 15.11?

<!-- gh-comment-id:1543856190 --> @strickes commented on GitHub (May 11, 2023): did you get it to work with 15.11?
Author
Owner

@alexey-sh commented on GitHub (May 12, 2023):

@strickes I didn't try 15.11

<!-- gh-comment-id:1546353264 --> @alexey-sh commented on GitHub (May 12, 2023): @strickes I didn't try 15.11
Author
Owner

@strickes commented on GitHub (May 24, 2023):

well it worked for 15.11, but it crashes on 16.x :D

<!-- gh-comment-id:1561238360 --> @strickes commented on GitHub (May 24, 2023): well it worked for 15.11, but it crashes on 16.x :D
Author
Owner

@raphaelbarreiros commented on GitHub (Jul 12, 2023):

@alexey-sh did you managed to make it work on v16? tks

<!-- gh-comment-id:1632848523 --> @raphaelbarreiros commented on GitHub (Jul 12, 2023): @alexey-sh did you managed to make it work on v16? tks
Author
Owner

@JounQin commented on GitHub (Feb 13, 2024):

well it worked for 15.11, but it crashes on 16.x :D

It does not work to me on v15.11, image: gitlab/gitlab-ee:15.11.13-ee.0

image
<!-- gh-comment-id:1942153203 --> @JounQin commented on GitHub (Feb 13, 2024): > well it worked for 15.11, but it crashes on 16.x :D It does not work to me on v15.11, `image: gitlab/gitlab-ee:15.11.13-ee.0` <img width="519" alt="image" src="https://github.com/CONIGUERO/gitlab-license/assets/8336744/e966a596-0d51-4409-aff0-0002fdb5b379">
Author
Owner

@alexey-sh commented on GitHub (Feb 14, 2024):

@raphaelbarreiros

I left the company where I worked on it.

I bet it shouldn't be hard to tune v16 because gitlab is not well developed (IMHO). Maybe chinese guys have a solution.

@JounQin
Do you have any logs? It must log a cause of the error.

<!-- gh-comment-id:1942934734 --> @alexey-sh commented on GitHub (Feb 14, 2024): @raphaelbarreiros I left the company where I worked on it. I bet it shouldn't be hard to tune v16 because gitlab is not well developed (IMHO). Maybe chinese guys have a solution. @JounQin Do you have any logs? It must log a cause of the error.
Author
Owner

@JounQin commented on GitHub (Feb 14, 2024):

Do you have any logs? It must log a cause of the error.

@alexey-sh Sorry, I've recreate the GitLab instance from latest tag instead without license enabled yet.

<!-- gh-comment-id:1943144754 --> @JounQin commented on GitHub (Feb 14, 2024): > Do you have any logs? It must log a cause of the error. @alexey-sh Sorry, I've recreate the GitLab instance from latest tag instead without license enabled yet.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/gitlab-license#1
No description provided.