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
e67ba9b0
Commit
e67ba9b0
authored
May 28, 2018
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Geo] Fix: Unauthenticated rate limits should not block Geo requests
parent
7f392a9b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
1 deletion
+60
-1
config/initializers/rack_attack_global.rb
config/initializers/rack_attack_global.rb
+7
-1
ee/lib/ee/gitlab/rack/attack/request.rb
ee/lib/ee/gitlab/rack/attack/request.rb
+20
-0
ee/spec/requests/rack_attack_global_spec.rb
ee/spec/requests/rack_attack_global_spec.rb
+33
-0
No files found.
config/initializers/rack_attack_global.rb
View file @
e67ba9b0
...
...
@@ -26,7 +26,7 @@ class Rack::Attack
throttle
(
'throttle_unauthenticated'
,
Gitlab
::
Throttle
.
unauthenticated_options
)
do
|
req
|
Gitlab
::
Throttle
.
settings
.
throttle_unauthenticated_enabled
&&
req
.
unauthenticated?
&&
!
req
.
api_internal_request
?
&&
!
req
.
should_be_skipped
?
&&
req
.
ip
end
...
...
@@ -43,6 +43,8 @@ class Rack::Attack
end
class
Request
prepend
::
EE
::
Gitlab
::
Rack
::
Attack
::
Request
def
unauthenticated?
!
authenticated_user_id
end
...
...
@@ -59,6 +61,10 @@ class Rack::Attack
path
=~
%r{^/api/v
\d
+/internal/}
end
def
should_be_skipped?
api_internal_request?
end
def
web_request?
!
api_request?
end
...
...
ee/lib/ee/gitlab/rack/attack/request.rb
0 → 100644
View file @
e67ba9b0
module
EE
module
Gitlab
module
Rack
module
Attack
module
Request
extend
::
Gitlab
::
Utils
::
Override
override
:should_be_skipped?
def
should_be_skipped?
super
||
geo?
end
def
geo?
::
Gitlab
::
Geo
::
JwtRequestDecoder
.
geo_auth_attempt?
(
env
[
'HTTP_AUTHORIZATION'
])
if
env
[
'HTTP_AUTHORIZATION'
]
end
end
end
end
end
end
ee/spec/requests/rack_attack_global_spec.rb
0 → 100644
View file @
e67ba9b0
require
'spec_helper'
describe
'Rack Attack global throttles'
do
around
do
|
example
|
# Instead of test environment's :null_store so the throttles can increment
Rack
::
Attack
.
cache
.
store
=
ActiveSupport
::
Cache
::
MemoryStore
.
new
# Make time-dependent tests deterministic
Timecop
.
freeze
{
example
.
run
}
Rack
::
Attack
.
cache
.
store
=
Rails
.
cache
end
context
'when the request is from Geo secondary'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:requests_per_period
)
{
1
}
before
do
settings_to_set
=
{
throttle_unauthenticated_requests_per_period:
requests_per_period
,
throttle_unauthenticated_enabled:
true
}
stub_application_setting
(
settings_to_set
)
end
it
'allows requests over the rate limit'
do
(
1
+
requests_per_period
).
times
do
get
"/
#{
project
.
full_path
}
.git/info/refs"
,
{
service:
'git-upload-pack'
},
{
'Authorization'
=>
"
#{
::
Gitlab
::
Geo
::
BaseRequest
::
GITLAB_GEO_AUTH_TOKEN_TYPE
}
token"
}
expect
(
response
).
to
have_http_status
401
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