Skip to content

Avoid remote development env overwrite on production

Zhaochen Li requested to merge zl/473215 into master

issue: Backend: Allow ENV overrides only on non produc... (#473215 - closed)

What does this MR do and why?

Clarify usage of ENV var overrides in settings ... (!159751 - merged) Makes it explicit that ENV variable overrides for remote development settings are for non-production rails environment. We need to actually enforce this in the code.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

  • Prevent ENV variable overrides In the settings module in production rails environments

How to set up and validate locally

We would only need a production console for testing out this easily.

  1. go to config/database.yml in gitlab project, and add in below config
production:
  main:
    adapter: postgresql
    encoding: unicode
    database: gitlabhq_development
    host: /Users/zhaochen.li/Projects/gitlab-development-kit/postgresql
    port: 5432
    pool: 10
    gssencmode: disable
    prepared_statements: false
    variables:
      statement_timeout: 120s

note we are using development db for production config.

  1. go to RAILS_ENV=production rails console
  2. test ::RemoteDevelopment::Settings.get_single_setting(:max_hours_before_termination_limit) to return 120 as default
  3. Then set ENV["GITLAB_REMOTE_DEVELOPMENT_MAX_HOURS_BEFORE_TERMINATION_LIMIT"] = "42"
  4. test ::RemoteDevelopment::Settings.get_single_setting(:max_hours_before_termination_limit) still returns 120, and does not take env
  5. go to rails console
  6. go through steps 3 to 5, and we should see after we set ENV, then step 5 should return 42 as expected
Edited by Zhaochen Li

Merge request reports

Loading