Skip to content

Commit 3681cae

Browse files
authored
Merge pull request ComplianceAsCode#6298 from ggbecker/mask-services-fix
Remove the option to enable/disable "mask" a service
2 parents 35e7cba + 965de99 commit 3681cae

12 files changed

+11
-63
lines changed

docs/manual/developer_guide.adoc

-1
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,6 @@ service_disabled::
17101710
** *servicename* - name of the service.
17111711
** *packagename* - name of the package that provides this service. This argument is optional. If *packagename* is not specified it means the name of the package is the same as the name of service.
17121712
** *daemonname* - name of the daemon. This argument is optional. If *daemonname* is not specified it means the name of the daemon is the same as the name of service.
1713-
** *mask_service* - Check if the service should be masked to prevent it from running. This argument is optional. Implicit value is "true".
17141713
* Languages: Ansible, Bash, OVAL, Puppet, Ignition, Kubernetes
17151714

17161715
service_enabled::

linux_os/guide/system/accounts/accounts-physical/disable_ctrlaltdel_reboot/ansible/shared.yml

+1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
systemd:
99
name: ctrl-alt-del.target
1010
masked: yes
11+
state: stopped
1112

linux_os/guide/system/accounts/accounts-physical/disable_ctrlaltdel_reboot/bash/shared.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# The process to disable ctrl+alt+del has changed in RHEL7.
55
# Reference: https://access.redhat.com/solutions/1123873
66
{{% endif %}}
7-
systemctl mask ctrl-alt-del.target
7+
systemctl mask --now ctrl-alt-del.target
88
{{%- else -%}}
99
# If system does not contain control-alt-delete.override,
1010
if [ ! -f /etc/init/control-alt-delete.override ]; then
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
22
# platform = Red Hat Enterprise Linux 7,Red Hat Enterprise Linux 8,multi_platform_fedora
33

4-
systemctl mask ctrl-alt-del.target
4+
systemctl mask --now ctrl-alt-del.target

shared/macros.jinja

+4-8
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ ocil_clause: "no line is returned"
256256
If the socket is not running the command will return the following output:
257257
<pre>inactive</pre>
258258

259-
By default the socket will also be masked, to check that the <code>{{{ socket }}}</code> is masked, run the following command:
259+
The socket will also be masked, to check that the <code>{{{ socket }}}</code> is masked, run the following command:
260260
<pre>$ systemctl show <code>{{{ socket }}}</code> | grep "LoadState\|UnitFileState"</pre>
261261

262262
If the socket is masked the command will return the following outputs:
@@ -333,7 +333,7 @@ ocil_clause: "the package is installed"
333333
If the service is not running the command will return the following output:
334334
<pre>inactive</pre>
335335

336-
By default the service will also be masked, to check that the <code>{{{ service }}}</code> is masked, run the following command:
336+
The service will also be masked, to check that the <code>{{{ service }}}</code> is masked, run the following command:
337337
<pre>$ systemctl show <code>{{{ service }}}</code> | grep "LoadState\|UnitFileState"</pre>
338338

339339
If the service is masked the command will return the following outputs:
@@ -379,9 +379,7 @@ ocil_clause: "the package is installed"
379379

380380
{{%- macro systemd_describe_socket_disable(socket) %}}
381381
The <code>{{{ socket }}}</code> socket can be disabled with the following command:
382-
<pre>$ sudo systemctl disable {{{ socket }}}.socket</pre>
383-
The <code>{{{ socket }}}</code> socket can be masked with the following command:
384-
<pre>$ sudo systemctl mask {{{ service }}}.socket</pre>
382+
<pre>$ sudo systemctl mask --now {{{ socket }}}.socket</pre>
385383
{{%- endmacro %}}
386384

387385

@@ -401,9 +399,7 @@ ocil_clause: "the package is installed"
401399

402400
{{%- macro systemd_describe_service_disable(service) %}}
403401
The <code>{{{ service }}}</code> service can be disabled with the following command:
404-
<pre>$ sudo systemctl disable {{{ service }}}.service</pre>
405-
The <code>{{{ service }}}</code> service can be masked with the following command:
406-
<pre>$ sudo systemctl mask {{{ service }}}.service</pre>
402+
<pre>$ sudo systemctl mask --now {{{ service }}}.service</pre>
407403
{{%- endmacro %}}
408404

409405

shared/templates/template_ANSIBLE_service_disabled

-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
name: "{{{ DAEMONNAME }}}.service"
1515
enabled: "no"
1616
state: "stopped"
17-
{{%- if MASK_SERVICE %}}
1817
masked: "yes"
19-
{{%- endif %}}
2018
when: '"{{{ DAEMONNAME }}}.service" in ansible_facts.services'
2119

2220
- name: "Unit Socket Exists - {{{ DAEMONNAME }}}.socket"
@@ -33,9 +31,7 @@
3331
name: "{{{ DAEMONNAME }}}.socket"
3432
enabled: "no"
3533
state: "stopped"
36-
{{%- if MASK_SERVICE %}}
3734
masked: "yes"
38-
{{%- endif %}}
3935
when: '"{{{ DAEMONNAME }}}.socket" in socket_file_exists.stdout_lines[1]'
4036
{{% elif init_system == "upstart" %}}
4137
- name: Stop {{{ SERVICENAME }}}

shared/templates/template_BASH_service_disabled

-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ SYSTEMCTL_EXEC='/usr/bin/systemctl'
1515
# Disable socket activation if we have a unit file for it
1616
if "$SYSTEMCTL_EXEC" list-unit-files | grep -q '^{{{ DAEMONNAME }}}.socket'; then
1717
"$SYSTEMCTL_EXEC" stop '{{{ DAEMONNAME }}}.socket'
18-
"$SYSTEMCTL_EXEC" disable '{{{ DAEMONNAME }}}.socket'
19-
{{%- if MASK_SERVICE %}}
2018
"$SYSTEMCTL_EXEC" mask '{{{ DAEMONNAME }}}.socket'
21-
{{%- endif %}}
2219
fi
2320
# The service may not be running because it has been started and failed,
2421
# so let's reset the state so OVAL checks pass.

shared/templates/template_IGNITION_service_disabled

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ spec:
1313
units:
1414
- name: {{{ DAEMONNAME }}}.service
1515
enabled: false
16-
{{%- if MASK_SERVICE %}}
1716
mask: true
18-
{{%- endif %}}
17+
state: stopped
1918
- name: {{{ DAEMONNAME }}}.socket
2019
enabled: false
21-
{{%- if MASK_SERVICE %}}
2220
mask: true
23-
{{%- endif %}}
21+
state: stopped

shared/templates/template_KUBERNETES_service_disabled

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ spec:
1313
units:
1414
- name: {{{ DAEMONNAME }}}.service
1515
enabled: false
16-
{{%- if MASK_SERVICE %}}
1716
mask: true
18-
{{%- endif %}}
17+
state: stopped
1918
- name: {{{ DAEMONNAME }}}.socket
2019
enabled: false
21-
{{%- if MASK_SERVICE %}}
2220
mask: true
23-
{{%- endif %}}
21+
state: stopped

shared/templates/template_OVAL_service_disabled

-30
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,12 @@
1212
<criterion comment="{{{ PACKAGENAME }}} removed" test_ref="{{{ package_removed_test_id }}}" />
1313
<criteria operator="AND" comment="service {{{ SERVICENAME }}} is not configured to start">
1414
<criterion comment="{{{ SERVICENAME }}} is not running" test_ref="test_service_not_running_{{{ SERVICENAME }}}" />
15-
{{%- if MASK_SERVICE %}}
1615
<criterion comment="Property LoadState of service {{{ SERVICENAME }}} is masked" test_ref="test_service_loadstate_is_masked_{{{ SERVICENAME }}}" />
1716
<criterion comment="Property FragmentPath of service {{{ SERVICENAME }}} is set to /dev/null" test_ref="test_service_fragmentpath_is_dev_null_{{{ SERVICENAME }}}" />
18-
{{%- else %}}
19-
<criterion comment="{{{ SERVICENAME }}} not wanted by multi-user.target" test_ref="test_{{{ SERVICENAME }}}_not_wanted_by_multi_user_target" />
20-
<criterion comment="{{{ SERVICENAME }}} socket not wanted by multi-user.target" test_ref="test_{{{ SERVICENAME }}}_socket_not_wanted_by_multi_user_target" />
21-
{{%- endif %}}
2217
</criteria>
2318
</criteria>
2419
</definition>
2520

26-
<linux:systemdunitdependency_test check="all" check_existence="any_exist" comment="systemd test" id="test_{{{ SERVICENAME }}}_not_wanted_by_multi_user_target" version="1">
27-
<linux:object object_ref="object_multi_user_target_for_{{{ SERVICENAME }}}_disabled" />
28-
<linux:state state_ref="state_systemd_{{{ SERVICENAME }}}_off"/>
29-
</linux:systemdunitdependency_test>
30-
<linux:systemdunitdependency_object id="object_multi_user_target_for_{{{ SERVICENAME }}}_disabled" comment="list of dependencies of multi-user.target" version="1">
31-
<linux:unit>multi-user.target</linux:unit>
32-
</linux:systemdunitdependency_object>
33-
<linux:systemdunitdependency_state id="state_systemd_{{{ SERVICENAME }}}_off" comment="{{{ SERVICENAME }}} service is not listed in the dependencies" version="1">
34-
<linux:dependency entity_check="none satisfy">{{{ SERVICENAME }}}.service</linux:dependency>
35-
</linux:systemdunitdependency_state>
36-
37-
<linux:systemdunitdependency_test check="all" check_existence="any_exist" comment="systemd test" id="test_{{{ SERVICENAME }}}_socket_not_wanted_by_multi_user_target" version="1">
38-
<linux:object object_ref="object_multi_user_target_for_{{{ SERVICENAME }}}_socket_disabled" />
39-
<linux:state state_ref="state_systemd_{{{ SERVICENAME }}}_socket_off"/>
40-
</linux:systemdunitdependency_test>
41-
<linux:systemdunitdependency_object id="object_multi_user_target_for_{{{ SERVICENAME }}}_socket_disabled" comment="list of dependencies of multi-user.target" version="1">
42-
<linux:unit>multi-user.target</linux:unit>
43-
</linux:systemdunitdependency_object>
44-
<linux:systemdunitdependency_state id="state_systemd_{{{ SERVICENAME }}}_socket_off" comment="{{{ SERVICENAME }}} socket is not listed in the dependencies" version="1">
45-
<linux:dependency entity_check="none satisfy">{{{ SERVICENAME }}}.socket</linux:dependency>
46-
</linux:systemdunitdependency_state>
47-
4821
<linux:systemdunitproperty_test id="test_service_not_running_{{{ SERVICENAME }}}" check="all" check_existence="any_exist" comment="Test that the {{{ SERVICENAME }}} service is not running" version="1">
4922
<linux:object object_ref="obj_service_not_running_{{{ SERVICENAME }}}"/>
5023
<linux:state state_ref="state_service_not_running_{{{ SERVICENAME }}}"/>
@@ -56,7 +29,6 @@
5629
<linux:systemdunitproperty_state id="state_service_not_running_{{{ SERVICENAME }}}" version="1" comment="{{{ SERVICENAME }}} is not running">
5730
<linux:value>inactive</linux:value>
5831
</linux:systemdunitproperty_state>
59-
{{%- if MASK_SERVICE %}}
6032
<linux:systemdunitproperty_test id="test_service_loadstate_is_masked_{{{ SERVICENAME }}}" check="all" check_existence="any_exist" comment="Test that the property LoadState from the service {{{ SERVICENAME }}} is masked" version="1">
6133
<linux:object object_ref="obj_service_loadstate_is_masked_{{{ SERVICENAME }}}"/>
6234
<linux:state state_ref="state_service_loadstate_is_masked_{{{ SERVICENAME }}}"/>
@@ -80,8 +52,6 @@
8052
<linux:systemdunitproperty_state id="state_service_fragmentpath_is_dev_null_{{{ SERVICENAME }}}" version="1" comment="FragmentPath is set to /dev/null">
8153
<linux:value>/dev/null</linux:value>
8254
</linux:systemdunitproperty_state>
83-
{{%- endif %}}
84-
8555

8656
{{% else %}}
8757

ssg/templates.py

-2
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,6 @@ def service_disabled(data, lang):
301301
data["packagename"] = data["servicename"]
302302
if "daemonname" not in data:
303303
data["daemonname"] = data["servicename"]
304-
if "mask_service" not in data:
305-
data["mask_service"] = "true"
306304
return data
307305

308306

utils/migrate_template_csv_to_rule.py

-5
Original file line numberDiff line numberDiff line change
@@ -505,17 +505,12 @@ def services_disabled_csv_to_dict(csv_line, csv_data):
505505
service_name = csv_line[0]
506506
package_name = csv_line[1]
507507
daemon_name = csv_line[2]
508-
mask_service = "true"
509-
if len(csv_line) == 4:
510-
mask_service = csv_line[3]
511508

512509
rule_id = f"service_{service_name}_disabled"
513510

514511
data_service_disabled["servicename"] = service_name
515512
data_service_disabled["packagename"] = package_name
516513
data_service_disabled["daemonname"] = daemon_name
517-
if not mask_service:
518-
data_service_disabled["mask_service"] = mask_service
519514
service_disabled["vars"] = data_service_disabled
520515

521516
csv_data[rule_id] = service_disabled

0 commit comments

Comments
 (0)