Skip to content

Commit fbb7aa6

Browse files
balasankarcWill Chandler
andcommitted
Merge branch 'wc/shell-token-restart' into 'master'
Restart Gitaly when updating Gitlab-Shell token See merge request https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/7297 Merged-by: Balasankar 'Balu' C <[email protected]> Approved-by: Jason Plum <[email protected]> Approved-by: Balasankar 'Balu' C <[email protected]> Co-authored-by: Will Chandler <[email protected]>
2 parents 67c7676 + 70c0a0e commit fbb7aa6

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,10 @@
410410
gitlab_workhorse_services.each { |svc| notifies :restart, svc }
411411
end
412412

413+
gitlab_shell_secret_services = dependent_services
414+
gitlab_shell_secret_services += ['runit_service[gitaly]'] if omnibus_helper.should_notify?('gitaly')
415+
gitlab_shell_secret_services += ['runit_service[gitlab-sshd]'] if Services.enabled?('gitlab_sshd')
416+
413417
templatesymlink "Create a gitlab_shell_secret and create a symlink to Rails root" do
414418
link_from File.join(gitlab_rails_source_dir, ".gitlab_shell_secret")
415419
link_to File.join(gitlab_rails_etc_dir, "gitlab_shell_secret")
@@ -419,7 +423,7 @@
419423
mode "0644"
420424
sensitive true
421425
variables(secret_token: node['gitlab']['gitlab_shell']['secret_token'])
422-
dependent_services.each { |svc| notifies :restart, svc }
426+
gitlab_shell_secret_services.each { |svc| notifies :restart, svc }
423427
notifies :run, 'bash[Set proper security context on ssh files for selinux]', :delayed if SELinuxHelper.enabled?
424428
end
425429

spec/chef/cookbooks/gitlab/recipes/gitlab-rails_spec.rb

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,93 @@
11411141
end
11421142
end
11431143

1144+
describe 'gitlab_shell_secret' do
1145+
let(:templatesymlink) { chef_run.templatesymlink('Create a gitlab_shell_secret and create a symlink to Rails root') }
1146+
1147+
context 'by default' do
1148+
cached(:chef_run) do
1149+
ChefSpec::SoloRunner.new.converge('gitlab::default')
1150+
end
1151+
1152+
it 'creates the template' do
1153+
expect(chef_run).to create_templatesymlink("Create a gitlab_pages_secret and create a symlink to Rails root").with(
1154+
owner: 'root',
1155+
group: 'root',
1156+
mode: '0644'
1157+
)
1158+
end
1159+
1160+
it 'template triggers notifications' do
1161+
expect(templatesymlink).to notify('runit_service[gitaly]').to(:restart).delayed
1162+
expect(templatesymlink).to notify('runit_service[puma]').to(:restart).delayed
1163+
expect(templatesymlink).to notify('sidekiq_service[sidekiq]').to(:restart).delayed
1164+
end
1165+
end
1166+
1167+
context 'with gitlab-sshd enabled' do
1168+
let(:templatesymlink) { chef_run.templatesymlink('Create a gitlab_shell_secret and create a symlink to Rails root') }
1169+
1170+
cached(:chef_run) do
1171+
RSpec::Mocks.with_temporary_scope do
1172+
stub_gitlab_rb(
1173+
gitlab_sshd: { enable: true }
1174+
)
1175+
end
1176+
1177+
ChefSpec::SoloRunner.new.converge('gitlab::default')
1178+
end
1179+
1180+
it 'creates the template' do
1181+
expect(chef_run).to create_templatesymlink("Create a gitlab_pages_secret and create a symlink to Rails root").with(
1182+
owner: 'root',
1183+
group: 'root',
1184+
mode: '0644'
1185+
)
1186+
end
1187+
1188+
it 'template triggers notifications' do
1189+
expect(templatesymlink).to notify('runit_service[gitlab-sshd]').to(:restart).delayed
1190+
expect(templatesymlink).to notify('runit_service[gitaly]').to(:restart).delayed
1191+
expect(templatesymlink).to notify('runit_service[puma]').to(:restart).delayed
1192+
expect(templatesymlink).to notify('sidekiq_service[sidekiq]').to(:restart).delayed
1193+
end
1194+
end
1195+
1196+
context 'with specific gitlab_shell_secret' do
1197+
let(:gitlab_shell_secret_token) { SecureRandom.base64(32) }
1198+
1199+
cached(:chef_run) do
1200+
RSpec::Mocks.with_temporary_scope do
1201+
stub_gitlab_rb(
1202+
gitlab_shell: { secret_token: gitlab_shell_secret_token }
1203+
)
1204+
end
1205+
1206+
ChefSpec::SoloRunner.new.converge('gitlab::default')
1207+
end
1208+
1209+
it 'renders the correct node attribute' do
1210+
expect(chef_run).to create_templatesymlink("Create a gitlab_shell_secret and create a symlink to Rails root").with_variables(
1211+
secret_token: gitlab_shell_secret_token
1212+
)
1213+
end
1214+
1215+
it 'uses the correct owner and permissions' do
1216+
expect(chef_run).to create_templatesymlink('Create a gitlab_shell_secret and create a symlink to Rails root').with(
1217+
owner: 'root',
1218+
group: 'root',
1219+
mode: '0644'
1220+
)
1221+
end
1222+
1223+
it 'template triggers notifications' do
1224+
expect(templatesymlink).to notify('runit_service[gitaly]').to(:restart).delayed
1225+
expect(templatesymlink).to notify('runit_service[puma]').to(:restart).delayed
1226+
expect(templatesymlink).to notify('sidekiq_service[sidekiq]').to(:restart).delayed
1227+
end
1228+
end
1229+
end
1230+
11441231
describe 'gitlab_pages_secret' do
11451232
let(:templatesymlink) { chef_run.templatesymlink('Create a gitlab_pages_secret and create a symlink to Rails root') }
11461233

0 commit comments

Comments
 (0)