diff --git a/files/gitlab-cookbooks/gitlab/attributes/default.rb b/files/gitlab-cookbooks/gitlab/attributes/default.rb index 45ab05a1d9c7514c12ed5aa5f2632f2c565b191b_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvYXR0cmlidXRlcy9kZWZhdWx0LnJi..692a4fed7629073320145e6ddfb57ea46dfa9eb8_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvYXR0cmlidXRlcy9kZWZhdWx0LnJi 100644 --- a/files/gitlab-cookbooks/gitlab/attributes/default.rb +++ b/files/gitlab-cookbooks/gitlab/attributes/default.rb @@ -505,6 +505,9 @@ # Path to the public Certificate Authority file # defaults to /opt/gitlab/embedded/ssl/certs/cacert.pem. The install-dir path is set at build time default['gitlab']['gitlab_rails']['smtp_ca_file'] = "#{node['package']['install-dir']}/embedded/ssl/certs/cacert.pem" +# These are defaults from Net::SMTP: https://ruby-doc.org/stdlib-3.0.0/libdoc/net/smtp/rdoc/Net/SMTP.html +default['gitlab']['gitlab_rails']['smtp_open_timeout'] = 30 +default['gitlab']['gitlab_rails']['smtp_read_timeout'] = 60 # Path to directory that contains (ca) certificates that should also be trusted (e.g. on # outgoing Webhooks connections). For these certificates symlinks will be created in diff --git a/files/gitlab-cookbooks/gitlab/templates/default/smtp_settings.rb.erb b/files/gitlab-cookbooks/gitlab/templates/default/smtp_settings.rb.erb index 45ab05a1d9c7514c12ed5aa5f2632f2c565b191b_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvdGVtcGxhdGVzL2RlZmF1bHQvc210cF9zZXR0aW5ncy5yYi5lcmI=..692a4fed7629073320145e6ddfb57ea46dfa9eb8_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvdGVtcGxhdGVzL2RlZmF1bHQvc210cF9zZXR0aW5ncy5yYi5lcmI= 100644 --- a/files/gitlab-cookbooks/gitlab/templates/default/smtp_settings.rb.erb +++ b/files/gitlab-cookbooks/gitlab/templates/default/smtp_settings.rb.erb @@ -10,7 +10,7 @@ <% end %> user_name: <%= node['gitlab']['gitlab_rails']["smtp_user_name"]&.inspect || "secrets.username" %>, password: <%= node['gitlab']['gitlab_rails']["smtp_password"]&.inspect || "secrets.password" %>, -<% %w{ address port domain enable_starttls_auto tls ssl openssl_verify_mode ca_path ca_file }.each do |key| %> +<% %w{ address port domain enable_starttls_auto tls ssl openssl_verify_mode ca_path ca_file open_timeout read_timeout }.each do |key| %> <% value = node['gitlab']['gitlab_rails']["smtp_#{key}"] %> <%= "#{key}: #{value.inspect}," unless value.nil? %> <% end %> diff --git a/spec/chef/cookbooks/gitlab/recipes/gitlab-rails_spec.rb b/spec/chef/cookbooks/gitlab/recipes/gitlab-rails_spec.rb index 45ab05a1d9c7514c12ed5aa5f2632f2c565b191b_c3BlYy9jaGVmL2Nvb2tib29rcy9naXRsYWIvcmVjaXBlcy9naXRsYWItcmFpbHNfc3BlYy5yYg==..692a4fed7629073320145e6ddfb57ea46dfa9eb8_c3BlYy9jaGVmL2Nvb2tib29rcy9naXRsYWIvcmVjaXBlcy9naXRsYWItcmFpbHNfc3BlYy5yYg== 100644 --- a/spec/chef/cookbooks/gitlab/recipes/gitlab-rails_spec.rb +++ b/spec/chef/cookbooks/gitlab/recipes/gitlab-rails_spec.rb @@ -1196,6 +1196,56 @@ end context 'SMTP settings' do + context 'defaults' do + before do + stub_gitlab_rb( + gitlab_rails: { + smtp_enable: true + } + ) + end + + it 'renders the default timeout values' do + expect(chef_run).to create_templatesymlink('Create a smtp_settings.rb and create a symlink to Rails root').with_variables( + hash_including( + 'smtp_open_timeout' => 30, + 'smtp_read_timeout' => 60 + ) + ) + + expect(chef_run).to render_file('/var/opt/gitlab/gitlab-rails/etc/smtp_settings.rb').with_content { |content| + expect(content).to include('open_timeout: 30') + expect(content).to include('read_timeout: 60') + } + end + end + + context 'when timeouts are set' do + before do + stub_gitlab_rb( + gitlab_rails: { + smtp_enable: true, + smtp_open_timeout: 10, + smtp_read_timeout: 20 + } + ) + end + + it 'renders the timeout values' do + expect(chef_run).to create_templatesymlink('Create a smtp_settings.rb and create a symlink to Rails root').with_variables( + hash_including( + 'smtp_open_timeout' => 10, + 'smtp_read_timeout' => 20 + ) + ) + + expect(chef_run).to render_file('/var/opt/gitlab/gitlab-rails/etc/smtp_settings.rb').with_content { |content| + expect(content).to include('open_timeout: 10') + expect(content).to include('read_timeout: 20') + } + end + end + context 'when connection pooling is not configured' do it 'creates smtp_settings.rb with pooling disabled' do stub_gitlab_rb(