BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
4b3c1e56
Unverified
Commit
4b3c1e56
authored
Nov 21, 2016
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move LfsHelper to a new LfsRequest concern
Also create a new WorkhorseRequest concern Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
a207c3d1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
91 additions
and
54 deletions
+91
-54
lfs_request.rb
app/controllers/concerns/lfs_request.rb
+50
-26
workhorse_request.rb
app/controllers/concerns/workhorse_request.rb
+13
-0
git_http_client_controller.rb
app/controllers/projects/git_http_client_controller.rb
+8
-8
git_http_controller.rb
app/controllers/projects/git_http_controller.rb
+7
-5
lfs_api_controller.rb
app/controllers/projects/lfs_api_controller.rb
+10
-11
lfs_storage_controller.rb
app/controllers/projects/lfs_storage_controller.rb
+3
-4
No files found.
app/
helpers/lfs_helper
.rb
→
app/
controllers/concerns/lfs_request
.rb
View file @
4b3c1e56
module
LfsHelper
include
Gitlab
::
Routing
.
url_helpers
# This concern assumes:
# - a `#project` accessor
# - a `#user` accessor
# - a `#authentication_result` accessor
# - a `#can?(object, action, subject)` method
# - a `#ci?` method
# - a `#download_request?` method
# - a `#upload_request?` method
# - a `#has_authentication_ability?(ability)` method
module
LfsRequest
extend
ActiveSupport
::
Concern
included
do
before_action
:require_lfs_enabled!
before_action
:lfs_check_access!
end
private
def
require_lfs_enabled!
return
if
Gitlab
.
config
.
lfs
.
enabled
...
...
@@ -17,35 +33,15 @@ module LfsHelper
return
if
download_request?
&&
lfs_download_access?
return
if
upload_request?
&&
lfs_upload_access?
if
project
.
public?
||
(
user
&&
user
.
can?
(
:read_project
,
project
)
)
render_lfs_forbidden
if
project
.
public?
||
can?
(
user
,
:read_project
,
project
)
lfs_forbidden!
else
render_lfs_not_found
end
end
def
lfs_download_access?
return
false
unless
project
.
lfs_enabled?
ci?
||
lfs_deploy_token?
||
user_can_download_code?
||
build_can_download_code?
end
def
objects
@objects
||=
(
params
[
:objects
]
||
[]).
to_a
end
def
user_can_download_code?
has_authentication_ability?
(
:download_code
)
&&
can?
(
user
,
:download_code
,
project
)
end
def
build_can_download_code?
has_authentication_ability?
(
:build_download_code
)
&&
can?
(
user
,
:build_download_code
,
project
)
end
def
lfs_upload_access?
return
false
unless
project
.
lfs_enabled?
has_authentication_ability?
(
:push_code
)
&&
can?
(
user
,
:push_code
,
project
)
def
lfs_forbidden!
render_lfs_forbidden
end
def
render_lfs_forbidden
...
...
@@ -70,6 +66,30 @@ module LfsHelper
)
end
def
lfs_download_access?
return
false
unless
project
.
lfs_enabled?
ci?
||
lfs_deploy_token?
||
user_can_download_code?
||
build_can_download_code?
end
def
lfs_upload_access?
return
false
unless
project
.
lfs_enabled?
has_authentication_ability?
(
:push_code
)
&&
can?
(
user
,
:push_code
,
project
)
end
def
lfs_deploy_token?
authentication_result
.
lfs_deploy_token?
(
project
)
end
def
user_can_download_code?
has_authentication_ability?
(
:download_code
)
&&
can?
(
user
,
:download_code
,
project
)
end
def
build_can_download_code?
has_authentication_ability?
(
:build_download_code
)
&&
can?
(
user
,
:build_download_code
,
project
)
end
def
storage_project
@storage_project
||=
begin
result
=
project
...
...
@@ -82,4 +102,8 @@ module LfsHelper
result
end
end
def
objects
@objects
||=
(
params
[
:objects
]
||
[]).
to_a
end
end
app/controllers/concerns/workhorse_request.rb
0 → 100644
View file @
4b3c1e56
module
WorkhorseRequest
extend
ActiveSupport
::
Concern
included
do
before_action
:verify_workhorse_api!
end
private
def
verify_workhorse_api!
Gitlab
::
Workhorse
.
verify_api_request!
(
request
.
headers
)
end
end
app/controllers/projects/git_http_client_controller.rb
View file @
4b3c1e56
...
...
@@ -18,6 +18,14 @@ class Projects::GitHttpClientController < Projects::ApplicationController
private
def
download_request?
raise
NotImplementedError
end
def
upload_request?
raise
NotImplementedError
end
def
authenticate_user
@authentication_result
=
Gitlab
::
Auth
::
Result
.
new
...
...
@@ -130,10 +138,6 @@ class Projects::GitHttpClientController < Projects::ApplicationController
authentication_result
.
ci?
(
project
)
end
def
lfs_deploy_token?
authentication_result
.
lfs_deploy_token?
(
project
)
end
def
authentication_has_download_access?
has_authentication_ability?
(
:download_code
)
||
has_authentication_ability?
(
:build_download_code
)
end
...
...
@@ -149,8 +153,4 @@ class Projects::GitHttpClientController < Projects::ApplicationController
def
authentication_project
authentication_result
.
project
end
def
verify_workhorse_api!
Gitlab
::
Workhorse
.
verify_api_request!
(
request
.
headers
)
end
end
app/controllers/projects/git_http_controller.rb
View file @
4b3c1e56
# This file should be identical in GitLab Community Edition and Enterprise Edition
class
Projects
::
GitHttpController
<
Projects
::
GitHttpClientController
before_action
:verify_workhorse_api!
include
WorkhorseRequest
# GET /foo/bar.git/info/refs?service=git-upload-pack (git pull)
# GET /foo/bar.git/info/refs?service=git-receive-pack (git push)
...
...
@@ -67,14 +65,18 @@ class Projects::GitHttpController < Projects::GitHttpClientController
end
def
render_denied
if
user
&&
user
.
can?
(
:read_project
,
project
)
render
plain:
'Access denied'
,
status: :forbidden
if
user
&&
can?
(
user
,
:read_project
,
project
)
render
plain:
access_denied_message
,
status: :forbidden
else
# Do not leak information about project existence
render_not_found
end
end
def
access_denied_message
'Access denied'
end
def
upload_pack_allowed?
return
false
unless
Gitlab
.
config
.
gitlab_shell
.
upload_pack
...
...
app/controllers/projects/lfs_api_controller.rb
View file @
4b3c1e56
class
Projects
::
LfsApiController
<
Projects
::
GitHttpClientController
include
Lfs
Helper
include
Lfs
Request
before_action
:require_lfs_enabled!
before_action
:lfs_check_access!
,
except:
[
:deprecated
]
skip_before_action
:lfs_check_access!
,
only:
[
:deprecated
]
def
batch
unless
objects
.
present?
...
...
@@ -31,6 +30,14 @@ class Projects::LfsApiController < Projects::GitHttpClientController
private
def
download_request?
params
[
:operation
]
==
'download'
end
def
upload_request?
params
[
:operation
]
==
'upload'
end
def
existing_oids
@existing_oids
||=
begin
storage_project
.
lfs_objects
.
where
(
oid:
objects
.
map
{
|
o
|
o
[
'oid'
].
to_s
}).
pluck
(
:oid
)
...
...
@@ -79,12 +86,4 @@ class Projects::LfsApiController < Projects::GitHttpClientController
}
}
end
def
download_request?
params
[
:operation
]
==
'download'
end
def
upload_request?
params
[
:operation
]
==
'upload'
end
end
app/controllers/projects/lfs_storage_controller.rb
View file @
4b3c1e56
class
Projects
::
LfsStorageController
<
Projects
::
GitHttpClientController
include
LfsHelper
include
LfsRequest
include
WorkhorseRequest
before_action
:require_lfs_enabled!
before_action
:lfs_check_access!
before_action
:verify_workhorse_api!
,
only:
[
:upload_authorize
]
skip_before_action
:verify_workhorse_api!
,
only:
[
:download
,
:upload_finalize
]
def
download
lfs_object
=
LfsObject
.
find_by_oid
(
oid
)
...
...
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