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
Léo-Paul Géneau
gitlab-ce
Commits
f2c46672
Commit
f2c46672
authored
Jul 23, 2018
by
Mayra Cabrera
Committed by
Grzegorz Bizon
Jul 23, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve "Deploy Tokens failed to clone LFS repository"
parent
d1f890e9
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
4 deletions
+73
-4
app/controllers/concerns/lfs_request.rb
app/controllers/concerns/lfs_request.rb
+17
-2
app/models/deploy_token.rb
app/models/deploy_token.rb
+5
-1
changelogs/unreleased/46869-deploy-tokens-failed-to-clone-lfs-repository.yml
...ed/46869-deploy-tokens-failed-to-clone-lfs-repository.yml
+5
-0
spec/models/deploy_token_spec.rb
spec/models/deploy_token_spec.rb
+8
-1
spec/requests/lfs_http_spec.rb
spec/requests/lfs_http_spec.rb
+38
-0
No files found.
app/controllers/concerns/lfs_request.rb
View file @
f2c46672
...
@@ -71,7 +71,22 @@ module LfsRequest
...
@@ -71,7 +71,22 @@ module LfsRequest
def
lfs_download_access?
def
lfs_download_access?
return
false
unless
project
.
lfs_enabled?
return
false
unless
project
.
lfs_enabled?
ci?
||
lfs_deploy_token?
||
user_can_download_code?
||
build_can_download_code?
ci?
||
lfs_deploy_token?
||
user_can_download_code?
||
build_can_download_code?
||
deploy_token_can_download_code?
end
def
deploy_token_can_download_code?
deploy_token_present?
&&
deploy_token
.
project
==
project
&&
deploy_token
.
active?
&&
deploy_token
.
read_repository?
end
def
deploy_token_present?
user
&&
user
.
is_a?
(
DeployToken
)
end
def
deploy_token
user
end
end
def
lfs_upload_access?
def
lfs_upload_access?
...
@@ -86,7 +101,7 @@ module LfsRequest
...
@@ -86,7 +101,7 @@ module LfsRequest
end
end
def
user_can_download_code?
def
user_can_download_code?
has_authentication_ability?
(
:download_code
)
&&
can?
(
user
,
:download_code
,
project
)
has_authentication_ability?
(
:download_code
)
&&
can?
(
user
,
:download_code
,
project
)
&&
!
deploy_token_present?
end
end
def
build_can_download_code?
def
build_can_download_code?
...
...
app/models/deploy_token.rb
View file @
f2c46672
...
@@ -27,7 +27,7 @@ class DeployToken < ActiveRecord::Base
...
@@ -27,7 +27,7 @@ class DeployToken < ActiveRecord::Base
end
end
def
active?
def
active?
!
revoked
!
revoked
&&
expires_at
>
Date
.
today
end
end
def
scopes
def
scopes
...
@@ -58,6 +58,10 @@ class DeployToken < ActiveRecord::Base
...
@@ -58,6 +58,10 @@ class DeployToken < ActiveRecord::Base
write_attribute
(
:expires_at
,
value
.
presence
||
Forever
.
date
)
write_attribute
(
:expires_at
,
value
.
presence
||
Forever
.
date
)
end
end
def
admin?
false
end
private
private
def
ensure_at_least_one_scope
def
ensure_at_least_one_scope
...
...
changelogs/unreleased/46869-deploy-tokens-failed-to-clone-lfs-repository.yml
0 → 100644
View file @
f2c46672
---
title
:
Allow cloning LFS repositories through DeployTokens
merge_request
:
20729
author
:
type
:
other
spec/models/deploy_token_spec.rb
View file @
f2c46672
...
@@ -62,11 +62,18 @@ describe DeployToken do
...
@@ -62,11 +62,18 @@ describe DeployToken do
end
end
end
end
context
"when it hasn't been revoked"
do
context
"when it hasn't been revoked
and is not expired
"
do
it
'should return true'
do
it
'should return true'
do
expect
(
deploy_token
.
active?
).
to
be_truthy
expect
(
deploy_token
.
active?
).
to
be_truthy
end
end
end
end
context
"when it hasn't been revoked and is expired"
do
it
'should return true'
do
deploy_token
.
update_attribute
(
:expires_at
,
Date
.
today
-
5
.
days
)
expect
(
deploy_token
.
active?
).
to
be_falsy
end
end
end
end
describe
'#username'
do
describe
'#username'
do
...
...
spec/requests/lfs_http_spec.rb
View file @
f2c46672
...
@@ -575,6 +575,40 @@ describe 'Git LFS API and storage' do
...
@@ -575,6 +575,40 @@ describe 'Git LFS API and storage' do
end
end
end
end
context
'when using Deploy Tokens'
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:authorization
)
{
authorize_deploy_token
}
let
(
:update_user_permissions
)
{
nil
}
let
(
:role
)
{
nil
}
let
(
:update_lfs_permissions
)
do
project
.
lfs_objects
<<
lfs_object
end
context
'when Deploy Token is valid'
do
let
(
:deploy_token
)
{
create
(
:deploy_token
,
projects:
[
project
])
}
it_behaves_like
'an authorized requests'
end
context
'when Deploy Token is not valid'
do
let
(
:deploy_token
)
{
create
(
:deploy_token
,
projects:
[
project
],
read_repository:
false
)
}
it
'responds with access denied'
do
expect
(
response
).
to
have_gitlab_http_status
(
401
)
end
end
context
'when Deploy Token is not related to the project'
do
let
(
:another_project
)
{
create
(
:project
,
:repository
)
}
let
(
:deploy_token
)
{
create
(
:deploy_token
,
projects:
[
another_project
])
}
it
'responds with access forbidden'
do
# We render 404, to prevent data leakage about existence of the project
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
end
end
context
'when build is authorized as'
do
context
'when build is authorized as'
do
let
(
:authorization
)
{
authorize_ci_project
}
let
(
:authorization
)
{
authorize_ci_project
}
...
@@ -1381,6 +1415,10 @@ describe 'Git LFS API and storage' do
...
@@ -1381,6 +1415,10 @@ describe 'Git LFS API and storage' do
ActionController
::
HttpAuthentication
::
Basic
.
encode_credentials
(
user
.
username
,
Gitlab
::
LfsToken
.
new
(
user
).
token
)
ActionController
::
HttpAuthentication
::
Basic
.
encode_credentials
(
user
.
username
,
Gitlab
::
LfsToken
.
new
(
user
).
token
)
end
end
def
authorize_deploy_token
ActionController
::
HttpAuthentication
::
Basic
.
encode_credentials
(
deploy_token
.
username
,
deploy_token
.
token
)
end
def
post_lfs_json
(
url
,
body
=
nil
,
headers
=
nil
)
def
post_lfs_json
(
url
,
body
=
nil
,
headers
=
nil
)
post
(
url
,
body
.
try
(
:to_json
),
(
headers
||
{}).
merge
(
'Content-Type'
=>
LfsRequest
::
CONTENT_TYPE
))
post
(
url
,
body
.
try
(
:to_json
),
(
headers
||
{}).
merge
(
'Content-Type'
=>
LfsRequest
::
CONTENT_TYPE
))
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