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
1
Merge Requests
1
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-ce
Commits
f60838ca
Commit
f60838ca
authored
Feb 10, 2022
by
Jonas Wälter
Committed by
Imre Farkas
Feb 10, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Git over HTTP: bypass admin mode
parent
a1033f87
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
4 deletions
+31
-4
app/controllers/repositories/git_http_client_controller.rb
app/controllers/repositories/git_http_client_controller.rb
+9
-0
spec/requests/git_http_spec.rb
spec/requests/git_http_spec.rb
+22
-4
No files found.
app/controllers/repositories/git_http_client_controller.rb
View file @
f60838ca
...
@@ -17,6 +17,9 @@ module Repositories
...
@@ -17,6 +17,9 @@ module Repositories
prepend_before_action
:authenticate_user
,
:parse_repo_path
prepend_before_action
:authenticate_user
,
:parse_repo_path
skip_around_action
:sessionless_bypass_admin_mode!
around_action
:bypass_admin_mode!
,
if: :authenticated_user
feature_category
:source_code_management
feature_category
:source_code_management
def
authenticated_user
def
authenticated_user
...
@@ -136,6 +139,12 @@ module Repositories
...
@@ -136,6 +139,12 @@ module Repositories
container
&&
container
&&
Guest
.
can?
(
repo_type
.
guest_read_ability
,
container
)
Guest
.
can?
(
repo_type
.
guest_read_ability
,
container
)
end
end
def
bypass_admin_mode!
(
&
block
)
return
yield
unless
Gitlab
::
CurrentSettings
.
admin_mode
Gitlab
::
Auth
::
CurrentUserMode
.
bypass_session!
(
authenticated_user
.
id
,
&
block
)
end
end
end
end
end
...
...
spec/requests/git_http_spec.rb
View file @
f60838ca
...
@@ -836,6 +836,24 @@ RSpec.describe 'Git HTTP requests' do
...
@@ -836,6 +836,24 @@ RSpec.describe 'Git HTTP requests' do
end
end
end
end
end
end
context
"when the user is admin"
do
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:env
)
{
{
user:
admin
.
username
,
password:
admin
.
password
}
}
# Currently, the admin mode is bypassed for git operations.
# Once the admin mode is considered for git operations, this test will fail.
# Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/296509
context
'when admin mode is enabled'
,
:enable_admin_mode
do
it_behaves_like
'pulls are allowed'
it_behaves_like
'pushes are allowed'
end
context
'when admin mode is disabled'
do
it_behaves_like
'pulls are allowed'
it_behaves_like
'pushes are allowed'
end
end
end
end
end
end
...
@@ -929,10 +947,10 @@ RSpec.describe 'Git HTTP requests' do
...
@@ -929,10 +947,10 @@ RSpec.describe 'Git HTTP requests' do
context
'when admin mode is disabled'
do
context
'when admin mode is disabled'
do
it_behaves_like
'can download code only'
it_behaves_like
'can download code only'
it
'downloads from other project get status 40
4
'
do
it
'downloads from other project get status 40
3
'
do
clone_get
"
#{
other_project
.
full_path
}
.git"
,
user:
'gitlab-ci-token'
,
password:
build
.
token
clone_get
"
#{
other_project
.
full_path
}
.git"
,
user:
'gitlab-ci-token'
,
password:
build
.
token
expect
(
response
).
to
have_gitlab_http_status
(
:
not_found
)
expect
(
response
).
to
have_gitlab_http_status
(
:
forbidden
)
end
end
end
end
end
end
...
@@ -1534,10 +1552,10 @@ RSpec.describe 'Git HTTP requests' do
...
@@ -1534,10 +1552,10 @@ RSpec.describe 'Git HTTP requests' do
context
'when admin mode is disabled'
do
context
'when admin mode is disabled'
do
it_behaves_like
'can download code only'
it_behaves_like
'can download code only'
it
'downloads from other project get status 40
4
'
do
it
'downloads from other project get status 40
3
'
do
clone_get
"
#{
other_project
.
full_path
}
.git"
,
user:
'gitlab-ci-token'
,
password:
build
.
token
clone_get
"
#{
other_project
.
full_path
}
.git"
,
user:
'gitlab-ci-token'
,
password:
build
.
token
expect
(
response
).
to
have_gitlab_http_status
(
:
not_found
)
expect
(
response
).
to
have_gitlab_http_status
(
:
forbidden
)
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