diff --git a/app/presenters/blob_presenter.rb b/app/presenters/blob_presenter.rb index e8261e6f8df..f5afe21ce97 100644 --- a/app/presenters/blob_presenter.rb +++ b/app/presenters/blob_presenter.rb @@ -126,13 +126,9 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated def transformed_blob_data @transformed_blob ||= if blob.path.ends_with?('.ipynb') - new_blob = IpynbDiff.transform(blob.data, - raise_errors: true, - options: { include_metadata: false, cell_decorator: :percent }) - - Gitlab::AppLogger.info(new_blob ? 'IPYNBDIFF_BLOB_GENERATED' : 'IPYNBDIFF_BLOB_NIL') - - new_blob + IpynbDiff.transform(blob.data, + raise_errors: true, + options: { include_metadata: false, cell_decorator: :percent }) end @transformed_blob ||= blob.data diff --git a/app/services/ci/parse_dotenv_artifact_service.rb b/app/services/ci/parse_dotenv_artifact_service.rb index 2ee9be476bb..725ecbcce5d 100644 --- a/app/services/ci/parse_dotenv_artifact_service.rb +++ b/app/services/ci/parse_dotenv_artifact_service.rb @@ -2,8 +2,7 @@ module Ci class ParseDotenvArtifactService < ::BaseService - MAX_ACCEPTABLE_DOTENV_SIZE = 5.kilobytes - MAX_ACCEPTABLE_VARIABLES_COUNT = 20 + include ::Gitlab::Utils::StrongMemoize SizeLimitError = Class.new(StandardError) ParserError = Class.new(StandardError) @@ -27,9 +26,9 @@ module Ci raise ArgumentError, 'Artifact is not dotenv file type' end - unless artifact.file.size < MAX_ACCEPTABLE_DOTENV_SIZE + unless artifact.file.size < dotenv_size_limit raise SizeLimitError, - "Dotenv Artifact Too Big. Maximum Allowable Size: #{MAX_ACCEPTABLE_DOTENV_SIZE}" + "Dotenv Artifact Too Big. Maximum Allowable Size: #{dotenv_size_limit}" end end @@ -45,9 +44,9 @@ module Ci end end - if variables.size > MAX_ACCEPTABLE_VARIABLES_COUNT + if variables.size > dotenv_variable_limit raise SizeLimitError, - "Dotenv files cannot have more than #{MAX_ACCEPTABLE_VARIABLES_COUNT} variables" + "Dotenv files cannot have more than #{dotenv_variable_limit} variables" end variables @@ -60,5 +59,13 @@ module Ci result.each(&:strip!) end + + def dotenv_variable_limit + strong_memoize(:dotenv_variable_limit) { project.actual_limits.dotenv_variables } + end + + def dotenv_size_limit + strong_memoize(:dotenv_size_limit) { project.actual_limits.dotenv_size } + end end end diff --git a/data/deprecations/templates/example.yml b/data/deprecations/templates/example.yml index fb164247cb6..0aaa68e4bd8 100644 --- a/data/deprecations/templates/example.yml +++ b/data/deprecations/templates/example.yml @@ -19,9 +19,7 @@ This area supports markdown. Delete this entire comment and replace it with your markdown content. - Make sure to run `bin/rake gitlab:docs:compile_deprecations` locally before committing and pushing your changes. - - When ready, assign to your tech writer to review and merge. + When ready, assign to your tech writer for review. When ready, they will run `bin/rake gitlab:docs:compile_deprecations` to update the deprecations doc, then merge. END OF BODY COMMENT --> # The following items are not published on the docs page, but may be used in the future. diff --git a/db/migrate/20211105160316_create_dotenv_application_limits.rb b/db/migrate/20211105160316_create_dotenv_application_limits.rb new file mode 100644 index 00000000000..3ea94fd60fc --- /dev/null +++ b/db/migrate/20211105160316_create_dotenv_application_limits.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class CreateDotenvApplicationLimits < Gitlab::Database::Migration[1.0] + def change + add_column(:plan_limits, :dotenv_variables, :integer, default: 20, null: false) + add_column(:plan_limits, :dotenv_size, :integer, default: 5.kilobytes, null: false) + end +end diff --git a/db/migrate/20211105161404_insert_dotenv_application_limits.rb b/db/migrate/20211105161404_insert_dotenv_application_limits.rb new file mode 100644 index 00000000000..2749cf4a019 --- /dev/null +++ b/db/migrate/20211105161404_insert_dotenv_application_limits.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class InsertDotenvApplicationLimits < Gitlab::Database::Migration[1.0] + def up + create_or_update_plan_limit('dotenv_variables', 'default', 150) + create_or_update_plan_limit('dotenv_variables', 'free', 50) + create_or_update_plan_limit('dotenv_variables', 'opensource', 150) + create_or_update_plan_limit('dotenv_variables', 'premium', 100) + create_or_update_plan_limit('dotenv_variables', 'premium_trial', 100) + create_or_update_plan_limit('dotenv_variables', 'ultimate', 150) + create_or_update_plan_limit('dotenv_variables', 'ultimate_trial', 150) + + create_or_update_plan_limit('dotenv_size', 'default', 5.kilobytes) + end + + def down + create_or_update_plan_limit('dotenv_variables', 'default', 20) + create_or_update_plan_limit('dotenv_variables', 'free', 20) + create_or_update_plan_limit('dotenv_variables', 'opensource', 20) + create_or_update_plan_limit('dotenv_variables', 'premium', 20) + create_or_update_plan_limit('dotenv_variables', 'premium_trial', 20) + create_or_update_plan_limit('dotenv_variables', 'ultimate', 20) + create_or_update_plan_limit('dotenv_variables', 'ultimate_trial', 20) + + create_or_update_plan_limit('dotenv_size', 'default', 5.kilobytes) + end +end diff --git a/db/schema_migrations/20211105160316 b/db/schema_migrations/20211105160316 new file mode 100644 index 00000000000..493dfb4afbd --- /dev/null +++ b/db/schema_migrations/20211105160316 @@ -0,0 +1 @@ +afb9552a4104b10b25d65a9fec478c5c28a31ec31402400554db4288033bacb6 \ No newline at end of file diff --git a/db/schema_migrations/20211105161404 b/db/schema_migrations/20211105161404 new file mode 100644 index 00000000000..98b4bcdacfb --- /dev/null +++ b/db/schema_migrations/20211105161404 @@ -0,0 +1 @@ +911cc21de320d0d5716ce80ebca56433b793c2072cb62da783605c99bb9aada9 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 669d2549dd8..83eaafdd9bc 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -17574,7 +17574,9 @@ CREATE TABLE plan_limits ( ci_jobs_trace_size_limit integer DEFAULT 100 NOT NULL, pages_file_entries integer DEFAULT 200000 NOT NULL, dast_profile_schedules integer DEFAULT 1 NOT NULL, - external_audit_event_destinations integer DEFAULT 5 NOT NULL + external_audit_event_destinations integer DEFAULT 5 NOT NULL, + dotenv_variables integer DEFAULT 20 NOT NULL, + dotenv_size integer DEFAULT 5120 NOT NULL ); CREATE SEQUENCE plan_limits_id_seq diff --git a/doc/administration/instance_limits.md b/doc/administration/instance_limits.md index 2f20026ace4..2f1161793fe 100644 --- a/doc/administration/instance_limits.md +++ b/doc/administration/instance_limits.md @@ -610,6 +610,40 @@ To disable this limitation entirely, disable the feature flag in the console: Feature.disable(:ci_yaml_limit_size) ``` +### Limit dotenv variables + +> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/321552) in GitLab 14.5. + +You can set a limit on the maximum number of variables inside of a dotenv artifact. +This limit is checked every time a dotenv file is exported as an artifact. + +Set the limit to `0` to disable it. Defaults to `0` on self-managed instances. + +To set this limit to `100` on a self-managed instance, run the following command in the +[GitLab Rails console](operations/rails_console.md#starting-a-rails-console-session): + +```ruby +Plan.default.actual_limits.update!(dotenv_variable_limit: 100) +``` + +This limit is [enabled on GitLab.com](../user/gitlab_com/index.md#gitlab-cicd). + +### Limit dotenv file size + +> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/321552) in GitLab 14.5. + +You can set a limit on the maximum size of a dotenv artifact. This limit is checked +every time a dotenv file is exported as an artifact. + +Set the limit to `0` to disable it. Defaults to 5KB. + +To set this limit to 5KB on a self-managed installation, run the following in the +[GitLab Rails console](operations/rails_console.md#starting-a-rails-console-session): + +```ruby +Plan.default.actual_limits.update!(dotenv_size_limit: 5.kilobytes) +``` + ## Instance monitoring and metrics ### Limit inbound incident management alerts diff --git a/doc/user/gitlab_com/index.md b/doc/user/gitlab_com/index.md index b6211683283..e626219c55f 100644 --- a/doc/user/gitlab_com/index.md +++ b/doc/user/gitlab_com/index.md @@ -140,6 +140,7 @@ the related documentation. | [Scheduled Job Archival](../../user/admin_area/settings/continuous_integration.md#archive-jobs) | 3 months | Never | | Max test cases per [unit test report](../../ci/unit_test_reports.md) | `500_000` | Unlimited | | [Max registered runners](../../administration/instance_limits.md#number-of-registered-runners-per-scope) | Free tier: `50` per-group / `50` per-project
All paid tiers: `1_000` per-group / `1_000` per-project | `1_000` per-group / `1_000` per-project | +| [Limit dotenv variables](../../administration/instance_limits.md#limit-dotenv-variables) | Free tier: `50` / Premium tier: `100` / Ultimate tier: `150` | Unlimited | ## Account and limit settings diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index 30871a16e4e..bad792992fc 100644 --- a/lib/gitlab/diff/file.rb +++ b/lib/gitlab/diff/file.rb @@ -463,9 +463,7 @@ module Gitlab diff.diff = new_diff.scan(/.*\n/)[2..-1].join('') if new_diff - Gitlab::AppLogger.info({ message: new_diff ? 'IPYNB_DIFF_GENERATED' : 'IPYNB_DIFF_NIL', - from: from&.to_s, to: to&.to_s, - lib_version: Gem.loaded_specs["ipynbdiff"].version.version }) + Gitlab::AppLogger.info({ message: new_diff ? 'IPYNB_DIFF_GENERATED' : 'IPYNB_DIFF_NIL' }) rescue IpynbDiff::InvalidNotebookError => e Gitlab::ErrorTracking.track_exception(e, issue_url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/344676') diff --git a/scripts/lint-doc.sh b/scripts/lint-doc.sh index e99b8a47301..1698d724fd2 100755 --- a/scripts/lint-doc.sh +++ b/scripts/lint-doc.sh @@ -128,7 +128,7 @@ function run_locally_or_in_docker() { $cmd $args elif hash docker 2>/dev/null then - docker run -t -v ${PWD}:/gitlab -w /gitlab --rm registry.gitlab.com/gitlab-org/gitlab-docs/lint-markdown:alpine-3.13-vale-2.10.2-markdownlint-0.26.0 ${cmd} ${args} + docker run -t -v ${PWD}:/gitlab -w /gitlab --rm registry.gitlab.com/gitlab-org/gitlab-docs/lint-markdown:alpine-3.14-vale-2.12.0-markdownlint-0.29.0 ${cmd} ${args} else echo echo " ✖ ERROR: '${cmd}' not found. Install '${cmd}' or Docker to proceed." >&2 diff --git a/spec/services/ci/parse_dotenv_artifact_service_spec.rb b/spec/services/ci/parse_dotenv_artifact_service_spec.rb index 7536e04f2de..c4040a426f2 100644 --- a/spec/services/ci/parse_dotenv_artifact_service_spec.rb +++ b/spec/services/ci/parse_dotenv_artifact_service_spec.rb @@ -45,7 +45,7 @@ RSpec.describe Ci::ParseDotenvArtifactService do it 'returns error' do expect(subject[:status]).to eq(:error) - expect(subject[:message]).to eq("Dotenv Artifact Too Big. Maximum Allowable Size: #{described_class::MAX_ACCEPTABLE_DOTENV_SIZE}") + expect(subject[:message]).to eq("Dotenv Artifact Too Big. Maximum Allowable Size: #{service.send(:dotenv_size_limit)}") expect(subject[:http_status]).to eq(:bad_request) end end @@ -186,7 +186,7 @@ RSpec.describe Ci::ParseDotenvArtifactService do context 'when more than limitated variables are specified in dotenv' do let(:blob) do StringIO.new.tap do |s| - (described_class::MAX_ACCEPTABLE_VARIABLES_COUNT + 1).times do |i| + (service.send(:dotenv_variable_limit) + 1).times do |i| s << "KEY#{i}=VAR#{i}\n" end end.string @@ -194,7 +194,7 @@ RSpec.describe Ci::ParseDotenvArtifactService do it 'returns error' do expect(subject[:status]).to eq(:error) - expect(subject[:message]).to eq("Dotenv files cannot have more than #{described_class::MAX_ACCEPTABLE_VARIABLES_COUNT} variables") + expect(subject[:message]).to eq("Dotenv files cannot have more than #{service.send(:dotenv_variable_limit)} variables") expect(subject[:http_status]).to eq(:bad_request) end end diff --git a/spec/support/time_travel.rb b/spec/support/time_travel.rb index 332b37c1f2b..9dfbfd20524 100644 --- a/spec/support/time_travel.rb +++ b/spec/support/time_travel.rb @@ -9,14 +9,6 @@ RSpec.configure do |config| freeze_time { example.run } end - config.around(:example, :time_travel) do |example| - duration = example.metadata[:time_travel] - - raise 'The time_travel RSpec metadata must have an ActiveSupport::Duration value (such as `30.days`).' unless duration.is_a?(ActiveSupport::Duration) - - travel(duration) { example.run } - end - config.around(:example, :time_travel_to) do |example| date_or_time = example.metadata[:time_travel_to] diff --git a/spec/support_specs/time_travel_spec.rb b/spec/support_specs/time_travel_spec.rb index 8d80a889443..8fa51c0c1f0 100644 --- a/spec/support_specs/time_travel_spec.rb +++ b/spec/support_specs/time_travel_spec.rb @@ -9,18 +9,6 @@ RSpec.describe 'time travel' do end end - describe ':time_travel' do - today = Date.current - - it 'time-travels by the given duration', time_travel: 3.days do - expect(Date.current).to eq(today + 3.days) - end - - it 'works with negative durations', time_travel: -5.days do - expect(Date.current).to eq(today - 5.days) - end - end - describe ':time_travel_to' do it 'time-travels to the specified date', time_travel_to: '2020-01-01' do expect(Date.current).to eq(Date.new(2020, 1, 1))