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
a1ec2ad0
Commit
a1ec2ad0
authored
Aug 29, 2019
by
Patrick Bajao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Auto create authorized_keys file if doesn't exist
Utilize the auto repair functionality of system checks.
parent
b047359d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
70 additions
and
0 deletions
+70
-0
lib/gitlab/authorized_keys.rb
lib/gitlab/authorized_keys.rb
+9
-0
lib/system_check/app/authorized_keys_permission_check.rb
lib/system_check/app/authorized_keys_permission_check.rb
+4
-0
spec/lib/gitlab/authorized_keys_spec.rb
spec/lib/gitlab/authorized_keys_spec.rb
+35
-0
spec/lib/system_check/app/authorized_keys_permission_check_spec.rb
...system_check/app/authorized_keys_permission_check_spec.rb
+22
-0
No files found.
lib/gitlab/authorized_keys.rb
View file @
a1ec2ad0
...
...
@@ -22,6 +22,15 @@ module Gitlab
false
end
# Creates the authorized_keys file if it doesn't exist
#
# @return [Boolean]
def
create
open_authorized_keys_file
(
File
::
CREAT
)
{
true
}
rescue
Errno
::
EACCES
false
end
# Add id and its key to the authorized_keys file
#
# @param [String] id identifier of key prefixed by `key-`
...
...
lib/system_check/app/authorized_keys_permission_check.rb
View file @
a1ec2ad0
...
...
@@ -14,6 +14,10 @@ module SystemCheck
authorized_keys
.
accessible?
end
def
repair!
authorized_keys
.
create
end
def
show_error
try_fixing_it
([
"sudo chmod 700
#{
File
.
dirname
(
authorized_keys
.
file
)
}
"
,
...
...
spec/lib/gitlab/authorized_keys_spec.rb
View file @
a1ec2ad0
...
...
@@ -37,6 +37,41 @@ describe Gitlab::AuthorizedKeys do
end
end
describe
'#create'
do
subject
{
authorized_keys
.
create
}
context
'authorized_keys file exists'
do
before
do
create_authorized_keys_fixture
end
after
do
delete_authorized_keys_file
end
it
{
is_expected
.
to
be_truthy
}
end
context
'authorized_keys file does not exist'
do
after
do
delete_authorized_keys_file
end
it
'creates authorized_keys file'
do
expect
(
subject
).
to
be_truthy
expect
(
File
.
exist?
(
tmp_authorized_keys_path
)).
to
be_truthy
end
end
context
'cannot create file'
do
before
do
allow
(
File
).
to
receive
(
:open
).
and_raise
(
Errno
::
EACCES
)
end
it
{
is_expected
.
to
be_falsey
}
end
end
describe
'#add_key'
do
let
(
:id
)
{
'key-741'
}
...
...
spec/lib/system_check/app/authorized_keys_permission_check_spec.rb
View file @
a1ec2ad0
...
...
@@ -42,4 +42,26 @@ describe SystemCheck::App::AuthorizedKeysPermissionCheck do
it
{
is_expected
.
to
eq
(
false
)
}
end
end
describe
'#repair!'
do
subject
{
system_check
.
repair!
}
before
do
expect_next_instance_of
(
Gitlab
::
AuthorizedKeys
)
do
|
instance
|
allow
(
instance
).
to
receive
(
:create
)
{
created
}
end
end
context
'authorized_keys file created'
do
let
(
:created
)
{
true
}
it
{
is_expected
.
to
eq
(
true
)
}
end
context
'authorized_keys file is not created'
do
let
(
:created
)
{
false
}
it
{
is_expected
.
to
eq
(
false
)
}
end
end
end
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