Skip to content

Commit ef49507

Browse files
committed
[Security] Disable unused background services: wpa_supplicant and cups.
Signed-off-by: Giacomo Marciani <[email protected]>
1 parent a6f368a commit ef49507

File tree

5 files changed

+119
-22
lines changed

5 files changed

+119
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This file is used to list changes made in each version of the AWS ParallelCluste
77
------
88

99
**ENHANCEMENTS**
10+
- Disable unused background services wpa_supplicant and cups to improve security.
1011

1112
**CHANGES**
1213

cookbooks/aws-parallelcluster-platform/recipes/install/disable_services.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,13 @@
2727
service 'log4j-cve-2021-44228-hotpatch' do
2828
action %i(disable stop mask)
2929
end unless on_docker?
30+
31+
# Necessary on Ubuntu and Amazon Linux 2
32+
service 'cups' do
33+
action %i(disable stop mask)
34+
end unless on_docker?
35+
36+
# Necessary on Ubuntu 22
37+
service 'wpa_supplicant' do
38+
action %i(disable stop mask)
39+
end unless on_docker?

cookbooks/aws-parallelcluster-platform/spec/unit/recipes/disable_services_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818
is_expected.to stop_service('log4j-cve-2021-44228-hotpatch')
1919
is_expected.to mask_service('log4j-cve-2021-44228-hotpatch')
2020
end
21+
22+
it 'disables cups' do
23+
is_expected.to disable_service('cups')
24+
is_expected.to stop_service('cups')
25+
is_expected.to mask_service('cups')
26+
end
27+
28+
it 'disables wpa_supplicant' do
29+
is_expected.to disable_service('wpa_supplicant')
30+
is_expected.to stop_service('wpa_supplicant')
31+
is_expected.to mask_service('wpa_supplicant')
32+
end
2133
end
2234
end
2335
end

cookbooks/aws-parallelcluster-platform/test/controls/disable_services_spec.rb

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,46 @@
1010
# See the License for the specific language governing permissions and limitations under the License.
1111

1212
control 'tag:testami_tag:config_services_disabled_on_debian_family' do
13-
title 'Test that DLAMI multi eni helper is disabled and masked on debian family'
13+
services = %w(aws-ubuntu-eni-helper wpa_supplicant)
14+
15+
title "Test that #{services.join(',')} are disabled and masked on debian family"
1416

1517
only_if { os_properties.debian_family? && !os_properties.on_docker? }
1618

17-
describe service('aws-ubuntu-eni-helper') do
18-
it { should_not be_enabled }
19-
it { should_not be_running }
20-
end
19+
services.each do |service_name|
20+
describe service(service_name) do
21+
it { should_not be_enabled }
22+
it { should_not be_running }
23+
end
2124

22-
describe bash('systemctl list-unit-files --state=masked --no-legend') do
23-
its(:exit_status) { should eq 0 }
24-
its(:stdout) { should match /aws-ubuntu-eni-helper.service\s*masked/ }
25+
describe bash('systemctl list-unit-files --state=masked --no-legend') do
26+
its(:exit_status) { should eq 0 }
27+
its(:stdout) { should match /#{service_name}.service\s*masked/ }
28+
end
2529
end
2630
end
2731

2832
control 'tag:testami_tag:config_services_disabled_on_amazon_family' do
29-
title 'Test that log4j-cve-2021-44228-hotpatch is disabled and masked on amazon family'
33+
services = %w(log4j-cve-2021-44228-hotpatch cups)
3034

31-
only_if { os_properties.amazon_family? && !os_properties.on_docker? }
35+
title "Test that #{services.join(',')} are disabled and masked on amazon family"
3236

33-
describe service('log4j-cve-2021-44228-hotpatch') do
34-
it { should_not be_enabled }
35-
it { should_not be_running }
36-
end
37-
38-
describe bash('systemctl list-unit-files --state=masked --no-legend') do
39-
its(:exit_status) { should eq 0 }
40-
its(:stdout) { should match /log4j-cve-2021-44228-hotpatch.service\s*masked/ }
41-
end
37+
only_if { os_properties.amazon_family? && !os_properties.on_docker? }
4238

43-
describe bash('systemctl show -p LoadState log4j-cve-2021-44228-hotpatch') do
44-
its(:exit_status) { should eq 0 }
45-
its(:stdout) { should match /LoadState=masked/ }
39+
services.each do |service_name|
40+
describe service(service_name) do
41+
it { should_not be_enabled }
42+
it { should_not be_running }
43+
end
44+
45+
describe bash('systemctl list-unit-files --state=masked --no-legend') do
46+
its(:exit_status) { should eq 0 }
47+
its(:stdout) { should match /#{service_name}.service\s*masked/ }
48+
end
49+
50+
describe bash("systemctl show -p LoadState #{service_name}") do
51+
its(:exit_status) { should eq 0 }
52+
its(:stdout) { should match /LoadState=masked/ }
53+
end
4654
end
4755
end
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
require 'spec_helper'
2+
3+
describe 'aws-parallelcluster-slurm::config_head_node' do
4+
for_all_oses do |platform, version|
5+
context "on #{platform}#{version}" do
6+
cached(:chef_run) do
7+
runner = runner(platform: platform, version: version) do
8+
allow_any_instance_of(Object).to receive(:are_mount_or_unmount_required?).and_return(false)
9+
allow_any_instance_of(Object).to receive(:dig).and_return(true)
10+
RSpec::Mocks.configuration.allow_message_expectations_on_nil = true
11+
end
12+
runner.converge(described_recipe)
13+
end
14+
cached(:node) { chef_run.node }
15+
16+
it 'creates the slurmdbd configuration files' do
17+
slurm_install_dir = "#{node['cluster']['slurm']['install_dir']}"
18+
slurm_user = "#{node['cluster']['slurm']['user']}"
19+
slurm_group = "#{node['cluster']['slurm']['group']}"
20+
is_expected.to create_template_if_missing("#{slurm_install_dir}/etc/slurmdbd.conf").with(
21+
source: 'slurm/slurmdbd.conf.erb',
22+
user: slurm_user,
23+
group: slurm_group,
24+
mode: '0600'
25+
)
26+
is_expected.to create_file("#{slurm_install_dir}/etc/slurm_parallelcluster_slurmdbd.conf").with(
27+
user: slurm_user,
28+
group: slurm_group,
29+
mode: '0600'
30+
)
31+
end
32+
33+
it 'creates the Slurm database password update script' do
34+
is_expected.to create_template("#{node['cluster']['scripts_dir']}/slurm/update_slurm_database_password.sh").with(
35+
source: 'slurm/head_node/update_slurm_database_password.sh.erb',
36+
user: 'root',
37+
group: 'root',
38+
mode: '0700'
39+
)
40+
end
41+
42+
it 'executes the Slurm database password update scripts' do
43+
is_expected.to run_execute("update Slurm database password").with(
44+
command: "#{node['cluster']['scripts_dir']}/slurm/update_slurm_database_password.sh",
45+
user: "root",
46+
group: "root"
47+
)
48+
end
49+
50+
it 'starts the slurm database daemon' do
51+
is_expected.to enable_service("slurmdbd")
52+
is_expected.to start_service("slurmdbd")
53+
end
54+
55+
it "waits for the Slurm database to respond" do
56+
is_expected.to run_execute("wait for slurm database").with(
57+
command: "#{node['cluster']['slurm']['install_dir']}/bin/sacctmgr show clusters -Pn"
58+
)
59+
end
60+
61+
it "bootstraps the Slurm database idempotently" do
62+
is_expected.to run_bash("bootstrap slurm database")
63+
end
64+
end
65+
end
66+
end

0 commit comments

Comments
 (0)