summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-05-31 05:22:56 +0000
committerStan Hu <stanhu@gmail.com>2019-05-31 05:22:56 +0000
commit6189c869b87aa469f5efb058834cd65afd8fe563 (patch)
tree70a5fdd93cea81aed9c1638bc32513a1fdf84bb7 /lib
parentc8c08d326942f30ad87d0702cc8b9c5896d296ad (diff)
parent39e21fb2661693fed914012a39fb3a53b2b687c2 (diff)
downloadgitlab-ce-6189c869b87aa469f5efb058834cd65afd8fe563.tar.gz
Merge branch 'generate-letsencrypt-private_key-on-the-fly' into 'master'
Generate letsencrypt private key on the fly Closes #62452 See merge request gitlab-org/gitlab-ce!28855
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/lets_encrypt/client.rb23
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/gitlab/lets_encrypt/client.rb b/lib/gitlab/lets_encrypt/client.rb
index 5501f7981ec..66aea137012 100644
--- a/lib/gitlab/lets_encrypt/client.rb
+++ b/lib/gitlab/lets_encrypt/client.rb
@@ -3,6 +3,8 @@
module Gitlab
module LetsEncrypt
class Client
+ include Gitlab::Utils::StrongMemoize
+
PRODUCTION_DIRECTORY_URL = 'https://acme-v02.api.letsencrypt.org/directory'
STAGING_DIRECTORY_URL = 'https://acme-staging-v02.api.letsencrypt.org/directory'
@@ -35,6 +37,8 @@ module Gitlab
def enabled?
return false unless Feature.enabled?(:pages_auto_ssl)
+ return false unless private_key
+
Gitlab::CurrentSettings.lets_encrypt_terms_of_service_accepted
end
@@ -45,7 +49,11 @@ module Gitlab
end
def private_key
- @private_key ||= OpenSSL::PKey.read(Gitlab::CurrentSettings.lets_encrypt_private_key)
+ strong_memoize(:private_key) do
+ private_key_string = Gitlab::CurrentSettings.lets_encrypt_private_key
+ private_key_string ||= generate_private_key
+ OpenSSL::PKey.read(private_key_string) if private_key_string
+ end
end
def admin_email
@@ -69,6 +77,19 @@ module Gitlab
STAGING_DIRECTORY_URL
end
end
+
+ def generate_private_key
+ return if Gitlab::Database.read_only?
+
+ application_settings = Gitlab::CurrentSettings.current_application_settings
+ application_settings.with_lock do
+ unless application_settings.lets_encrypt_private_key
+ application_settings.update(lets_encrypt_private_key: OpenSSL::PKey::RSA.new(4096).to_pem)
+ end
+
+ application_settings.lets_encrypt_private_key
+ end
+ end
end
end
end