Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-shell
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
nexedi
gitlab-shell
Commits
a2258baf
Commit
a2258baf
authored
Aug 02, 2017
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix setting permissions of SSH key tempfiles
parent
09607d45
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
13 deletions
+19
-13
lib/gitlab_projects.rb
lib/gitlab_projects.rb
+8
-5
spec/gitlab_projects_spec.rb
spec/gitlab_projects_spec.rb
+11
-8
No files found.
lib/gitlab_projects.rb
View file @
a2258baf
...
...
@@ -433,26 +433,29 @@ class GitlabProjects
options
=
{}
if
ENV
.
key?
(
'GITLAB_SHELL_SSH_KEY'
)
key_file
=
Tempfile
.
new
(
'gitlab-shell-key-file'
,
mode:
0
o400
)
key_file
=
Tempfile
.
new
(
'gitlab-shell-key-file'
)
key_file
.
chmod
(
0
o400
)
key_file
.
write
(
ENV
[
'GITLAB_SHELL_SSH_KEY'
])
key_file
.
close
options
[
'IdentityFile'
]
=
key_file
.
path
options
[
'IdentitiesOnly'
]
=
true
options
[
'IdentitiesOnly'
]
=
'yes'
end
if
ENV
.
key?
(
'GITLAB_SHELL_KNOWN_HOSTS'
)
known_hosts_file
=
Tempfile
.
new
(
'gitlab-shell-known-hosts'
,
mode:
0
o400
)
known_hosts_file
=
Tempfile
.
new
(
'gitlab-shell-known-hosts'
)
known_hosts_file
.
chmod
(
0
o400
)
known_hosts_file
.
write
(
ENV
[
'GITLAB_SHELL_KNOWN_HOSTS'
])
known_hosts_file
.
close
options
[
'StrictHostKeyChecking'
]
=
true
options
[
'StrictHostKeyChecking'
]
=
'yes'
options
[
'UserKnownHostsFile'
]
=
known_hosts_file
.
path
end
return
yield
({})
if
options
.
empty?
script
=
Tempfile
.
new
(
'gitlab-shell-ssh-wrapper'
,
mode:
0
o755
)
script
=
Tempfile
.
new
(
'gitlab-shell-ssh-wrapper'
)
script
.
chmod
(
0
o755
)
script
.
write
(
custom_ssh_script
(
options
))
script
.
close
...
...
spec/gitlab_projects_spec.rb
View file @
a2258baf
...
...
@@ -336,12 +336,15 @@ describe GitlabProjects do
ENV
.
replace
(
original
)
end
def
stub_tempfile
(
name
,
*
args
)
def
stub_tempfile
(
name
,
filename
,
opts
=
{})
chmod
=
opts
.
delete
(
:chmod
)
file
=
StringIO
.
new
allow
(
file
).
to
receive
(
:close!
)
allow
(
file
).
to
receive
(
:path
).
and_return
(
name
)
expect
(
Tempfile
).
to
receive
(
:new
).
with
(
*
args
).
and_return
(
file
)
expect
(
Tempfile
).
to
receive
(
:new
).
with
(
filename
).
and_return
(
file
)
expect
(
file
).
to
receive
(
:chmod
).
with
(
chmod
)
if
chmod
file
end
...
...
@@ -397,14 +400,14 @@ describe GitlabProjects do
end
it
'sets GIT_SSH to a custom script'
do
script
=
stub_tempfile
(
'scriptFile'
,
'gitlab-shell-ssh-wrapper'
,
mode:
0
755
)
key
=
stub_tempfile
(
'/tmp files/keyFile'
,
'gitlab-shell-key-file'
,
mode:
0
400
)
script
=
stub_tempfile
(
'scriptFile'
,
'gitlab-shell-ssh-wrapper'
,
chmod:
0
o
755
)
key
=
stub_tempfile
(
'/tmp files/keyFile'
,
'gitlab-shell-key-file'
,
chmod:
0
o
400
)
stub_spawn
({
'GIT_SSH'
=>
'scriptFile'
},
*
cmd
)
expect
(
gl_projects
.
exec
).
to
be
true
expect
(
script
.
string
).
to
eq
(
"#!/bin/sh
\n
exec ssh '-oIdentityFile=
\"
/tmp files/keyFile
\"
' '-oIdentitiesOnly=
\"
true
\"
'
\"
$@
\"
"
)
expect
(
script
.
string
).
to
eq
(
"#!/bin/sh
\n
exec ssh '-oIdentityFile=
\"
/tmp files/keyFile
\"
' '-oIdentitiesOnly=
\"
yes
\"
'
\"
$@
\"
"
)
expect
(
key
.
string
).
to
eq
(
'SSH KEY'
)
end
end
...
...
@@ -418,14 +421,14 @@ describe GitlabProjects do
end
it
'sets GIT_SSH to a custom script'
do
script
=
stub_tempfile
(
'scriptFile'
,
'gitlab-shell-ssh-wrapper'
,
mode:
0
755
)
key
=
stub_tempfile
(
'/tmp files/knownHosts'
,
'gitlab-shell-known-hosts'
,
mode:
0
400
)
script
=
stub_tempfile
(
'scriptFile'
,
'gitlab-shell-ssh-wrapper'
,
chmod:
0
o
755
)
key
=
stub_tempfile
(
'/tmp files/knownHosts'
,
'gitlab-shell-known-hosts'
,
chmod:
0
o
400
)
stub_spawn
({
'GIT_SSH'
=>
'scriptFile'
},
*
cmd
)
expect
(
gl_projects
.
exec
).
to
be
true
expect
(
script
.
string
).
to
eq
(
"#!/bin/sh
\n
exec ssh '-oStrictHostKeyChecking=
\"
true
\"
' '-oUserKnownHostsFile=
\"
/tmp files/knownHosts
\"
'
\"
$@
\"
"
)
expect
(
script
.
string
).
to
eq
(
"#!/bin/sh
\n
exec ssh '-oStrictHostKeyChecking=
\"
yes
\"
' '-oUserKnownHostsFile=
\"
/tmp files/knownHosts
\"
'
\"
$@
\"
"
)
expect
(
key
.
string
).
to
eq
(
'KNOWN HOSTS'
)
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