Commit Graph

162 Commits

Author SHA1 Message Date
GitLab Bot aca89cb7e9 Add latest changes from gitlab-org/gitlab@master 2020-08-04 15:09:27 +00:00
GitLab Bot ed00b1a6a3 Add latest changes from gitlab-org/gitlab@master 2020-07-28 12:09:49 +00:00
GitLab Bot ce34395e91 Add latest changes from gitlab-org/gitlab@master 2020-07-13 12:09:18 +00:00
GitLab Bot 2f147005c5 Add latest changes from gitlab-org/gitlab@master 2020-07-11 00:09:17 +00:00
GitLab Bot c6e6762bbf Add latest changes from gitlab-org/gitlab@master 2020-06-01 09:08:28 +00:00
GitLab Bot a5650b86b5 Add latest changes from gitlab-org/gitlab@master 2020-05-13 21:08:55 +00:00
GitLab Bot 3aeda4e614 Add latest changes from gitlab-org/gitlab@master 2020-04-30 21:09:47 +00:00
GitLab Bot 0f59ad0c29 Add latest changes from gitlab-org/gitlab@master 2020-04-28 09:09:34 +00:00
GitLab Bot e33f87ac0f Add latest changes from gitlab-org/gitlab@master 2020-04-21 15:21:10 +00:00
GitLab Bot b71a496c7a Add latest changes from gitlab-org/gitlab@master 2020-04-15 03:09:11 +00:00
GitLab Bot 132dd28342 Add latest changes from gitlab-org/gitlab@master 2020-03-28 09:08:30 +00:00
GitLab Bot 6f2065c468 Add latest changes from gitlab-org/gitlab@master 2020-03-25 15:07:47 +00:00
GitLab Bot 76e9fc7b29 Add latest changes from gitlab-org/gitlab@master 2020-03-11 18:09:23 +00:00
GitLab Bot 1fa79760ad Add latest changes from gitlab-org/gitlab@master 2020-03-10 12:08:16 +00:00
GitLab Bot 9ac561230f Add latest changes from gitlab-org/gitlab@master 2020-03-10 00:08:12 +00:00
GitLab Bot 22e9af3c8b Add latest changes from gitlab-org/gitlab@master 2020-01-27 12:08:35 +00:00
GitLab Bot 4f749a9b30 Add latest changes from gitlab-org/gitlab@master 2020-01-25 00:08:59 +00:00
GitLab Bot 411cc77938 Add latest changes from gitlab-org/gitlab@master 2020-01-24 18:09:00 +00:00
GitLab Bot ccaa944882 Add latest changes from gitlab-org/gitlab@master 2020-01-23 03:08:53 +00:00
GitLab Bot a5ab3467a7 Add latest changes from gitlab-org/gitlab@master 2020-01-13 15:07:53 +00:00
GitLab Bot 511e761b41 Add latest changes from gitlab-org/gitlab@master 2020-01-03 15:08:33 +00:00
GitLab Bot 7f8330873c Add latest changes from gitlab-org/gitlab@master 2019-12-18 21:07:37 +00:00
GitLab Bot e723867717 Add latest changes from gitlab-org/gitlab@master 2019-12-17 18:07:48 +00:00
GitLab Bot 34b3567c97 Add latest changes from gitlab-org/gitlab@master 2019-11-19 09:06:16 +00:00
GitLab Bot 25521def84 Add latest changes from gitlab-org/gitlab@master 2019-10-03 18:06:11 +00:00
GitLab Bot 2b3007dc96 Add latest changes from gitlab-org/gitlab@master 2019-09-20 18:06:35 +00:00
GitLab Bot 80f61b4035 Add latest changes from gitlab-org/gitlab@master 2019-09-18 14:02:45 +00:00
GitLab Bot b7dfe2ae40 Add latest changes from gitlab-org/gitlab@master 2019-09-13 13:26:31 +00:00
Alessio Caiazza e32069ef6c Process workhorse accelerated wiki uploads
Wiki attachments can be workhorse accelerated.
This commit is backward compatible with older workhorse
2019-09-06 15:53:13 +02:00
dineshpanda e908e11776 Avoid calling freeze on already frozen strings in lib/gitlab 2019-09-04 09:52:02 +05:30
Mayra Cabrera 0ab89d8e36 Add a rubocop for Rails.logger
Suggests to use a JSON structured log instead

Related to https://gitlab.com/gitlab-org/gitlab-ce/issues/54102
2019-07-10 19:26:47 +00:00
Stan Hu f93b2e02a5 Run rubocop -a on CE files 2019-05-05 03:24:28 -07:00
Andrew Newdigate 4f4de36cac Migrate correlation and tracing code to LabKit
This change is a fairly straightforward refactor to extract the tracing
and correlation-id code from the gitlab rails codebase into the new
LabKit-Ruby project.

The corresponding import into LabKit-Ruby was in
https://gitlab.com/gitlab-org/labkit-ruby/merge_requests/1

The code itself remains very similar for now.

Extracting it allows us to reuse it in other projects, such as
Gitaly-Ruby. This will give us the advantages of correlation-ids and
distributed tracing in that project too.
2019-04-18 09:57:16 +02:00
Stan Hu 01203e7188 Fix health checks not working behind load balancers
The change in
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/24199 caused
requests coming from a load balancer to arrive as 127.0.0.1 instead of
the actual IP.

`Rack::Request#ip` behaves slightly differently different than
`ActionDispatch::Request#remote_ip`: the former will return the first
X-Forwarded-For IP if all of the IPs are trusted proxies, while the
second one filters out all proxies and falls back to REMOTE_ADDR, which
is 127.0.0.1.

For now, we can revert back to using `Rack::Request` because these
middlewares don't manipulate parameters. The actual fix problem involves
fixing Rails: https://github.com/rails/rails/issues/28436.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/58573
2019-03-12 12:46:40 -07:00
Stan Hu 51ca79228b Log queue duration in production_json.log
`queue_duration` is a useful metric that is currently in api_json.log
but not in production_json.log. We should add it because it tells us how
long the request sat in Workhorse before Unicorn processed it. Having
this field enables the support team to better troubleshoot when delays
began to happen.
2019-02-12 06:58:55 -08:00
Rémy Coutable 3a2abc1d50
Enable the Layout/ExtraSpacing cop
Signed-off-by: Rémy Coutable <remy@rymai.me>
2019-01-24 13:05:45 +01:00
Ash McKenzie 61111d4c0d
Bang up predicate methods and use #internal_route?
Extract internal route logic check out into #internal_route?
Add ? to #grack_route and #lfs_route predicate methods
2019-01-16 19:14:46 +11:00
Ash McKenzie c0a5b628c8
Allow sidekiq admin requests, regardless of root 2019-01-16 19:14:46 +11:00
Stan Hu aff2b6e4eb Switch use of Rack::Request to ActionDispatch::Request
As mentioned in
https://gitlab.com/gitlab-org/gitlab-ee/issues/9035#note_129093444,
Rails 5 switched ActionDispatch::Request so that it no longer inherits
Rack::Request directly. A middleware that uses Rack::Request to
read the environment may see stale request parameters if
another middleware modifies the environment via ActionDispatch::Request.
To be safe, we should be using ActionDispatch::Request everywhere.
2019-01-07 00:35:53 -08:00
Stan Hu 7d28e39f58 Fix multipart attachments not uploading
Mixing and matching the use of Rack::Request and ActionDispatch::Request
in Rails 5 is bad, particularly if you have middleware that
manipulates or accesses environment variables.

`Gitlab::Middleware::Multipart` attempts to rewrite request parameters
to the proper values (e.g. replacing `data_file` with
`UploadedFile`). It does this by calling `Rack::Request#update_params`,
which essentially updates `env['rack.request.form_hash']`.

By changing to `ActionDispatch::Request`, the Go middleware was causing
the request parameters to be stored inside
`env['action_dispatch.request.request_parameters']`. Later calls to
`Rack::Request#update_params` would not have any effect because it would
attempt to update `env['rack.request.form_has']` instead of
`env['action_dispatch.request.request_parameters']`. As a result, the
controller still saw the old parameters.

Since the Go middleware appears to be using `ActionDispatch::Request`
for authorization methods, we can switch the multipart middleware to
use it too.

Closes https://gitlab.com/gitlab-org/gitlab-ee/issues/9035
2019-01-05 01:56:47 -08:00
mortyccp 3a62f15657 Remove authentication via warden and PRIVATE_TOKEN header 2019-01-03 20:28:02 +08:00
mortyccp 970582079a Fix lint error 2019-01-03 20:28:02 +08:00
mortyccp d1fea99deb Allow basic authentication on go get middleware 2019-01-03 20:28:02 +08:00
Jasper Maes 56296f1eda Remove rails4 specific code 2018-12-16 10:48:41 +01:00
Kamil Trzciński eb33ca49b8 Add `::` to Gitlab::Middleware::CorrelationId 2018-12-07 12:18:03 +00:00
Kamil Trzciński 39c1731a53 Log and pass correlation-id between Unicorn, Sidekiq and Gitaly
The Correlation ID is taken or generated from received X-Request-ID.
Then it is being passed to all executed services (sidekiq workers
or gitaly calls).

The Correlation ID is logged in all structured logs as `correlation_id`.
2018-12-06 20:46:14 +01:00
gfyoung 7ec8af5017 Enable even more frozen string for lib/gitlab
Enables frozen string for the following:

* lib/gitlab/hook_data/**/*.rb
* lib/gitlab/i18n/**/*.rb
* lib/gitlab/import/**/*.rb
* lib/gitlab/import_export/**/*.rb
* lib/gitlab/kubernetes/**/*.rb
* lib/gitlab/legacy_github_import/**/*.rb
* lib/gitlab/manifest_import/**/*.rb
* lib/gitlab/metrics/**/*.rb
* lib/gitlab/middleware/**/*.rb

Partially addresses gitlab-org/gitlab-ce#47424.
2018-11-16 17:41:14 -08:00
Stan Hu 39f252254b Make sure there's only one slash as path separator
In Ruby 2.4, `URI.join("http://test//", "a").to_s` will
remove the double slash, however it's not the case in
Ruby 2.5. Using chomp should work better for the intention,
as we're not trying to allow things like ../ or / paths
resolution.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/53180
2018-11-09 15:36:45 -08:00
Andrew Newdigate 647db32396 Fix multipart error on rails reload 2018-09-05 18:00:11 +00:00
Jan Provaznik 4ca9f3b417 Add public/uploads/tmp to allowed upload paths
When direct_upload is enabled and a for file is being uploaded,
then workhorse uses `public/uploads/tmp` path. If `uploads.storage_path`
i sset to a different directory, then upload fails because
`public/uploads/tmp` is not in allowed paths.
2018-08-21 17:39:46 +02:00
Stan Hu 22d44ae9a6 Use /-/health instead of breaking /-/liveness 2018-07-28 14:35:02 -07:00
Stan Hu eb2bc7d99a Simplify /-/liveness check to avoid connecting to the database
The previous implementation would hit the database each time
and provide a dummy response. If the database goes down, this
means all application workers would be taken out of service.
Simplify this check by using a Rails middleware that intercepts
this endpoint and returns a 200 response.
2018-07-28 14:35:02 -07:00
Jan Provaznik e2ec97a92e Add FileUploader.root to allowed upload paths
Currently we check if uploaded file is under
`Gitlab.config.uploads.storage_path`, the problem is that
uploads are placed in `uploads` subdirectory which is symlink.

In allow_path? method we check real (expanded) paths, which causes
that `Gitlab.config.uploads.storage_path` is expaned into symlink
path and there is a mismatch with upload file path.

By adding `Gitlab.config.uploads.storage_path/uploads` into allowed
paths, this path is expaned during path check.

`Gitlab.config.uploads.storage_path` is left there intentionally in case
some uploader wouldn't use `uploads` subdir.
2018-07-08 10:43:57 +02:00
Brett Walker f3e1028371 Refactor rspec matchers in read_only_spec.rb 2018-07-07 04:22:44 +00:00
Kamil Trzciński (OoO till 3th) 34694c3afc Merge branch 'jprovazn-direct-upload' into 'master'
Add workhorse authorize method for project/group uploads

Closes #44663

See merge request gitlab-org/gitlab-ce!19717
2018-07-04 09:50:29 +00:00
Ash McKenzie 26bea57883 Better route matching for read-only detection 2018-07-02 17:29:04 +10:00
Jan Provaznik 249c24891a Updated multipart to support workhorse direct uploads 2018-06-27 12:54:46 +02:00
Mike Greiling 996e5d79df
move dev server middleware to new namespace 2018-05-01 15:15:10 -05:00
Kamil Trzciński 678620cce6 Add `direct_upload` setting for artifacts 2018-04-05 15:01:14 +02:00
Stan Hu 72da56aaa5 Fix "A copy of Gitlab::Middleware::Readonly has been removed from the module tree but is still active"
Similar to #34047 and #29327
2018-03-21 21:18:11 -07:00
Gabriel Mazetto 5c7a738105 [CE] Add Naming/FileName rule checking expected class/module per filename 2018-03-08 12:56:54 +00:00
Lin Jen-Shin bb4fcb7809 Move constants and update for feedback 2018-03-03 00:39:42 +08:00
Lin Jen-Shin 6c5a7d5305 Merge remote-tracking branch 'upstream/master' into 42572-release-controller
* upstream/master: (889 commits)
  SlackService - respect `notify_only_default_branch` for push events
  Clarify usage ping wording in admin area
  Update incoming emails documents
  Allow to include also descendant group labels
  Update docs on grouping CI jobs
  Support additional LabelsFinder parameters for group labels
  Extend Cluster Applications to install GitLab Runner to Kubernetes cluster
  Remove registry list webpack entry point
  Remove trailing newline that was causing an EE conflict
  Small fixes in Vuex docs
  Remove u2f webpack bundle
  Update documentation WRT to request parameters
  remove common_vue CommonsChunk config
  Fetch commit signatures from Gitaly in batches
  migrate stl_viewer to dynamic import
  migrate sketch_viewer to dynamic import
  migrate pdf_viewer to dynamic import
  migrate notebook_viewer to dynamic import
  migrate balsamiq_viewer to dynamic import
  Add some strings that were missing in gitlab.pot
  ...
2018-03-03 00:10:21 +08:00
Douwe Maan 7a6c7bd66b Allow token authentication on go-get request 2018-02-23 10:33:46 +00:00
Alessio Caiazza 34c2a59c57
Honour workhorse provided file name
In the attempt to unify file uploading at workhorse level gitlab-org/gitlab-workhorse!230
we moved to a prefix-based tempfile creation in order to avoid upload collisions.

Artifacts and LFS uploads already set original_filename to workhorse provided filename

This commit add the same feature to `Gitlab::Middleware::Multipart`
2018-02-12 17:31:29 +01:00
Lin Jen-Shin 5309d4457a Put controller in its separate file 2018-02-07 22:56:07 +08:00
Lin Jen-Shin 31f1ec59a7 Release the entire env 2018-02-07 22:56:07 +08:00
Lin Jen-Shin bbfce29ba8 Use a controller to hold request values
So that we don't need to hold env after the request.
This makes it much harder to test, especially Rails session is
acting weirdly, so we need `dig('flash', 'flashes', 'alert')`
to dig the actual flash value.
2018-02-07 22:45:02 +08:00
Lin Jen-Shin d4d564c8e7 Try not to hold env and release the controller
after the request. This way, we could release the
project referred from the controller, which potentially
referred a repository which potentially allocated a lot of
memories.

Before this change, we could hold the last request data
and cannot release the memory. After this change, the
largest request data should be able to be collected from GC.

This might not impact the instances having heavy load,
as the last request should be changing all the time,
and GC won't kick in for each request anyway.

However it could still potentially allow us to free more
memories for each GC runs, because now we could free one
more request anyway.
2018-02-07 22:45:02 +08:00
Mario de la Ossa eaada9d706 use Gitlab::UserSettings directly as a singleton instead of including/extending it 2018-02-02 18:39:55 +00:00
Takuya Noguchi 2b6307f6ad Enable RuboCop Style/RegexpLiteral 2018-02-01 02:06:07 +09:00
🙈 jacopo beschi 🙉 729f05f0e3 Adds Rubocop rule for line break around conditionals 2018-01-11 16:34:01 +00:00
digitalMoksha aeb2f49fd4 Revert "check for `read_only?` first before seeing if request is disallowed"
This reverts commit 91075c8237.
2017-11-21 15:35:30 +01:00
digitalMoksha 91075c8237 check for `read_only?` first before seeing if request is disallowed 2017-11-21 13:30:54 +01:00
digitalMoksha cba68d338b use `Gitlab::Routing.url_helpers` instead of `Rails.application.routes.url_helpers`
since `Rails.application.routes.url_helpers` creates a new anonymous module every time it's called
2017-11-21 13:29:57 +01:00
Stan Hu 3c52e2f06e Optimize read-only middleware so that it does not consume as much CPU
In !15082, we changed the behavior of the middleware to call
`Rails.application.routes.recognize_path` whenever a new route arrived.
However, this can be a CPU-intensive task because Rails needs to allocate
memory and compile 850+ different regular expressions, which are complicated
in GitLab.

As a short-term fix, we can do a lightweight string match before
we do the heavier comparison.

Closes #40185, gitlab-com/infrastructure#3240
2017-11-20 15:27:52 -08:00
Rémy Coutable 4f09d099e9 Merge branch '18040-rubocop-line-break-after-guard-clause' into 'master'
Adds Rubocop rule for line break after guard clause

Closes #18040

See merge request gitlab-org/gitlab-ce!15188
2017-11-20 09:22:14 +00:00
Douwe Maan f767dd4a4d Fix go-import meta data when enabled_git_access_protocol is a blank string 2017-11-17 12:17:16 +01:00
Jacopo 181cd299f9 Adds Rubocop rule for line break after guard clause
Adds a rubocop rule (with autocorrect) to ensure line break after guard clauses.
2017-11-16 17:58:29 +01:00
Douwe Maan b579cc7620 Merge branch 'feature-change-signout-route' into 'master'
Change Sign Out route from a DELETE to a GET

Closes #39708

See merge request gitlab-org/gitlab-ce!15231
2017-11-08 09:28:50 +00:00
Joe Marty 4dea7944c4 Updates tests to reflect sign_out route change
- Also remove sign_out DELETE route from read-only whitelist routes
2017-11-07 11:42:25 -06:00
Pawel Chojnacki 67b3e3d84a move metrics for ActiveRecord, RailsCache and queue duration to instance variables 2017-11-02 18:18:16 +01:00
Pawel Chojnacki 77e938a8f9 Avoid using Send (but is it better?) + small rubocop cleanup 2017-11-02 18:11:44 +01:00
Pawel Chojnacki 95a23d246c Convert rails_queue_duration to metric_rails_queue_duration_seconds 2017-11-02 18:11:44 +01:00
Brett Walker 2fd5cc2bff Geo route whitelisting is too optimistic 2017-11-02 12:50:04 +00:00
Guilherme Vieira 1cc92dae77 Returns a ssh url for go-get=1 2017-10-31 19:22:40 -02:00
Toon Claes d13669716a Create idea of read-only database
In GitLab EE, a GitLab instance can be read-only (e.g. when it's a Geo
secondary node). But in GitLab CE it also might be useful to have the
"read-only" idea around. So port it back to GitLab CE.

Also having the principle of read-only in GitLab CE would hopefully
lead to less errors introduced, doing write operations when there
aren't allowed for read-only calls.

Closes gitlab-org/gitlab-ce#37534.
2017-10-06 22:37:40 +02:00
Robert Speicher bc10afb600 Merge branch 'dm-go-get-xss' into 'security-9-3'
Fix XSS issue in go-get handling

See merge request !2128
2017-09-07 20:22:16 -04:00
Robert Speicher 4edfad9678 Enable Layout/TrailingWhitespace cop and auto-correct offenses 2017-08-15 13:44:37 -04:00
Robert Speicher d0622b79d8 Better categorize test coverage results
Also marks a few things as uncovered, and removes an unused class.
2017-08-11 10:59:11 -04:00
Douwe Maan 359f04e8a1 Fix go-get support for projects in nested groups 2017-03-07 19:40:19 -06:00
Mike Greiling 780e3e976d fix missing @ symbol 2017-02-27 12:20:00 -06:00
Mike Greiling 48707bc2ab ensure webpack dev server proxy connects regardless of request headers 2017-02-27 00:32:50 -06:00
Douwe Maan b7d8df503c Enable Style/MutableConstant 2017-02-23 09:31:56 -06:00
Mike Greiling a2d837a371 add rack middleware to proxy webpack dev server 2017-02-01 16:23:26 -06:00
Jacob Vosmaer 4ec259fd36 Inject ::UploadedFile from Multipart middleware
I mistakenly concluded Rack::Multipart injects File instances into the
params. These should be UploadedFile instances. This reuses a mock
UploadedFile class we already had in GitLab.
2016-12-21 13:07:53 +01:00
Jacob Vosmaer 6731ab5d76 Add Gitlab::Middleware::Multipart 2016-12-15 12:26:36 +01:00
Jacob Vosmaer 2bd0ed4a5c Fix typo in gitlab-workhorse header 2016-08-19 12:25:52 +02:00
Grzegorz Bizon face87b7bb Enable Style/Semicolon rubocop style cop
See #17478
2016-06-01 08:45:14 +02:00
Jacob Vosmaer 5771114f9b Rename metric to 'rails queue duration' 2016-05-26 17:53:21 +02:00