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
0
Merge Requests
0
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
iv
gitlab-ce
Commits
20b9bb20
Commit
20b9bb20
authored
Jun 24, 2016
by
Alejandro Rodríguez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create (if necessary) and link the gitlab-shell secret file on the rake install task
parent
86359ec8
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
19 deletions
+43
-19
config/initializers/gitlab_shell_secret_token.rb
config/initializers/gitlab_shell_secret_token.rb
+1
-19
lib/gitlab/backend/shell.rb
lib/gitlab/backend/shell.rb
+17
-0
lib/tasks/gitlab/shell.rake
lib/tasks/gitlab/shell.rake
+2
-0
spec/lib/gitlab/backend/shell_spec.rb
spec/lib/gitlab/backend/shell_spec.rb
+23
-0
No files found.
config/initializers/gitlab_shell_secret_token.rb
View file @
20b9bb20
# Be sure to restart your server when you modify this file.
require
'securerandom'
# Your secret key for verifying the gitlab_shell.
secret_file
=
Gitlab
.
config
.
gitlab_shell
.
secret_file
unless
File
.
exist?
secret_file
# Generate a new token of 16 random hexadecimal characters and store it in secret_file.
token
=
SecureRandom
.
hex
(
16
)
File
.
write
(
secret_file
,
token
)
end
link_path
=
File
.
join
(
Gitlab
.
config
.
gitlab_shell
.
path
,
'.gitlab_shell_secret'
)
if
File
.
exist?
(
Gitlab
.
config
.
gitlab_shell
.
path
)
&&
!
File
.
exist?
(
link_path
)
FileUtils
.
symlink
(
secret_file
,
link_path
)
end
Gitlab
::
Shell
.
new
.
generate_and_link_secret_token
lib/gitlab/backend/shell.rb
View file @
20b9bb20
require
'securerandom'
module
Gitlab
class
Shell
class
Error
<
StandardError
;
end
...
...
@@ -188,6 +190,21 @@ module Gitlab
File
.
exist?
(
full_path
(
storage
,
dir_name
))
end
# Create (if necessary) and link the secret token file
def
generate_and_link_secret_token
secret_file
=
Gitlab
.
config
.
gitlab_shell
.
secret_file
unless
File
.
exist?
secret_file
# Generate a new token of 16 random hexadecimal characters and store it in secret_file.
token
=
SecureRandom
.
hex
(
16
)
File
.
write
(
secret_file
,
token
)
end
link_path
=
File
.
join
(
gitlab_shell_path
,
'.gitlab_shell_secret'
)
if
File
.
exist?
(
gitlab_shell_path
)
&&
!
File
.
exist?
(
link_path
)
FileUtils
.
symlink
(
secret_file
,
link_path
)
end
end
protected
def
gitlab_shell_path
...
...
lib/tasks/gitlab/shell.rake
View file @
20b9bb20
...
...
@@ -71,6 +71,8 @@ namespace :gitlab do
File
.
open
(
File
.
join
(
home_dir
,
".ssh"
,
"environment"
),
"w+"
)
do
|
f
|
f
.
puts
"PATH=
#{
ENV
[
'PATH'
]
}
"
end
Gitlab
::
Shell
.
new
.
generate_and_link_secret_token
end
desc
"GitLab | Setup gitlab-shell"
...
...
spec/lib/gitlab/backend/shell_spec.rb
View file @
20b9bb20
...
...
@@ -21,6 +21,29 @@ describe Gitlab::Shell, lib: true do
it
{
expect
(
gitlab_shell
.
url_to_repo
(
'diaspora'
)).
to
eq
(
Gitlab
.
config
.
gitlab_shell
.
ssh_path_prefix
+
"diaspora.git"
)
}
describe
'generate_and_link_secret_token'
do
let
(
:secret_file
)
{
'tmp/tests/.secret_shell_test'
}
let
(
:link_file
)
{
'tmp/tests/shell-secret-test/.gitlab_shell_secret'
}
before
do
allow
(
Gitlab
.
config
.
gitlab_shell
).
to
receive
(
:path
).
and_return
(
'tmp/tests/shell-secret-test'
)
allow
(
Gitlab
.
config
.
gitlab_shell
).
to
receive
(
:secret_file
).
and_return
(
secret_file
)
FileUtils
.
mkdir
(
'tmp/tests/shell-secret-test'
)
gitlab_shell
.
generate_and_link_secret_token
end
after
do
FileUtils
.
rm_rf
(
'tmp/tests/shell-secret-test'
)
FileUtils
.
rm_rf
(
secret_file
)
end
it
'creates and links the secret token file'
do
expect
(
File
.
exist?
(
secret_file
)).
to
be
(
true
)
expect
(
File
.
symlink?
(
link_file
)).
to
be
(
true
)
expect
(
File
.
readlink
(
link_file
)).
to
eq
(
secret_file
)
end
end
describe
Gitlab
::
Shell
::
KeyAdder
,
lib:
true
do
describe
'#add_key'
do
it
'normalizes space characters in the key'
do
...
...
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