Verify ufw Enabled

Classification:

compliance

Framework:

Control:

Description

The ufw service can be enabled with the following command:

$ sudo systemctl enable ufw.service

Rationale

The ufw service must be enabled and running in order for ufw to protect the system

Remediation

Shell script

The following script can be run on the host to remediate the issue.

# Remediation is applicable only in certain platforms
if [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ] && { ( [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ] && dpkg-query --show --showformat='${db:Status-Status}\n' 'ufw' 2>/dev/null | grep -q installed ); }; then

SYSTEMCTL\_EXEC='/usr/bin/systemctl'
"$SYSTEMCTL\_EXEC" unmask 'ufw.service'
"$SYSTEMCTL\_EXEC" start 'ufw.service'
"$SYSTEMCTL\_EXEC" enable 'ufw.service'

else
 >&2 echo 'Remediation is not applicable, nothing was done'
fi

Ansible playbook

The following playbook can be run with Ansible to remediate the issue.

- name: Gather the package facts
 package\_facts:
 manager: auto
 tags:
 - DISA-STIG-UBTU-20-010434
 - enable\_strategy
 - low\_complexity
 - low\_disruption
 - medium\_severity
 - no\_reboot\_needed
 - service\_ufw\_enabled

- name: Enable service ufw
 block:

 - name: Gather the package facts
 package\_facts:
 manager: auto

 - name: Enable service ufw
 systemd:
 name: ufw
 enabled: 'yes'
 state: started
 masked: 'no'
 when:
 - '"ufw" in ansible\_facts.packages'
 when:
 - ansible\_virtualization\_type not in ["docker", "lxc", "openvz", "podman", "container"]
 - ( ansible\_virtualization\_type not in ["docker", "lxc", "openvz", "podman", "container"]
 and "ufw" in ansible\_facts.packages )
 tags:
 - DISA-STIG-UBTU-20-010434
 - enable\_strategy
 - low\_complexity
 - low\_disruption
 - medium\_severity
 - no\_reboot\_needed
 - service\_ufw\_enabled