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
9b561836
Commit
9b561836
authored
Oct 26, 2020
by
allison.browne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix unauthorized access to schedule variables
Security fix for single pipeline schedule api view
parent
5b982e86
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
97 additions
and
23 deletions
+97
-23
app/policies/ci/pipeline_schedule_policy.rb
app/policies/ci/pipeline_schedule_policy.rb
+1
-0
changelogs/unreleased/security-unauthorized-access-schedule-variables-milestone-13-6.yml
...unauthorized-access-schedule-variables-milestone-13-6.yml
+5
-0
lib/api/ci/pipeline_schedules.rb
lib/api/ci/pipeline_schedules.rb
+1
-1
lib/api/entities/ci/pipeline_schedule_details.rb
lib/api/entities/ci/pipeline_schedule_details.rb
+3
-1
spec/policies/project_policy_spec.rb
spec/policies/project_policy_spec.rb
+1
-1
spec/requests/api/ci/pipeline_schedules_spec.rb
spec/requests/api/ci/pipeline_schedules_spec.rb
+86
-20
No files found.
app/policies/ci/pipeline_schedule_policy.rb
View file @
9b561836
...
...
@@ -17,6 +17,7 @@ module Ci
rule
{
can?
(
:admin_pipeline
)
|
(
can?
(
:update_build
)
&
owner_of_schedule
)
}.
policy
do
enable
:update_pipeline_schedule
enable
:admin_pipeline_schedule
enable
:read_pipeline_schedule_variables
end
rule
{
can?
(
:admin_pipeline_schedule
)
&
~
owner_of_schedule
}.
policy
do
...
...
changelogs/unreleased/security-unauthorized-access-schedule-variables-milestone-13-6.yml
0 → 100644
View file @
9b561836
---
title
:
Fix unauthorized user is able to access schedule pipeline variables and values
merge_request
:
author
:
type
:
security
lib/api/ci/pipeline_schedules.rb
View file @
9b561836
...
...
@@ -36,7 +36,7 @@ module API
requires
:pipeline_schedule_id
,
type:
Integer
,
desc:
'The pipeline schedule id'
end
get
':id/pipeline_schedules/:pipeline_schedule_id'
do
present
pipeline_schedule
,
with:
Entities
::
Ci
::
PipelineScheduleDetails
present
pipeline_schedule
,
with:
Entities
::
Ci
::
PipelineScheduleDetails
,
user:
current_user
end
desc
'Create a new pipeline schedule'
do
...
...
lib/api/entities/ci/pipeline_schedule_details.rb
View file @
9b561836
...
...
@@ -5,7 +5,9 @@ module API
module
Ci
class
PipelineScheduleDetails
<
PipelineSchedule
expose
:last_pipeline
,
using:
::
API
::
Entities
::
Ci
::
PipelineBasic
expose
:variables
,
using:
::
API
::
Entities
::
Ci
::
Variable
expose
:variables
,
using:
::
API
::
Entities
::
Ci
::
Variable
,
if:
->
(
schedule
,
options
)
{
Ability
.
allowed?
(
options
[
:user
],
:read_pipeline_schedule_variables
,
schedule
)
}
end
end
end
...
...
spec/policies/project_policy_spec.rb
View file @
9b561836
...
...
@@ -137,7 +137,7 @@ RSpec.describe ProjectPolicy do
it
'disallows all permissions except pipeline when the feature is disabled'
do
builds_permissions
=
[
:create_build
,
:read_build
,
:update_build
,
:admin_build
,
:destroy_build
,
:create_pipeline_schedule
,
:read_pipeline_schedule
,
:update_pipeline_schedule
,
:admin_pipeline_schedule
,
:destroy_pipeline_schedule
,
:create_pipeline_schedule
,
:read_pipeline_schedule
_variables
,
:update_pipeline_schedule
,
:admin_pipeline_schedule
,
:destroy_pipeline_schedule
,
:create_environment
,
:read_environment
,
:update_environment
,
:admin_environment
,
:destroy_environment
,
:create_cluster
,
:read_cluster
,
:update_cluster
,
:admin_cluster
,
:destroy_cluster
,
:create_deployment
,
:read_deployment
,
:update_deployment
,
:admin_deployment
,
:destroy_deployment
...
...
spec/requests/api/ci/pipeline_schedules_spec.rb
View file @
9b561836
...
...
@@ -97,46 +97,112 @@ RSpec.describe API::Ci::PipelineSchedules do
pipeline_schedule
.
pipelines
<<
build
(
:ci_pipeline
,
project:
project
)
end
context
'authenticated user with valid permissions'
do
it
'returns pipeline_schedule details'
do
get
api
(
"/projects/
#{
project
.
id
}
/pipeline_schedules/
#{
pipeline_schedule
.
id
}
"
,
developer
)
matcher
:return_pipeline_schedule_sucessfully
do
match_unless_raises
do
|
reponse
|
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
match_response_schema
(
'pipeline_schedule'
)
end
end
it
'responds with 404 Not Found if requesting non-existing pipeline_schedule'
do
get
api
(
"/projects/
#{
project
.
id
}
/pipeline_schedules/-5"
,
developer
)
shared_context
'request with project permissions'
do
context
'authenticated user with project permisions'
do
before
do
project
.
add_maintainer
(
user
)
end
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
it
'returns pipeline_schedule details'
do
get
api
(
"/projects/
#{
project
.
id
}
/pipeline_schedules/
#{
pipeline_schedule
.
id
}
"
,
user
)
expect
(
response
).
to
return_pipeline_schedule_sucessfully
expect
(
json_response
).
to
have_key
(
'variables'
)
end
end
end
context
'authenticated user with invalid permissions'
do
it
'does not return pipeline_schedules list'
do
get
api
(
"/projects/
#{
project
.
id
}
/pipeline_schedules/
#{
pipeline_schedule
.
id
}
"
,
user
)
shared_examples
'request with schedule ownership'
do
context
'authenticated user with pipeline schedule ownership'
do
it
'returns pipeline_schedule details'
do
get
api
(
"/projects/
#{
project
.
id
}
/pipeline_schedules/
#{
pipeline_schedule
.
id
}
"
,
developer
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
expect
(
response
).
to
return_pipeline_schedule_sucessfully
expect
(
json_response
).
to
have_key
(
'variables'
)
end
end
end
context
'authenticated user with insufficient permissions'
do
before
do
project
.
add_guest
(
user
)
shared_examples
'request with unauthenticated user'
do
context
'with unauthenticated user'
do
it
'does not return pipeline_schedule'
do
get
api
(
"/projects/
#{
project
.
id
}
/pipeline_schedules/
#{
pipeline_schedule
.
id
}
"
)
expect
(
response
).
to
have_gitlab_http_status
(
:unauthorized
)
end
end
end
it
'does not return pipeline_schedules list'
do
get
api
(
"/projects/
#{
project
.
id
}
/pipeline_schedules/
#{
pipeline_schedule
.
id
}
"
,
user
)
shared_examples
'request with non-existing pipeline_schedule'
do
it
'responds with 404 Not Found if requesting non-existing pipeline_schedule'
do
get
api
(
"/projects/
#{
project
.
id
}
/pipeline_schedules/-5"
,
developer
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
context
'unauthenticated user'
do
it
'does not return pipeline_schedules list'
do
get
api
(
"/projects/
#{
project
.
id
}
/pipeline_schedules/
#{
pipeline_schedule
.
id
}
"
)
context
'with private project'
do
it_behaves_like
'request with schedule ownership'
it_behaves_like
'request with project permissions'
it_behaves_like
'request with unauthenticated user'
it_behaves_like
'request with non-existing pipeline_schedule'
expect
(
response
).
to
have_gitlab_http_status
(
:unauthorized
)
context
'authenticated user with no project permissions'
do
it
'does not return pipeline_schedule'
do
get
api
(
"/projects/
#{
project
.
id
}
/pipeline_schedules/
#{
pipeline_schedule
.
id
}
"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
context
'authenticated user with insufficient project permissions'
do
before
do
project
.
add_guest
(
user
)
end
it
'does not return pipeline_schedule'
do
get
api
(
"/projects/
#{
project
.
id
}
/pipeline_schedules/
#{
pipeline_schedule
.
id
}
"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
end
context
'with public project'
do
let_it_be
(
:project
)
{
create
(
:project
,
:repository
,
:public
,
public_builds:
false
)
}
it_behaves_like
'request with schedule ownership'
it_behaves_like
'request with project permissions'
it_behaves_like
'request with unauthenticated user'
it_behaves_like
'request with non-existing pipeline_schedule'
context
'authenticated user with no project permissions'
do
it
'returns pipeline_schedule with no variables'
do
get
api
(
"/projects/
#{
project
.
id
}
/pipeline_schedules/
#{
pipeline_schedule
.
id
}
"
,
user
)
expect
(
response
).
to
return_pipeline_schedule_sucessfully
expect
(
json_response
).
not_to
have_key
(
'variables'
)
end
end
context
'authenticated user with insufficient project permissions'
do
before
do
project
.
add_guest
(
user
)
end
it
'returns pipeline_schedule with no variables'
do
get
api
(
"/projects/
#{
project
.
id
}
/pipeline_schedules/
#{
pipeline_schedule
.
id
}
"
,
user
)
expect
(
response
).
to
return_pipeline_schedule_sucessfully
expect
(
json_response
).
not_to
have_key
(
'variables'
)
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