Commit c5b79e96 authored by Avielle Wolfe's avatar Avielle Wolfe Committed by GitLab Release Tools Bot

Restrict CI lint access to pipeline creators

Merge branch 'security-aw-355738-restrict-ci-config-access-14-10' into '14-10-stable-ee'

See merge request gitlab-org/security/gitlab!2515

Changelog: security
parent 43645436
...@@ -12,7 +12,7 @@ module Resolvers ...@@ -12,7 +12,7 @@ module Resolvers
Should not be requested more than once per request. Should not be requested more than once per request.
MD MD
authorize :read_pipeline authorize :create_pipeline
argument :project_path, GraphQL::Types::ID, argument :project_path, GraphQL::Types::ID,
required: true, required: true,
......
...@@ -407,6 +407,9 @@ and [Helm Chart deployments](https://docs.gitlab.com/charts/). They come with ap ...@@ -407,6 +407,9 @@ and [Helm Chart deployments](https://docs.gitlab.com/charts/). They come with ap
- The upgrade to GitLab 14.10 executes a [concurrent index drop](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/84308) of unneeded - The upgrade to GitLab 14.10 executes a [concurrent index drop](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/84308) of unneeded
entries from the `ci_job_artifacts` database table. This could potentially run for multiple minutes, especially if the table has a lot of entries from the `ci_job_artifacts` database table. This could potentially run for multiple minutes, especially if the table has a lot of
traffic and the migration is unable to acquire a lock. It is advised to let this process finish as restarting may result in data loss. traffic and the migration is unable to acquire a lock. It is advised to let this process finish as restarting may result in data loss.
- Unauthenticated requests to the [`ciConfig` GraphQL field](../api/graphql/reference/index.md#queryciconfig) are no longer supported.
Before you upgrade to GitLab 15.1, add an [access token](../api/index.md#authentication) to your requests.
The user creating the token must have [permission](../user/permissions.md) to create pipelines in the project.
### 14.9.0 ### 14.9.0
......
...@@ -7,24 +7,13 @@ RSpec.describe Resolvers::Ci::ConfigResolver do ...@@ -7,24 +7,13 @@ RSpec.describe Resolvers::Ci::ConfigResolver do
describe '#resolve' do describe '#resolve' do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository, creator: user, namespace: user.namespace) } let_it_be(:project) { create(:project, :repository) }
let_it_be(:sha) { nil } let_it_be(:sha) { nil }
let_it_be(:content) do let_it_be(:content) do
File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci_includes.yml')) File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci_includes.yml'))
end end
let(:ci_lint) do
ci_lint_double = instance_double(::Gitlab::Ci::Lint)
allow(ci_lint_double).to receive(:validate).and_return(fake_result)
ci_lint_double
end
before do
allow(::Gitlab::Ci::Lint).to receive(:new).and_return(ci_lint)
end
subject(:response) do subject(:response) do
resolve(described_class, resolve(described_class,
args: { project_path: project.full_path, content: content, sha: sha }, args: { project_path: project.full_path, content: content, sha: sha },
...@@ -49,51 +38,76 @@ RSpec.describe Resolvers::Ci::ConfigResolver do ...@@ -49,51 +38,76 @@ RSpec.describe Resolvers::Ci::ConfigResolver do
end end
end end
context 'with a valid .gitlab-ci.yml' do context 'when the user can create a pipeline' do
context 'with a sha' do let(:ci_lint) do
let(:sha) { '1231231' } ci_lint_double = instance_double(::Gitlab::Ci::Lint)
allow(ci_lint_double).to receive(:validate).and_return(fake_result)
it_behaves_like 'a valid config file' ci_lint_double
end end
context 'without a sha' do before do
it_behaves_like 'a valid config file' allow(::Gitlab::Ci::Lint).to receive(:new).and_return(ci_lint)
project.add_developer(user)
end end
end
context 'with an invalid .gitlab-ci.yml' do context 'with a valid .gitlab-ci.yml' do
let(:content) { 'invalid' } context 'with a sha' do
let(:sha) { '1231231' }
let(:fake_result) do it_behaves_like 'a valid config file'
Gitlab::Ci::Lint::Result.new( end
jobs: [],
merged_yaml: content, context 'without a sha' do
errors: ['Invalid configuration format'], it_behaves_like 'a valid config file'
warnings: [] end
)
end end
it 'responds with errors about invalid syntax' do context 'with an invalid .gitlab-ci.yml' do
expect(response[:status]).to eq(:invalid) let(:content) { 'invalid' }
expect(response[:errors]).to eq(['Invalid configuration format'])
let(:fake_result) do
Gitlab::Ci::Lint::Result.new(
jobs: [],
merged_yaml: content,
errors: ['Invalid configuration format'],
warnings: []
)
end
it 'responds with errors about invalid syntax' do
expect(response[:status]).to eq(:invalid)
expect(response[:errors]).to match_array(['Invalid configuration format'])
end
end end
end
context 'with an invalid SHA' do context 'with an invalid SHA' do
let_it_be(:sha) { ':' } let_it_be(:sha) { ':' }
let(:ci_lint) do let(:ci_lint) do
ci_lint_double = instance_double(::Gitlab::Ci::Lint) ci_lint_double = instance_double(::Gitlab::Ci::Lint)
allow(ci_lint_double).to receive(:validate).and_raise(GRPC::InvalidArgument) allow(ci_lint_double).to receive(:validate).and_raise(GRPC::InvalidArgument)
ci_lint_double ci_lint_double
end
it 'logs the invalid SHA to Sentry' do
expect(Gitlab::ErrorTracking).to receive(:track_and_raise_exception)
.with(GRPC::InvalidArgument, sha: ':')
response
end
end end
end
it 'logs the invalid SHA to Sentry' do context 'when the user cannot create a pipeline' do
expect(Gitlab::ErrorTracking).to receive(:track_and_raise_exception) before do
.with(GRPC::InvalidArgument, sha: ':') project.add_guest(user)
end
response it 'returns an error stating that the user cannot access the linting' do
expect { response }.to raise_error(::Gitlab::Graphql::Errors::ResourceNotAvailable)
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment