Merge branch '56309-read-only-controller-doesn-t-account-for-relative-paths-for-admin-sidekiq-route' into 'master'
Allow sidekiq admin requests, regardless of root Closes #56309 See merge request gitlab-org/gitlab-ce!24352
This commit is contained in:
commit
dbe11b9ca5
|
@ -71,12 +71,16 @@ module Gitlab
|
||||||
@route_hash ||= Rails.application.routes.recognize_path(request.url, { method: request.request_method }) rescue {}
|
@route_hash ||= Rails.application.routes.recognize_path(request.url, { method: request.request_method }) rescue {}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Overridden in EE module
|
def relative_url
|
||||||
def whitelisted_routes
|
File.join('', Gitlab.config.gitlab.relative_url_root).chomp('/')
|
||||||
grack_route || ReadOnly.internal_routes.any? { |path| request.path.include?(path) } || lfs_route || sidekiq_route
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def grack_route
|
# Overridden in EE module
|
||||||
|
def whitelisted_routes
|
||||||
|
grack_route? || internal_route? || lfs_route? || sidekiq_route?
|
||||||
|
end
|
||||||
|
|
||||||
|
def grack_route?
|
||||||
# Calling route_hash may be expensive. Only do it if we think there's a possible match
|
# Calling route_hash may be expensive. Only do it if we think there's a possible match
|
||||||
return false unless
|
return false unless
|
||||||
request.path.end_with?('.git/git-upload-pack', '.git/git-receive-pack')
|
request.path.end_with?('.git/git-upload-pack', '.git/git-receive-pack')
|
||||||
|
@ -84,7 +88,11 @@ module Gitlab
|
||||||
WHITELISTED_GIT_ROUTES[route_hash[:controller]]&.include?(route_hash[:action])
|
WHITELISTED_GIT_ROUTES[route_hash[:controller]]&.include?(route_hash[:action])
|
||||||
end
|
end
|
||||||
|
|
||||||
def lfs_route
|
def internal_route?
|
||||||
|
ReadOnly.internal_routes.any? { |path| request.path.include?(path) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def lfs_route?
|
||||||
# Calling route_hash may be expensive. Only do it if we think there's a possible match
|
# Calling route_hash may be expensive. Only do it if we think there's a possible match
|
||||||
unless request.path.end_with?('/info/lfs/objects/batch',
|
unless request.path.end_with?('/info/lfs/objects/batch',
|
||||||
'/info/lfs/locks', '/info/lfs/locks/verify') ||
|
'/info/lfs/locks', '/info/lfs/locks/verify') ||
|
||||||
|
@ -95,8 +103,8 @@ module Gitlab
|
||||||
WHITELISTED_GIT_LFS_ROUTES[route_hash[:controller]]&.include?(route_hash[:action])
|
WHITELISTED_GIT_LFS_ROUTES[route_hash[:controller]]&.include?(route_hash[:action])
|
||||||
end
|
end
|
||||||
|
|
||||||
def sidekiq_route
|
def sidekiq_route?
|
||||||
request.path.start_with?('/admin/sidekiq')
|
request.path.start_with?("#{relative_url}/admin/sidekiq")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -101,16 +101,36 @@ describe Gitlab::Middleware::ReadOnly do
|
||||||
expect(subject).not_to disallow_request
|
expect(subject).not_to disallow_request
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'expects requests to sidekiq admin to be allowed' do
|
context 'sidekiq admin requests' do
|
||||||
response = request.post('/admin/sidekiq')
|
where(:mounted_at) do
|
||||||
|
[
|
||||||
|
'',
|
||||||
|
'/',
|
||||||
|
'/gitlab',
|
||||||
|
'/gitlab/',
|
||||||
|
'/gitlab/gitlab',
|
||||||
|
'/gitlab/gitlab/'
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
expect(response).not_to be_redirect
|
with_them do
|
||||||
expect(subject).not_to disallow_request
|
before do
|
||||||
|
stub_config_setting(relative_url_root: mounted_at)
|
||||||
|
end
|
||||||
|
|
||||||
response = request.get('/admin/sidekiq')
|
it 'allows requests' do
|
||||||
|
path = File.join(mounted_at, 'admin/sidekiq')
|
||||||
|
response = request.post(path)
|
||||||
|
|
||||||
expect(response).not_to be_redirect
|
expect(response).not_to be_redirect
|
||||||
expect(subject).not_to disallow_request
|
expect(subject).not_to disallow_request
|
||||||
|
|
||||||
|
response = request.get(path)
|
||||||
|
|
||||||
|
expect(response).not_to be_redirect
|
||||||
|
expect(subject).not_to disallow_request
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
where(:description, :path) do
|
where(:description, :path) do
|
||||||
|
|
Loading…
Reference in New Issue