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
038ae1ec
Commit
038ae1ec
authored
Apr 15, 2020
by
Diego Louzán
Committed by
Imre Farkas
Apr 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Protect sidekiq admin UI with admin mode
parent
a661d092
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
100 additions
and
2 deletions
+100
-2
changelogs/unreleased/fix-admin-mode-sidekiq-admin-ui.yml
changelogs/unreleased/fix-admin-mode-sidekiq-admin-ui.yml
+5
-0
config/routes/sidekiq.rb
config/routes/sidekiq.rb
+1
-2
lib/constraints/admin_constrainer.rb
lib/constraints/admin_constrainer.rb
+25
-0
spec/lib/constraints/admin_constrainer_spec.rb
spec/lib/constraints/admin_constrainer_spec.rb
+69
-0
No files found.
changelogs/unreleased/fix-admin-mode-sidekiq-admin-ui.yml
0 → 100644
View file @
038ae1ec
---
title
:
Protect sidekiq admin UI with admin mode
merge_request
:
28164
author
:
Diego Louzán
type
:
fixed
config/routes/sidekiq.rb
View file @
038ae1ec
constraint
=
lambda
{
|
request
|
request
.
env
[
'warden'
].
authenticate?
&&
request
.
env
[
'warden'
].
user
.
admin?
}
constraints
constraint
do
constraints
::
Constraints
::
AdminConstrainer
.
new
do
mount
Sidekiq
::
Web
,
at:
'/admin/sidekiq'
,
as: :sidekiq
end
lib/constraints/admin_constrainer.rb
0 → 100644
View file @
038ae1ec
# frozen_string_literal: true
module
Constraints
class
AdminConstrainer
def
matches?
(
request
)
if
Feature
.
enabled?
(
:user_mode_in_session
)
admin_mode_enabled?
(
request
)
else
user_is_admin?
(
request
)
end
end
private
def
user_is_admin?
(
request
)
request
.
env
[
'warden'
].
authenticate?
&&
request
.
env
[
'warden'
].
user
.
admin?
end
def
admin_mode_enabled?
(
request
)
Gitlab
::
Session
.
with_session
(
request
.
session
)
do
request
.
env
[
'warden'
].
authenticate?
&&
Gitlab
::
Auth
::
CurrentUserMode
.
new
(
request
.
env
[
'warden'
].
user
).
admin_mode?
end
end
end
end
spec/lib/constraints/admin_constrainer_spec.rb
0 → 100644
View file @
038ae1ec
# frozen_string_literal: true
#
require
'spec_helper'
describe
Constraints
::
AdminConstrainer
,
:do_not_mock_admin_mode
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:session
)
{
{}
}
let
(
:env
)
{
{
'warden'
=>
double
(
:warden
,
authenticate?:
true
,
user:
user
)
}
}
let
(
:request
)
{
double
(
:request
,
session:
session
,
env:
env
)
}
around
do
|
example
|
Gitlab
::
Session
.
with_session
(
session
)
do
example
.
run
end
end
describe
'#matches'
do
context
'feature flag :user_mode_in_session is enabled'
do
context
'when user is a regular user'
do
it
'forbids access'
do
expect
(
subject
.
matches?
(
request
)).
to
be
(
false
)
end
end
context
'when user is an admin'
do
let
(
:user
)
{
create
(
:admin
)
}
context
'admin mode is disabled'
do
it
'forbids access'
do
expect
(
subject
.
matches?
(
request
)).
to
be
(
false
)
end
end
context
'admin mode is enabled'
do
before
do
current_user_mode
=
Gitlab
::
Auth
::
CurrentUserMode
.
new
(
user
)
current_user_mode
.
request_admin_mode!
current_user_mode
.
enable_admin_mode!
(
password:
user
.
password
)
end
it
'allows access'
do
expect
(
subject
.
matches?
(
request
)).
to
be
(
true
)
end
end
end
end
context
'feature flag :user_mode_in_session is disabled'
do
before
do
stub_feature_flags
(
user_mode_in_session:
false
)
end
context
'when user is a regular user'
do
it
'forbids access'
do
expect
(
subject
.
matches?
(
request
)).
to
be
(
false
)
end
end
context
'when user is an admin'
do
let
(
:user
)
{
create
(
:admin
)
}
it
'allows access'
do
expect
(
subject
.
matches?
(
request
)).
to
be
(
true
)
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