summaryrefslogtreecommitdiff
path: root/lib/gitlab/shell.rb
diff options
context:
space:
mode:
authorMichael Kozono <mkozono@gmail.com>2017-05-30 16:24:45 -0700
committerJames Edwards-Jones <jedwardsjones@gitlab.com>2018-01-08 20:34:19 +0000
commit255a0f85e3b62845b58f5a4aa189e57f36992c77 (patch)
tree339d54b2cf3a9408fa3014ab84a2ad426f65cb3c /lib/gitlab/shell.rb
parentac86b2043dea8f15cb0670db98c2bf21e1843d4b (diff)
downloadgitlab-ce-255a0f85e3b62845b58f5a4aa189e57f36992c77.tar.gz
Backport option to disable writing to `authorized_keys` file
Originally branch 'mk-toggle-writing-to-auth-keys-1631' See merge request !2004 Squashed commits: Add authorized_keys_enabled to Application Settings Ensure default settings are exposed in UI Without this change, `authorized_keys_enabled` is unchecked when it is nil, even if it should be checked by default. Add “Speed up SSH operations” documentation Clarify the reasons for disabling writes Add "How to go back" section Tweak copy Update Application Setting screenshot
Diffstat (limited to 'lib/gitlab/shell.rb')
-rw-r--r--lib/gitlab/shell.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/gitlab/shell.rb b/lib/gitlab/shell.rb
index 564047bbd34..20df19c734d 100644
--- a/lib/gitlab/shell.rb
+++ b/lib/gitlab/shell.rb
@@ -183,6 +183,8 @@ module Gitlab
# add_key("key-42", "sha-rsa ...")
#
def add_key(key_id, key_content)
+ return unless self.authorized_keys_enabled?
+
gitlab_shell_fast_execute([gitlab_shell_keys_path,
'add-key', key_id, self.class.strip_key(key_content)])
end
@@ -192,6 +194,8 @@ module Gitlab
# Ex.
# batch_add_keys { |adder| adder.add_key("key-42", "sha-rsa ...") }
def batch_add_keys(&block)
+ return unless self.authorized_keys_enabled?
+
IO.popen(%W(#{gitlab_shell_path}/bin/gitlab-keys batch-add-keys), 'w') do |io|
yield(KeyAdder.new(io))
end
@@ -203,6 +207,8 @@ module Gitlab
# remove_key("key-342", "sha-rsa ...")
#
def remove_key(key_id, key_content)
+ return unless self.authorized_keys_enabled?
+
args = [gitlab_shell_keys_path, 'rm-key', key_id]
args << key_content if key_content
@@ -215,6 +221,8 @@ module Gitlab
# remove_all_keys
#
def remove_all_keys
+ return unless self.authorized_keys_enabled?
+
gitlab_shell_fast_execute([gitlab_shell_keys_path, 'clear'])
end
@@ -410,5 +418,9 @@ module Gitlab
# need to do the same here...
raise Error, e
end
+
+ def authorized_keys_enabled?
+ current_application_settings.authorized_keys_enabled
+ end
end
end