Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
c08191e0
Commit
c08191e0
authored
Aug 23, 2019
by
Patrick Bajao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove the fallback path from gitlab-ce
parent
42484f55
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
482 deletions
+89
-482
lib/gitlab/shell.rb
lib/gitlab/shell.rb
+6
-80
spec/lib/gitlab/shell_spec.rb
spec/lib/gitlab/shell_spec.rb
+83
-402
No files found.
lib/gitlab/shell.rb
View file @
c08191e0
...
...
@@ -165,17 +165,8 @@ module Gitlab
def
add_key
(
key_id
,
key_content
)
return
unless
self
.
authorized_keys_enabled?
if
shell_out_for_gitlab_keys?
gitlab_shell_fast_execute
([
gitlab_shell_keys_path
,
'add-key'
,
key_id
,
strip_key
(
key_content
)
])
else
gitlab_authorized_keys
.
add_key
(
key_id
,
key_content
)
end
end
# Batch-add keys to authorized_keys
#
...
...
@@ -184,20 +175,8 @@ module Gitlab
def
batch_add_keys
(
keys
)
return
unless
self
.
authorized_keys_enabled?
if
shell_out_for_gitlab_keys?
begin
IO
.
popen
(
"
#{
gitlab_shell_keys_path
}
batch-add-keys"
,
'w'
)
do
|
io
|
add_keys_to_io
(
keys
,
io
)
end
$?
.
success?
rescue
Error
false
end
else
gitlab_authorized_keys
.
batch_add_keys
(
keys
)
end
end
# Remove ssh key from authorized_keys
#
...
...
@@ -207,12 +186,8 @@ module Gitlab
def
remove_key
(
id
,
_
=
nil
)
return
unless
self
.
authorized_keys_enabled?
if
shell_out_for_gitlab_keys?
gitlab_shell_fast_execute
([
gitlab_shell_keys_path
,
'rm-key'
,
id
])
else
gitlab_authorized_keys
.
rm_key
(
id
)
end
end
# Remove all ssh keys from gitlab shell
#
...
...
@@ -222,12 +197,8 @@ module Gitlab
def
remove_all_keys
return
unless
self
.
authorized_keys_enabled?
if
shell_out_for_gitlab_keys?
gitlab_shell_fast_execute
([
gitlab_shell_keys_path
,
'clear'
])
else
gitlab_authorized_keys
.
clear
end
end
# Remove ssh keys from gitlab shell that are not in the DB
#
...
...
@@ -341,14 +312,6 @@ module Gitlab
File
.
join
(
Gitlab
.
config
.
repositories
.
storages
[
storage
].
legacy_disk_path
,
dir_name
)
end
def
gitlab_shell_projects_path
File
.
join
(
gitlab_shell_path
,
'bin'
,
'gitlab-projects'
)
end
def
gitlab_shell_keys_path
File
.
join
(
gitlab_shell_path
,
'bin'
,
'gitlab-keys'
)
end
def
authorized_keys_enabled?
# Return true if nil to ensure the authorized_keys methods work while
# fixing the authorized_keys file during migration.
...
...
@@ -359,35 +322,6 @@ module Gitlab
private
def
shell_out_for_gitlab_keys?
Gitlab
.
config
.
gitlab_shell
.
authorized_keys_file
.
blank?
end
def
gitlab_shell_fast_execute
(
cmd
)
output
,
status
=
gitlab_shell_fast_execute_helper
(
cmd
)
return
true
if
status
.
zero?
Rails
.
logger
.
error
(
"gitlab-shell failed with error
#{
status
}
:
#{
output
}
"
)
# rubocop:disable Gitlab/RailsLogger
false
end
def
gitlab_shell_fast_execute_raise_error
(
cmd
,
vars
=
{})
output
,
status
=
gitlab_shell_fast_execute_helper
(
cmd
,
vars
)
raise
Error
,
output
unless
status
.
zero?
true
end
def
gitlab_shell_fast_execute_helper
(
cmd
,
vars
=
{})
vars
.
merge!
(
ENV
.
to_h
.
slice
(
*
GITLAB_SHELL_ENV_VARS
))
# Don't pass along the entire parent environment to prevent gitlab-shell
# from wasting I/O by searching through GEM_PATH
Bundler
.
with_original_env
{
Popen
.
popen
(
cmd
,
nil
,
vars
)
}
end
def
git_timeout
Gitlab
.
config
.
gitlab_shell
.
git_timeout
end
...
...
@@ -407,18 +341,10 @@ module Gitlab
def
batch_read_key_ids
(
batch_size:
100
,
&
block
)
return
unless
self
.
authorized_keys_enabled?
if
shell_out_for_gitlab_keys?
IO
.
popen
(
"
#{
gitlab_shell_keys_path
}
list-key-ids"
)
do
|
key_id_stream
|
key_id_stream
.
lazy
.
each_slice
(
batch_size
)
do
|
lines
|
yield
(
lines
.
map
{
|
l
|
l
.
chomp
.
to_i
})
end
end
else
gitlab_authorized_keys
.
list_key_ids
.
lazy
.
each_slice
(
batch_size
)
do
|
key_ids
|
yield
(
key_ids
)
end
end
end
def
strip_key
(
key
)
key
.
split
(
/[ ]+/
)[
0
,
2
].
join
(
' '
)
...
...
spec/lib/gitlab/shell_spec.rb
View file @
c08191e0
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment