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
cac9ac45
Commit
cac9ac45
authored
Jan 11, 2021
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Forbid snippet pushes when repo is read-only
parent
d4477f11
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
19 deletions
+37
-19
changelogs/unreleased/fj-forbid-push-when-snippet-read-only.yml
...logs/unreleased/fj-forbid-push-when-snippet-read-only.yml
+5
-0
lib/gitlab/git_access_snippet.rb
lib/gitlab/git_access_snippet.rb
+9
-5
spec/lib/gitlab/git_access_snippet_spec.rb
spec/lib/gitlab/git_access_snippet_spec.rb
+23
-14
No files found.
changelogs/unreleased/fj-forbid-push-when-snippet-read-only.yml
0 → 100644
View file @
cac9ac45
---
title
:
Forbid snippet pushes when repo is read-only
merge_request
:
51318
author
:
type
:
fixed
lib/gitlab/git_access_snippet.rb
View file @
cac9ac45
...
@@ -59,7 +59,7 @@ module Gitlab
...
@@ -59,7 +59,7 @@ module Gitlab
# TODO: Investigate if expanding actor/authentication types are needed.
# TODO: Investigate if expanding actor/authentication types are needed.
# https://gitlab.com/gitlab-org/gitlab/issues/202190
# https://gitlab.com/gitlab-org/gitlab/issues/202190
if
actor
&&
!
allowed_actor?
if
actor
&&
!
allowed_actor?
raise
ForbiddenError
,
ERROR_MESSAGES
[
:authentication_mechanism
]
raise
ForbiddenError
,
error_message
(
:authentication_mechanism
)
end
end
super
super
...
@@ -71,14 +71,18 @@ module Gitlab
...
@@ -71,14 +71,18 @@ module Gitlab
override
:check_push_access!
override
:check_push_access!
def
check_push_access!
def
check_push_access!
raise
ForbiddenError
,
ERROR_MESSAGES
[
:update_snippet
]
unless
user
raise
ForbiddenError
,
error_message
(
:update_snippet
)
unless
user
if
snippet
&
.
repository_read_only?
raise
ForbiddenError
,
error_message
(
:read_only
)
end
check_change_access!
check_change_access!
end
end
def
check_snippet_accessibility!
def
check_snippet_accessibility!
if
snippet
.
blank?
if
snippet
.
blank?
raise
NotFoundError
,
ERROR_MESSAGES
[
:snippet_not_found
]
raise
NotFoundError
,
error_message
(
:snippet_not_found
)
end
end
end
end
...
@@ -94,14 +98,14 @@ module Gitlab
...
@@ -94,14 +98,14 @@ module Gitlab
passed
=
guest_can_download_code?
||
user_can_download_code?
passed
=
guest_can_download_code?
||
user_can_download_code?
unless
passed
unless
passed
raise
ForbiddenError
,
ERROR_MESSAGES
[
:read_snippet
]
raise
ForbiddenError
,
error_message
(
:read_snippet
)
end
end
end
end
override
:check_change_access!
override
:check_change_access!
def
check_change_access!
def
check_change_access!
unless
user_can_push?
unless
user_can_push?
raise
ForbiddenError
,
ERROR_MESSAGES
[
:update_snippet
]
raise
ForbiddenError
,
error_message
(
:update_snippet
)
end
end
check_size_before_push!
check_size_before_push!
...
...
spec/lib/gitlab/git_access_snippet_spec.rb
View file @
cac9ac45
...
@@ -29,8 +29,17 @@ RSpec.describe Gitlab::GitAccessSnippet do
...
@@ -29,8 +29,17 @@ RSpec.describe Gitlab::GitAccessSnippet do
let
(
:actor
)
{
build
(
:deploy_key
)
}
let
(
:actor
)
{
build
(
:deploy_key
)
}
it
'does not allow push and pull access'
do
it
'does not allow push and pull access'
do
expect
{
push_access_check
}.
to
raise_forbidden
(
described_class
::
ERROR_MESSAGES
[
:authentication_mechanism
])
expect
{
push_access_check
}.
to
raise_forbidden
(
:authentication_mechanism
)
expect
{
pull_access_check
}.
to
raise_forbidden
(
described_class
::
ERROR_MESSAGES
[
:authentication_mechanism
])
expect
{
pull_access_check
}.
to
raise_forbidden
(
:authentication_mechanism
)
end
end
describe
'when snippet repository is read-only'
do
it
'does not allow push and allows pull access'
do
allow
(
snippet
).
to
receive
(
:repository_read_only?
).
and_return
(
true
)
expect
{
push_access_check
}.
to
raise_forbidden
(
:read_only
)
expect
{
pull_access_check
}.
not_to
raise_error
end
end
end
end
...
@@ -58,7 +67,7 @@ RSpec.describe Gitlab::GitAccessSnippet do
...
@@ -58,7 +67,7 @@ RSpec.describe Gitlab::GitAccessSnippet do
let
(
:snippet
)
{
nil
}
let
(
:snippet
)
{
nil
}
it
'blocks access with "not found"'
do
it
'blocks access with "not found"'
do
expect
{
pull_access_check
}.
to
raise_
snippet_not_found
expect
{
pull_access_check
}.
to
raise_
not_found
(
:snippet_not_found
)
end
end
end
end
...
@@ -66,7 +75,7 @@ RSpec.describe Gitlab::GitAccessSnippet do
...
@@ -66,7 +75,7 @@ RSpec.describe Gitlab::GitAccessSnippet do
let
(
:snippet
)
{
build_stubbed
(
:personal_snippet
)
}
let
(
:snippet
)
{
build_stubbed
(
:personal_snippet
)
}
it
'blocks access with "not found"'
do
it
'blocks access with "not found"'
do
expect
{
pull_access_check
}.
to
raise_
snippet_not_found
expect
{
pull_access_check
}.
to
raise_
not_found
(
:no_repo
)
end
end
end
end
end
end
...
@@ -81,8 +90,8 @@ RSpec.describe Gitlab::GitAccessSnippet do
...
@@ -81,8 +90,8 @@ RSpec.describe Gitlab::GitAccessSnippet do
it
'blocks access when the user did not accept terms'
do
it
'blocks access when the user did not accept terms'
do
message
=
/must accept the Terms of Service in order to perform this action/
message
=
/must accept the Terms of Service in order to perform this action/
expect
{
push_access_check
}.
to
raise_forbidden
(
message
)
expect
{
push_access_check
}.
to
raise_forbidden
_with_message
(
message
)
expect
{
pull_access_check
}.
to
raise_forbidden
(
message
)
expect
{
pull_access_check
}.
to
raise_forbidden
_with_message
(
message
)
end
end
it
'allows access when the user accepted the terms'
do
it
'allows access when the user accepted the terms'
do
...
@@ -149,8 +158,8 @@ RSpec.describe Gitlab::GitAccessSnippet do
...
@@ -149,8 +158,8 @@ RSpec.describe Gitlab::GitAccessSnippet do
let
(
:membership
)
{
membership
}
let
(
:membership
)
{
membership
}
it
'respects accessibility'
do
it
'respects accessibility'
do
expect
{
push_access_check
}.
to
raise_
snippet_not_found
expect
{
push_access_check
}.
to
raise_
not_found
(
:project_not_found
)
expect
{
pull_access_check
}.
to
raise_
snippet_not_found
expect
{
pull_access_check
}.
to
raise_
not_found
(
:project_not_found
)
end
end
end
end
end
end
...
@@ -273,7 +282,7 @@ RSpec.describe Gitlab::GitAccessSnippet do
...
@@ -273,7 +282,7 @@ RSpec.describe Gitlab::GitAccessSnippet do
allow
(
check
).
to
receive
(
:validate!
).
and_raise
(
Gitlab
::
GitAccess
::
ForbiddenError
,
'foo'
)
allow
(
check
).
to
receive
(
:validate!
).
and_raise
(
Gitlab
::
GitAccess
::
ForbiddenError
,
'foo'
)
end
end
expect
{
push_access_check
}.
to
raise_forbidden
(
'foo'
)
expect
{
push_access_check
}.
to
raise_forbidden
_with_message
(
'foo'
)
end
end
it
'sets the file count limit from Snippet class'
do
it
'sets the file count limit from Snippet class'
do
...
@@ -424,15 +433,15 @@ RSpec.describe Gitlab::GitAccessSnippet do
...
@@ -424,15 +433,15 @@ RSpec.describe Gitlab::GitAccessSnippet do
private
private
def
raise_
snippet_not_found
def
raise_
not_found
(
message_key
)
raise_error
(
Gitlab
::
GitAccess
::
NotFoundError
,
Gitlab
::
GitAccess
::
ERROR_MESSAGES
[
:snippet_not_found
]
)
raise_error
(
described_class
::
NotFoundError
,
described_class
.
error_message
(
message_key
)
)
end
end
def
raise_
project_not_found
def
raise_
forbidden
(
message_key
)
raise_error
(
Gitlab
::
GitAccess
::
NotFoundError
,
Gitlab
::
GitAccess
::
ERROR_MESSAGES
[
:project_not_found
]
)
raise_error
(
Gitlab
::
GitAccess
::
ForbiddenError
,
described_class
.
error_message
(
message_key
)
)
end
end
def
raise_forbidden
(
message
)
def
raise_forbidden
_with_message
(
message
)
raise_error
(
Gitlab
::
GitAccess
::
ForbiddenError
,
message
)
raise_error
(
Gitlab
::
GitAccess
::
ForbiddenError
,
message
)
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