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
Jérome Perrin
gitlab-ce
Commits
edcba1aa
Commit
edcba1aa
authored
Mar 27, 2018
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow HTTP(s) when git request is made by GitLab CI
parent
b15dd5df
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
4 deletions
+36
-4
app/controllers/projects/git_http_client_controller.rb
app/controllers/projects/git_http_client_controller.rb
+1
-0
app/controllers/projects/git_http_controller.rb
app/controllers/projects/git_http_controller.rb
+1
-1
lib/gitlab/git_access.rb
lib/gitlab/git_access.rb
+11
-2
spec/lib/gitlab/git_access_spec.rb
spec/lib/gitlab/git_access_spec.rb
+23
-1
No files found.
app/controllers/projects/git_http_client_controller.rb
View file @
edcba1aa
...
...
@@ -7,6 +7,7 @@ class Projects::GitHttpClientController < Projects::ApplicationController
attr_reader
:authentication_result
,
:redirected_path
delegate
:actor
,
:authentication_abilities
,
to: :authentication_result
,
allow_nil:
true
delegate
:type
,
to: :authentication_result
,
allow_nil:
true
,
prefix: :auth_result
alias_method
:user
,
:actor
alias_method
:authenticated_user
,
:actor
...
...
app/controllers/projects/git_http_controller.rb
View file @
edcba1aa
...
...
@@ -64,7 +64,7 @@ class Projects::GitHttpController < Projects::GitHttpClientController
@access
||=
access_klass
.
new
(
access_actor
,
project
,
'http'
,
authentication_abilities:
authentication_abilities
,
namespace_path:
params
[
:namespace_id
],
project_path:
project_path
,
redirected_path:
redirected_path
)
redirected_path:
redirected_path
,
auth_result_type:
auth_result_type
)
end
def
access_actor
...
...
lib/gitlab/git_access.rb
View file @
edcba1aa
...
...
@@ -29,9 +29,9 @@ module Gitlab
PUSH_COMMANDS
=
%w{ git-receive-pack }
.
freeze
ALL_COMMANDS
=
DOWNLOAD_COMMANDS
+
PUSH_COMMANDS
attr_reader
:actor
,
:project
,
:protocol
,
:authentication_abilities
,
:namespace_path
,
:project_path
,
:redirected_path
attr_reader
:actor
,
:project
,
:protocol
,
:authentication_abilities
,
:namespace_path
,
:project_path
,
:redirected_path
,
:auth_result_type
def
initialize
(
actor
,
project
,
protocol
,
authentication_abilities
:,
namespace_path:
nil
,
project_path:
nil
,
redirected_path:
nil
)
def
initialize
(
actor
,
project
,
protocol
,
authentication_abilities
:,
namespace_path:
nil
,
project_path:
nil
,
redirected_path:
nil
,
auth_result_type:
nil
)
@actor
=
actor
@project
=
project
@protocol
=
protocol
...
...
@@ -39,6 +39,7 @@ module Gitlab
@namespace_path
=
namespace_path
@project_path
=
project_path
@redirected_path
=
redirected_path
@auth_result_type
=
auth_result_type
end
def
check
(
cmd
,
changes
)
...
...
@@ -78,6 +79,12 @@ module Gitlab
authentication_abilities
.
include?
(
:build_download_code
)
&&
user_access
.
can_do_action?
(
:build_download_code
)
end
def
request_from_ci_build?
return
false
unless
protocol
==
'http'
auth_result_type
==
:build
||
auth_result_type
==
:ci
end
def
protocol_allowed?
Gitlab
::
ProtocolAccess
.
allowed?
(
protocol
)
end
...
...
@@ -93,6 +100,8 @@ module Gitlab
end
def
check_protocol!
return
if
request_from_ci_build?
unless
protocol_allowed?
raise
UnauthorizedError
,
"Git access over
#{
protocol
.
upcase
}
is not allowed"
end
...
...
spec/lib/gitlab/git_access_spec.rb
View file @
edcba1aa
...
...
@@ -10,12 +10,13 @@ describe Gitlab::GitAccess do
let
(
:protocol
)
{
'ssh'
}
let
(
:authentication_abilities
)
{
%i[read_project download_code push_code]
}
let
(
:redirected_path
)
{
nil
}
let
(
:auth_result_type
)
{
nil
}
let
(
:access
)
do
described_class
.
new
(
actor
,
project
,
protocol
,
authentication_abilities:
authentication_abilities
,
namespace_path:
namespace_path
,
project_path:
project_path
,
redirected_path:
redirected_path
)
redirected_path:
redirected_path
,
auth_result_type:
auth_result_type
)
end
let
(
:changes
)
{
'_any'
}
...
...
@@ -45,6 +46,7 @@ describe Gitlab::GitAccess do
before
do
disable_protocol
(
'http'
)
project
.
add_master
(
user
)
end
it
'blocks http push and pull'
do
...
...
@@ -53,6 +55,26 @@ describe Gitlab::GitAccess do
expect
{
pull_access_check
}.
to
raise_unauthorized
(
'Git access over HTTP is not allowed'
)
end
end
context
'when request is made from CI'
do
let
(
:auth_result_type
)
{
:build
}
it
"doesn't block http pull"
do
aggregate_failures
do
expect
{
pull_access_check
}.
not_to
raise_unauthorized
(
'Git access over HTTP is not allowed'
)
end
end
context
'when legacy CI credentials are used'
do
let
(
:auth_result_type
)
{
:ci
}
it
"doesn't block http pull"
do
aggregate_failures
do
expect
{
pull_access_check
}.
not_to
raise_unauthorized
(
'Git access over HTTP is not allowed'
)
end
end
end
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