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
f9b7ce50
Commit
f9b7ce50
authored
Jan 30, 2021
by
Diego Louzán
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Auto-enable admin mode on privileged environments
parent
31dddbc1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
1 deletion
+43
-1
changelogs/unreleased/feat-auto-enable-admin-mode-rake-runtime.yml
...s/unreleased/feat-auto-enable-admin-mode-rake-runtime.yml
+5
-0
lib/gitlab/auth/current_user_mode.rb
lib/gitlab/auth/current_user_mode.rb
+6
-1
spec/tasks/admin_mode_spec.rb
spec/tasks/admin_mode_spec.rb
+32
-0
No files found.
changelogs/unreleased/feat-auto-enable-admin-mode-rake-runtime.yml
0 → 100644
View file @
f9b7ce50
---
title
:
Auto-enable admin mode on privileged environments
merge_request
:
53015
author
:
Diego Louzán
type
:
changed
lib/gitlab/auth/current_user_mode.rb
View file @
f9b7ce50
...
...
@@ -77,7 +77,7 @@ module Gitlab
return
false
unless
user
Gitlab
::
SafeRequestStore
.
fetch
(
admin_mode_rs_key
)
do
user
.
admin?
&&
session_with_admin_mode?
user
.
admin?
&&
(
privileged_runtime?
||
session_with_admin_mode?
)
end
end
...
...
@@ -154,6 +154,11 @@ module Gitlab
Gitlab
::
SafeRequestStore
.
delete
(
admin_mode_rs_key
)
Gitlab
::
SafeRequestStore
.
delete
(
admin_mode_requested_rs_key
)
end
# Runtimes which imply shell access get admin mode automatically, see Gitlab::Runtime
def
privileged_runtime?
Gitlab
::
Runtime
.
rake?
||
Gitlab
::
Runtime
.
rails_runner?
||
Gitlab
::
Runtime
.
console?
end
end
end
end
spec/tasks/admin_mode_spec.rb
0 → 100644
View file @
f9b7ce50
# frozen_string_literal: true
require
'rake_helper'
RSpec
.
describe
'admin mode on tasks'
do
before
do
allow
(
::
Gitlab
::
Runtime
).
to
receive
(
:test_suite?
).
and_return
(
false
)
allow
(
::
Gitlab
::
Runtime
).
to
receive
(
:rake?
).
and_return
(
true
)
end
shared_examples
'verify admin mode'
do
|
state
|
it
'matches the expected admin mode'
do
Rake
::
Task
.
define_task
:verify_admin_mode
do
expect
(
Gitlab
::
Auth
::
CurrentUserMode
.
new
(
user
).
admin_mode?
).
to
be
(
state
)
end
run_rake_task
(
'verify_admin_mode'
)
end
end
describe
'with a regular user'
do
let
(
:user
)
{
create
(
:user
)
}
include_examples
'verify admin mode'
,
false
end
describe
'with an admin'
do
let
(
:user
)
{
create
(
:admin
)
}
include_examples
'verify admin mode'
,
true
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