Skip to content

Commit 5d3231d

Browse files
twk3balasankarc
andcommitted
Merge branch '4181-ssl-password-file' into 'master'
Support specifying ssl_password_file for nginx Closes #4181 See merge request https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/6367 Merged-by: DJ Mountney <[email protected]> Approved-by: Jason Young <[email protected]> Approved-by: DJ Mountney <[email protected]> Co-authored-by: Balasankar "Balu" C <[email protected]>
2 parents c5fd238 + 47996b1 commit 5d3231d

File tree

9 files changed

+68
-3
lines changed

9 files changed

+68
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ spec/examples.txt
3838
.projections.json
3939

4040
coverage/
41+
42+
junit_rspec.xml

doc/settings/ssl.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,12 @@ To enable HTTPS:
221221
the password when you reconfigure GitLab. In that case, Omnibus GitLab
222222
fails silently with no error messages.
223223

224-
To remove the password from the key:
224+
To specify the password for the key file, store the password in a text file
225+
(for example, `/etc/gitlab/ssl/key_file_password.txt`) and add the following
226+
to `/etc/gitlab/gitlab.rb`:
225227

226-
```shell
227-
openssl rsa -in certificate_before.key -out certificate_after.key
228+
```ruby
229+
nginx['ssl_password_file'] = '/etc/gitlab/ssl/key_file_password.txt'
228230
```
229231

230232
1. Reconfigure GitLab:

files/gitlab-config-template/gitlab.rb.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,7 @@ external_url 'GENERATED_EXTERNAL_URL'
14361436
# nginx['ssl_session_timeout'] = "1d"
14371437

14381438
# nginx['ssl_dhparam'] = nil # Path to dhparams.pem, eg. /etc/gitlab/ssl/dhparams.pem
1439+
# nginx['ssl_password_file'] = nil # Path to file with passphrases for ssl certificate secret keys
14391440
# nginx['listen_addresses'] = ['*', '[::]']
14401441

14411442
##! **Defaults to forcing web browsers to always communicate using only HTTPS**

files/gitlab-cookbooks/gitlab/attributes/default.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@
711711
default['gitlab']['nginx']['ssl_session_tickets'] = "off"
712712
default['gitlab']['nginx']['ssl_session_timeout'] = "1d" # settings from by https://ssl-config.mozilla.org/#server=nginx&version=1.17.7&config=intermediate&openssl=1.1.1d&ocsp=false&guideline=5.6
713713
default['gitlab']['nginx']['ssl_dhparam'] = nil # Path to dhparam.pem
714+
default['gitlab']['nginx']['ssl_password_file'] = nil
714715
default['gitlab']['nginx']['listen_addresses'] = ['*']
715716
default['gitlab']['nginx']['listen_port'] = nil # override only if you have a reverse proxy
716717
default['gitlab']['nginx']['listen_https'] = nil # override only if your reverse proxy internally communicates over HTTP

files/gitlab-cookbooks/gitlab/templates/default/nginx-gitlab-http.conf.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ server { ## HTTPS server
9898
<% if @ssl_dhparam %>
9999
ssl_dhparam <%= @ssl_dhparam %>;
100100
<% end %>
101+
102+
<% if @ssl_password_file %>
103+
ssl_password_file '<%= @ssl_password_file %>';
104+
<% end %>
101105
<% end %>
102106

103107
## Real IP Module Config

files/gitlab-cookbooks/gitlab/templates/default/nginx-gitlab-mattermost-http.conf.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ server { ## HTTPS server
5959
<% if @ssl_dhparam %>
6060
ssl_dhparam <%= @ssl_dhparam %>;
6161
<% end %>
62+
63+
<% if @ssl_password_file %>
64+
ssl_password_file '<%= @ssl_password_file %>';
65+
<% end %>
6266
<% end %>
6367

6468
## Real IP Module Config

files/gitlab-cookbooks/gitlab/templates/default/nginx-gitlab-pages-http.conf.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ server {
5757
<% if @ssl_dhparam %>
5858
ssl_dhparam <%= @ssl_dhparam %>;
5959
<% end %>
60+
61+
<% if @ssl_password_file %>
62+
ssl_password_file '<%= @ssl_password_file %>';
63+
<% end %>
6064
<% end %>
6165

6266
## Real IP Module Config

files/gitlab-cookbooks/gitlab/templates/default/nginx-gitlab-registry-http.conf.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ server { ## HTTPS server
7171
<% if @ssl_dhparam %>
7272
ssl_dhparam <%= @ssl_dhparam %>;
7373
<% end %>
74+
75+
<% if @ssl_password_file %>
76+
ssl_password_file '<%= @ssl_password_file %>';
77+
<% end %>
7478
<% end %>
7579

7680
## Real IP Module Config

spec/chef/cookbooks/gitlab/recipes/nginx_spec.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,49 @@
307307
expect(content).to include("ssl_verify_depth 7")
308308
}
309309
end
310+
311+
describe 'ssl_password_file' do
312+
context 'by default' do
313+
it 'does not set ssl_password_file' do
314+
http_conf.each_value do |conf|
315+
expect(chef_run).to render_file(conf).with_content { |content|
316+
expect(content).not_to include("ssl_password_file")
317+
}
318+
end
319+
end
320+
end
321+
322+
context 'when explicitly specified' do
323+
before do
324+
stub_gitlab_rb(
325+
external_url: 'https://localhost',
326+
mattermost_external_url: 'https://mattermost.localhost',
327+
registry_external_url: 'https://registry.localhost',
328+
pages_external_url: 'https://pages.localhost',
329+
nginx: {
330+
ssl_password_file: '/etc/gitlab/ssl/gitlab_password_file.txt'
331+
},
332+
mattermost_nginx: {
333+
ssl_password_file: '/etc/gitlab/ssl/mattermost_password_file.txt'
334+
},
335+
pages_nginx: {
336+
ssl_password_file: '/etc/gitlab/ssl/pages_password_file.txt'
337+
},
338+
registry_nginx: {
339+
ssl_password_file: '/etc/gitlab/ssl/registry_password_file.txt'
340+
}
341+
)
342+
end
343+
344+
it "sets ssl_password_file correctly in nginx config" do
345+
http_conf.each do |service, conf|
346+
expect(chef_run).to render_file(conf).with_content { |content|
347+
expect(content).to include("ssl_password_file '/etc/gitlab/ssl/#{service}_password_file.txt';")
348+
}
349+
end
350+
end
351+
end
352+
end
310353
end
311354

312355
context 'when is enabled' do

0 commit comments

Comments
 (0)