diff --git a/files/gitlab-config-template/gitlab.rb.template b/files/gitlab-config-template/gitlab.rb.template index 8cc8b032d0c0750aebbba4dd184ca71ba596c14d_ZmlsZXMvZ2l0bGFiLWNvbmZpZy10ZW1wbGF0ZS9naXRsYWIucmIudGVtcGxhdGU=..a3923de8023ffcde9ac57625d0b9f382901504f3_ZmlsZXMvZ2l0bGFiLWNvbmZpZy10ZW1wbGF0ZS9naXRsYWIucmIudGVtcGxhdGU= 100644 --- a/files/gitlab-config-template/gitlab.rb.template +++ b/files/gitlab-config-template/gitlab.rb.template @@ -806,6 +806,9 @@ #### Redis local UNIX socket (will be disabled if TCP method is used) # gitlab_rails['redis_socket'] = "/var/opt/gitlab/redis/redis.socket" +#### Session cookie settings +# gitlab_rails['session_store_session_cookie_token_prefix'] = '' + #### Sentinel support ####! To have Sentinel working, you must enable Redis TCP connection support ####! above and define a few Sentinel hosts below (to get a reliable setup diff --git a/files/gitlab-cookbooks/gitlab/attributes/default.rb b/files/gitlab-cookbooks/gitlab/attributes/default.rb index 8cc8b032d0c0750aebbba4dd184ca71ba596c14d_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvYXR0cmlidXRlcy9kZWZhdWx0LnJi..a3923de8023ffcde9ac57625d0b9f382901504f3_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvYXR0cmlidXRlcy9kZWZhdWx0LnJi 100644 --- a/files/gitlab-cookbooks/gitlab/attributes/default.rb +++ b/files/gitlab-cookbooks/gitlab/attributes/default.rb @@ -592,6 +592,8 @@ # used by workhorse to connect to a separate external redis instead of the omnibus-gitlab redis default['gitlab']['gitlab_rails']['redis_workhorse_sentinel_master'] = nil +default['gitlab']['gitlab_rails']['session_store_session_cookie_token_prefix'] = '' + default['gitlab']['gitlab_rails']['redis_yml_override'] = nil default['gitlab']['gitlab_rails']['smtp_enable'] = false diff --git a/files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb b/files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb index 8cc8b032d0c0750aebbba4dd184ca71ba596c14d_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvcmVjaXBlcy9naXRsYWItcmFpbHMucmI=..a3923de8023ffcde9ac57625d0b9f382901504f3_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvcmVjaXBlcy9naXRsYWItcmFpbHMucmI= 100644 --- a/files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb +++ b/files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb @@ -326,6 +326,18 @@ end end +templatesymlink "Create a session_store.yml and create a symlink to Rails root" do + link_from File.join(gitlab_rails_source_dir, "config/session_store.yml") + link_to File.join(gitlab_rails_etc_dir, "session_store.yml") + source "session_store.yml.erb" + owner "root" + group gitlab_group + mode "0640" + variables node['gitlab']['gitlab_rails'].to_hash + dependent_services.each { |svc| notifies :restart, svc } + sensitive true +end + templatesymlink "Create a smtp_settings.rb and create a symlink to Rails root" do link_from File.join(gitlab_rails_source_dir, "config/initializers/smtp_settings.rb") link_to File.join(gitlab_rails_etc_dir, "smtp_settings.rb") diff --git a/files/gitlab-cookbooks/gitlab/templates/default/session_store.yml.erb b/files/gitlab-cookbooks/gitlab/templates/default/session_store.yml.erb new file mode 100644 index 0000000000000000000000000000000000000000..a3923de8023ffcde9ac57625d0b9f382901504f3_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvdGVtcGxhdGVzL2RlZmF1bHQvc2Vzc2lvbl9zdG9yZS55bWwuZXJi --- /dev/null +++ b/files/gitlab-cookbooks/gitlab/templates/default/session_store.yml.erb @@ -0,0 +1,6 @@ +# This file is managed by gitlab-ctl. Manual changes will be +# erased! To change the contents below, edit /etc/gitlab/gitlab.rb +# and run `sudo gitlab-ctl reconfigure`. + +production: + session_cookie_token_prefix: <%= quote(@session_store_session_cookie_token_prefix) %> diff --git a/spec/chef/cookbooks/gitlab/recipes/gitlab-rails/session_store_yml_spec.rb b/spec/chef/cookbooks/gitlab/recipes/gitlab-rails/session_store_yml_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..a3923de8023ffcde9ac57625d0b9f382901504f3_c3BlYy9jaGVmL2Nvb2tib29rcy9naXRsYWIvcmVjaXBlcy9naXRsYWItcmFpbHMvc2Vzc2lvbl9zdG9yZV95bWxfc3BlYy5yYg== --- /dev/null +++ b/spec/chef/cookbooks/gitlab/recipes/gitlab-rails/session_store_yml_spec.rb @@ -0,0 +1,39 @@ +require 'chef_helper' + +RSpec.describe 'gitlab::gitlab-rails' do + describe 'Session store settings' do + let(:chef_run) { ChefSpec::SoloRunner.new(step_into: 'templatesymlink').converge('gitlab::default') } + let(:session_store_yml_template) { chef_run.template('/var/opt/gitlab/gitlab-rails/etc/session_store.yml') } + let(:session_store_yml_file_content) { ChefSpec::Renderer.new(chef_run, session_store_yml_template).content } + let(:session_store_yml) { YAML.safe_load(session_store_yml_file_content, aliases: true, symbolize_names: true) } + + before do + allow(Gitlab).to receive(:[]).and_call_original + allow(File).to receive(:symlink?).and_call_original + end + + context 'with default settings' do + it 'it renders the default settings' do + expect(session_store_yml[:production]).to eq({ session_cookie_token_prefix: "" }) + end + end + + context 'with custom session store configuration' do + before do + stub_gitlab_rb( + gitlab_rails: { + session_store_session_cookie_token_prefix: 'custom_prefix_' + } + ) + end + + it 'renders session_store.yml using these settings' do + expect(session_store_yml[:production]).to eq( + { + session_cookie_token_prefix: 'custom_prefix_' + } + ) + end + end + end +end