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
ff343fa0
Commit
ff343fa0
authored
Jul 13, 2017
by
Sean McGivern
Committed by
Mike Greiling
Jul 19, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge branch 'fix/mirror-user' into 'security-9-3-ee'
Fix mirroring and CI exploit See merge request !518
parent
b56c3c6a
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
88 additions
and
18 deletions
+88
-18
app/controllers/concerns/safe_mirror_params.rb
app/controllers/concerns/safe_mirror_params.rb
+19
-0
app/controllers/projects/imports_controller.rb
app/controllers/projects/imports_controller.rb
+8
-1
app/controllers/projects/mirrors_controller.rb
app/controllers/projects/mirrors_controller.rb
+8
-1
app/controllers/projects/settings/repository_controller.rb
app/controllers/projects/settings/repository_controller.rb
+2
-0
app/helpers/mirror_helper.rb
app/helpers/mirror_helper.rb
+4
-0
app/views/projects/mirrors/_show.html.haml
app/views/projects/mirrors/_show.html.haml
+2
-3
app/views/shared/_mirror_trigger_builds_setting.html.haml
app/views/shared/_mirror_trigger_builds_setting.html.haml
+1
-0
changelogs/unreleased-ee/fix-mirror-user.yml
changelogs/unreleased-ee/fix-mirror-user.yml
+4
-0
spec/controllers/projects/imports_controller_spec.rb
spec/controllers/projects/imports_controller_spec.rb
+25
-12
spec/controllers/projects/mirrors_controller_spec.rb
spec/controllers/projects/mirrors_controller_spec.rb
+14
-0
spec/features/projects/settings/ee/push_rules_settings_spec.rb
...features/projects/settings/ee/push_rules_settings_spec.rb
+1
-1
No files found.
app/controllers/concerns/safe_mirror_params.rb
0 → 100644
View file @
ff343fa0
module
SafeMirrorParams
extend
ActiveSupport
::
Concern
included
do
helper_method
:default_mirror_users
end
private
def
valid_mirror_user?
(
mirror_params
)
return
true
unless
mirror_params
[
:mirror_user_id
].
present?
default_mirror_users
.
map
(
&
:id
).
include?
(
mirror_params
[
:mirror_user_id
].
to_i
)
end
def
default_mirror_users
[
current_user
,
@project
.
mirror_user
].
compact
.
uniq
end
end
app/controllers/projects/imports_controller.rb
View file @
ff343fa0
class
Projects::ImportsController
<
Projects
::
ApplicationController
include
ContinueParams
include
SafeMirrorParams
# Authorize
before_action
:authorize_admin_project!
...
...
@@ -11,7 +12,7 @@ class Projects::ImportsController < Projects::ApplicationController
end
def
create
if
@project
.
update_attributes
(
import_params
)
if
@project
.
update_attributes
(
safe_
import_params
)
@project
.
reload
.
import_schedule
end
...
...
@@ -67,4 +68,10 @@ class Projects::ImportsController < Projects::ApplicationController
def
import_params
params
.
require
(
:project
).
permit
(
:import_url
,
:mirror
,
:mirror_user_id
)
end
def
safe_import_params
return
import_params
if
valid_mirror_user?
(
import_params
)
import_params
.
merge
(
mirror_user_id:
current_user
.
id
)
end
end
app/controllers/projects/mirrors_controller.rb
View file @
ff343fa0
class
Projects::MirrorsController
<
Projects
::
ApplicationController
include
RepositorySettingsRedirect
include
SafeMirrorParams
# Authorize
before_action
:authorize_admin_project!
,
except:
[
:update_now
]
before_action
:authorize_push_code!
,
only:
[
:update_now
]
...
...
@@ -12,7 +13,7 @@ class Projects::MirrorsController < Projects::ApplicationController
end
def
update
if
@project
.
update_attributes
(
mirror_params
)
if
@project
.
update_attributes
(
safe_
mirror_params
)
if
@project
.
mirror?
@project
.
force_import_job!
...
...
@@ -51,4 +52,10 @@ class Projects::MirrorsController < Projects::ApplicationController
params
.
require
(
:project
).
permit
(
:mirror
,
:import_url
,
:mirror_user_id
,
:mirror_trigger_builds
,
remote_mirrors_attributes:
[
:url
,
:id
,
:enabled
])
end
def
safe_mirror_params
return
mirror_params
if
valid_mirror_user?
(
mirror_params
)
mirror_params
.
merge
(
mirror_user_id:
current_user
.
id
)
end
end
app/controllers/projects/settings/repository_controller.rb
View file @
ff343fa0
module
Projects
module
Settings
class
RepositoryController
<
Projects
::
ApplicationController
include
SafeMirrorParams
before_action
:authorize_admin_project!
prepend
::
EE
::
Projects
::
Settings
::
RepositoryController
...
...
app/helpers/mirror_helper.rb
View file @
ff343fa0
...
...
@@ -4,4 +4,8 @@ module MirrorHelper
message
<<
"<br>To discard the local changes and overwrite the branch with the upstream version, delete it here and choose 'Update Now' above."
if
can?
(
current_user
,
:push_code
,
@project
)
message
end
def
options_for_mirror_user
options_from_collection_for_select
(
default_mirror_users
,
:id
,
:name
,
@project
.
mirror_user_id
||
current_user
.
id
)
end
end
app/views/projects/mirrors/_show.html.haml
View file @
ff343fa0
...
...
@@ -36,12 +36,11 @@
=
render
"projects/mirrors/instructions"
.form-group
=
f
.
label
:mirror_user_id
,
"Mirror user"
,
class:
"label-light"
=
users_select_tag
(
"project[mirror_user_id]"
,
class:
'input-large'
,
selected:
@project
.
mirror_user_id
||
current_user
.
id
,
first_user:
true
,
current_user:
true
,
push_code_to_protected_branches:
true
)
=
select_tag
(
'project[mirror_user_id]'
,
options_for_mirror_user
,
class:
"select2 lg"
,
required:
true
)
.help-block
This user will be the author of all events in the activity feed that are the result of an update,
like new branches being created or new commits being pushed to existing branches.
They need to have at least master access to this project
.
You can only assign yourself to be the mirror user
.
-
if
@project
.
builds_enabled?
=
render
"shared/mirror_trigger_builds_setting"
,
f:
f
=
f
.
submit
'Save changes'
,
class:
'btn btn-create'
,
name:
'update_remote_mirror'
...
...
app/views/shared/_mirror_trigger_builds_setting.html.haml
View file @
ff343fa0
...
...
@@ -6,3 +6,4 @@
Trigger pipelines when branches or tags are updated from the upstream repository.
Depending on the activity of the upstream repository, this may greatly increase the load on your CI runners.
Only enable this if you know they can handle the load.
<strong>
CI will run using the credentials assigned above.
</strong>
changelogs/unreleased-ee/fix-mirror-user.yml
0 → 100644
View file @
ff343fa0
---
title
:
Prevent mirror user to be assigned to users other than the current one
merge_request
:
author
:
spec/controllers/projects/imports_controller_spec.rb
View file @
ff343fa0
...
...
@@ -2,16 +2,15 @@ require 'spec_helper'
describe
Projects
::
ImportsController
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
before
do
sign_in
(
user
)
project
.
team
<<
[
user
,
:master
]
end
describe
'GET #show'
do
context
'when repository does not exists'
do
let
(
:project
)
{
create
(
:empty_project
)
}
before
do
sign_in
(
user
)
project
.
team
<<
[
user
,
:master
]
end
it
'renders template'
do
get
:show
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
...
...
@@ -28,11 +27,6 @@ describe Projects::ImportsController do
context
'when repository exists'
do
let
(
:project
)
{
create
(
:project_empty_repo
,
import_url:
'https://github.com/vim/vim.git'
)
}
before
do
sign_in
(
user
)
project
.
team
<<
[
user
,
:master
]
end
context
'when import is in progress'
do
before
do
project
.
update_attribute
(
:import_status
,
:started
)
...
...
@@ -125,4 +119,23 @@ describe Projects::ImportsController do
end
end
end
context
'POST #create'
do
context
'mirror user is not the current user'
do
it
'should only assign the current user'
do
allow_any_instance_of
(
EE
::
Project
).
to
receive
(
:add_import_job
)
new_user
=
create
(
:user
)
project
.
add_master
(
new_user
)
post
:create
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
project:
{
mirror:
true
,
mirror_user_id:
new_user
.
id
,
import_url:
'http://local.dev'
},
format: :json
expect
(
project
.
reload
.
mirror
).
to
eq
(
true
)
expect
(
project
.
reload
.
mirror_user
.
id
).
to
eq
(
user
.
id
)
end
end
end
end
spec/controllers/projects/mirrors_controller_spec.rb
View file @
ff343fa0
...
...
@@ -71,6 +71,20 @@ describe Projects::MirrorsController do
expect
(
project
.
reload
.
mirror
).
to
eq
(
true
)
expect
(
project
.
reload
.
import_url
).
to
eq
(
'http://local.dev'
)
end
context
'mirror user is not the current user'
do
it
'should only assign the current user'
do
expect_any_instance_of
(
EE
::
Project
).
to
receive
(
:force_import_job!
)
new_user
=
create
(
:user
)
project
.
add_master
(
new_user
)
do_put
(
project
,
mirror:
true
,
mirror_user_id:
new_user
.
id
,
import_url:
'http://local.dev'
)
expect
(
project
.
reload
.
mirror
).
to
eq
(
true
)
expect
(
project
.
reload
.
mirror_user
.
id
).
to
eq
(
project
.
owner
.
id
)
end
end
end
end
end
...
...
spec/features/projects/settings/ee/push_rules_settings_spec.rb
View file @
ff343fa0
...
...
@@ -60,7 +60,7 @@ describe 'Project settings > [EE] repository', feature: true do
click_button
(
'Save changes'
)
expect
(
find
(
'.select2-chosen'
)).
to
have_content
(
user
2
.
name
)
expect
(
find
(
'.select2-chosen'
)).
to
have_content
(
user
.
name
)
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