Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
gitlab-shell
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
Jonathon Reinhart
gitlab-shell
Commits
980eb544
Commit
980eb544
authored
7 years ago
by
Douwe Maan
Browse files
Options
Downloads
Plain Diff
Merge branch '100-require-tempfile' into 'master'
Fix SSH key and known_hosts support Closes #100 See merge request !156
parents
b3ff4c3d
cc62be58
No related branches found
Branches containing commit
Tags
v5.6.1
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGELOG
+4
-0
4 additions, 0 deletions
CHANGELOG
VERSION
+1
-1
1 addition, 1 deletion
VERSION
lib/gitlab_projects.rb
+9
-5
9 additions, 5 deletions
lib/gitlab_projects.rb
spec/gitlab_projects_spec.rb
+11
-8
11 additions, 8 deletions
spec/gitlab_projects_spec.rb
with
25 additions
and
14 deletions
CHANGELOG
+
4
−
0
View file @
980eb544
v 5.6.1
- Fix setting permissions of SSH key tempfiles
- Fix a missing constant error when using SSH authentication
v.5.6.0
- SSH authentication support
...
...
This diff is collapsed.
Click to expand it.
VERSION
+
1
−
1
View file @
980eb544
5.6.
0
5.6.
1
This diff is collapsed.
Click to expand it.
lib/gitlab_projects.rb
+
9
−
5
View file @
980eb544
require
'fileutils'
require
'tempfile'
require
'timeout'
require
'open3'
...
...
@@ -432,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
...
...
This diff is collapsed.
Click to expand it.
spec/gitlab_projects_spec.rb
+
11
−
8
View file @
980eb544
...
...
@@ -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'
,
mod
e
:
0755
)
key
=
stub_tempfile
(
'/tmp files/keyFile'
,
'gitlab-shell-key-file'
,
mod
e
:
0400
)
script
=
stub_tempfile
(
'scriptFile'
,
'gitlab-shell-ssh-wrapper'
,
ch
mod:
0
o
755
)
key
=
stub_tempfile
(
'/tmp files/keyFile'
,
'gitlab-shell-key-file'
,
ch
mod:
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'
,
mod
e
:
0755
)
key
=
stub_tempfile
(
'/tmp files/knownHosts'
,
'gitlab-shell-known-hosts'
,
mod
e
:
0400
)
script
=
stub_tempfile
(
'scriptFile'
,
'gitlab-shell-ssh-wrapper'
,
ch
mod:
0
o
755
)
key
=
stub_tempfile
(
'/tmp files/knownHosts'
,
'gitlab-shell-known-hosts'
,
ch
mod:
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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment