Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firewall technology related rules per service and package change logic according to interactive profile variable #11818

Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b49f4ce
Add oval macro to check external variable vs expected value
teacup-on-rockingchair Apr 14, 2024
660e7f8
Add variable to set default firewall technology used
teacup-on-rockingchair Apr 14, 2024
dc4a098
Set relevant values for SLE platforms
teacup-on-rockingchair Apr 14, 2024
64885fd
Templates for pkg installed/removed and svc enabled/disabled, guarded…
teacup-on-rockingchair Apr 14, 2024
9aa0beb
Enable nftable service on SLE only if active firewall technology is s…
teacup-on-rockingchair Apr 14, 2024
22ac8fd
Disable nftable service on SLE only if active firewall technology is …
teacup-on-rockingchair Apr 14, 2024
99243ab
Removing nftable package on SLE makes sense only if active firewall t…
teacup-on-rockingchair Apr 14, 2024
3a65275
Installing iptables package on SLE only if active firewall technology…
teacup-on-rockingchair Apr 14, 2024
93fc615
Enable iptables service on SLE only if active firewall technology is …
teacup-on-rockingchair Apr 14, 2024
53f09ca
Disable firewalld service on SLE only if active firewall technology i…
teacup-on-rockingchair Apr 14, 2024
55fd107
Removing package on SLE makes sense only if active firewall technolo…
teacup-on-rockingchair Apr 14, 2024
67b3616
Enable firewalld service on SLE only if active firewall technology is…
teacup-on-rockingchair Apr 14, 2024
7df2ff6
Installing firewalld package on SLE only if active firewall technolog…
teacup-on-rockingchair Apr 14, 2024
75126ba
Fix bash template to produce shellcheck compliant code
teacup-on-rockingchair Apr 14, 2024
e8ef4d7
Package removed template guarded is with inverted logic
teacup-on-rockingchair Apr 15, 2024
6ae92ca
Invert the logic for variable dependency for service disabled rules
teacup-on-rockingchair Apr 18, 2024
8f0fdfe
Replace machine with more relevant system_with_kernel platform
teacup-on-rockingchair Dec 12, 2024
55f0f79
Update shared/templates/package_removed_guard_var/ansible.template
teacup-on-rockingchair Jan 21, 2025
b7a296e
Update shared/templates/service_enabled_guard_var/ansible.template
teacup-on-rockingchair Jan 21, 2025
b96d658
Update shared/templates/package_installed_guard_var/ansible.template
teacup-on-rockingchair Jan 21, 2025
440dd03
Simplify template removing obsolete oval < 5.11 version support
teacup-on-rockingchair Dec 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,20 @@ fixtext: |-

{{{ package_install("firewalld") }}}

{{%- if product in [ "sle12", "sle15" ] %}}
template:
name: package_installed_guard_var
vars:
pkgname: firewalld
variable: var_network_filtering_service
value: firewalld
{{%- else %}}
template:
name: package_installed
vars:
pkgname: firewalld
{{%- endif %}}


srg_requirement:
{{{ full_name }}} must have the firewalld package installed.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,17 @@ fixtext: |-

srg_requirement: '{{{ srg_requirement_service_enabled("firewalld") }}}'

{{%- if product in [ "sle12", "sle15" ] %}}
template:
name: service_enabled_guard_var
vars:
packagename: firewalld
servicename: firewalld
variable: var_network_filtering_service
value: firewalld
{{%- else %}}
template:
name: service_enabled
vars:
servicename: firewalld
{{%- endif %}}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,16 @@ references:

fixtext: '{{{ fixtext_package_removed("firewalld") }}}'

{{%- if product in [ "sle12", "sle15" ] %}}
template:
name: package_removed_guard_var
vars:
pkgname: firewalld
variable: var_network_filtering_service
value: firewalld
{{%- else %}}
template:
name: package_removed
vars:
pkgname: firewalld
{{%- endif %}}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,18 @@ fixtext: '{{{ fixtext_service_disabled("firewalld") }}}'

srg_requirement: '{{{ srg_requirement_service_disabled("firewalld") }}}'

{{%- if product in [ "sle12", "sle15" ] %}}
template:
name: service_disabled_guard_var
vars:
packagename: firewalld
servicename: firewalld
variable: var_network_filtering_service
value: firewalld
{{%- else %}}
template:
name: service_disabled
vars:
servicename: firewalld
packagename: firewalld
{{%- endif %}}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,18 @@ ocil: |-
<br /><br />
{{{ ocil_service_enabled(service="ip6tables") }}}
{{%- if product in [ "sle12", "sle15" ] %}}
template:
name: service_enabled_guard_var
vars:
packagename: iptables
servicename: iptables
variable: var_network_filtering_service
value: iptables
{{%- else %}}
template:
name: service_enabled
vars:
servicename: ip6tables
packagename: iptables-ipv6
{{%- endif %}}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,22 @@ references:
nist: AC-4,CM-7(b),CA-3(5),SC-7(21),CM-6(a)
nist-csf: DE.AE-1,ID.AM-3,PR.AC-5,PR.DS-5,PR.IP-1,PR.PT-3,PR.PT-4

platform: system_with_kernel and package[iptables] and service_disabled[firewalld]
platform: machine and package[iptables] and service_disabled[firewalld]
Mab879 marked this conversation as resolved.
Show resolved Hide resolved

ocil: |-
{{{ ocil_service_enabled(service="iptables") }}}

{{%- if product in [ "sle12", "sle15" ] %}}
template:
name: service_enabled_guard_var
vars:
packagename: ip6tables
servicename: iptables-ipv6
variable: var_network_filtering_service
value: iptables
{{%- else %}}
template:
name: service_enabled
vars:
servicename: iptables
{{%- endif %}}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ ocil_clause: 'the package is not installed'

ocil: '{{{ ocil_package(package="iptables") }}}'

{{%- if product in [ "sle12", "sle15" ] %}}
template:
name: package_installed_guard_var
vars:
pkgname: iptables
variable: var_network_filtering_service
value: iptables
{{%- else %}}
template:
name: package_installed
vars:
pkgname: iptables
{{%- endif %}}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,17 @@ references:

fixtext: '{{{ fixtext_package_removed("nftables") }}}'

{{%- if product in [ "sle12", "sle15" ] %}}
template:
name: package_removed_guard_var
vars:
pkgname: nftables
variable: var_network_filtering_service
value: firewalld|nftables
operation: pattern match
{{%- else %}}
template:
name: package_removed
vars:
pkgname: nftables
{{%- endif %}}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,18 @@ fixtext: '{{{ fixtext_service_disabled("nftables") }}}'

platform: system_with_kernel and package[nftables] and package[firewalld]

{{%- if product in [ "sle12", "sle15" ] %}}
template:
name: service_disabled_guard_var
vars:
packagename: nftables
servicename: nftables
variable: var_network_filtering_service
value: nftables
{{%- else %}}
template:
name: service_disabled
vars:
servicename: nftables
packagename: nftables
{{%- endif %}}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,21 @@ ocil: |-
fixtext: |-
{{{ fixtext_service_enabled("nftables") }}}

platform: system_with_kernel and package[nftables] and service_disabled[firewalld]

platform: machine and package[nftables] and service_disabled[firewalld]
Mab879 marked this conversation as resolved.
Show resolved Hide resolved


{{%- if product in [ "sle12", "sle15" ] %}}
template:
name: service_enabled_guard_var
vars:
packagename: nftables
servicename: nftables
variable: var_network_filtering_service
value: nftables
{{%- else %}}
template:
name: service_enabled
vars:
servicename: nftables
{{%- endif %}}
19 changes: 19 additions & 0 deletions linux_os/guide/system/network/var_network_filtering_service.var
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
documentation_complete: true

title: 'Network filtering service'

description: |-
Network filtering service: iptables, nftables, firewalld or ufw

type: string

operator: equals

interactive: true

options:
iptables: iptables
nftables: nftables
firewalld: firewalld
ufw: ufw
default: firewalld
1 change: 1 addition & 0 deletions products/sle12/profiles/default.profile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ description: |-
is to keep a rule in the product's XCCDF Benchmark.

selections:
- var_network_filtering_service=iptables
- accounts_user_dot_user_ownership
- service_timesyncd_enabled
- gnome_gdm_disable_xdmcp
Expand Down
1 change: 1 addition & 0 deletions products/sle15/profiles/cis.profile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ description: |-

selections:
- cis_sle15:all:l2_server
- var_network_filtering_service=firewalld
# Exclude from CIS profile all rules related to ntp and timesyncd and keep only
# rules related to chrony
- '!ntpd_configure_restrictions'
Expand Down
1 change: 1 addition & 0 deletions products/sle15/profiles/default.profile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ description: |-
is to keep a rule in the product's XCCDF Benchmark.

selections:
- var_network_filtering_service=firewalld
- accounts_user_dot_user_ownership
- service_timesyncd_enabled
- gnome_gdm_disable_xdmcp
Expand Down
28 changes: 28 additions & 0 deletions shared/macros/10-oval.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -1760,3 +1760,31 @@ The macros generates the OVAL test including the dependent OVAL object and OVAL

</def-group>
{{%- endmacro -%}}

{{#
Macro to check if external variable is set to value
:param variable: Name of the external variable to check
:type variable: str
:param value: Value of the external variable
:type value: str
:param test_id: Suffix of the Ids in test, obj, and state elements
:type test_id: str
:param operation: Value operation
:type operation: str
#}}
{{%- macro oval_test_external_variable_value(variable,value,test_id='',operation='equals') -%}}
<ind:variable_test id="{{{ test_id }}}"
comment="Check external {{{ variable }}} is set to {{{ value }}}" check="all" version="1">
<ind:object object_ref="obj_{{{ test_id }}}"/>
<ind:state state_ref="ste_{{{ test_id }}}" />
</ind:variable_test>

<ind:variable_object id="obj_{{{ test_id }}}" version="1">
<ind:var_ref>{{{ variable }}}</ind:var_ref>
</ind:variable_object>
<ind:variable_state id="ste_{{{ test_id }}}" version="1">
<ind:value operation="{{{ operation }}}" datatype="string">{{{ value }}}</ind:value>
</ind:variable_state>

<external_variable comment="External variable {{{ variable }}}" datatype="string" id="{{{ variable }}}" version="1" />
{{%- endmacro -%}}
17 changes: 17 additions & 0 deletions shared/templates/package_installed_guard_var/ansible.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# platform = multi_platform_sle
# reboot = false
# strategy = enable
# complexity = low
# disruption = low

{{{ ansible_instantiate_variables(VARIABLE) }}}

- name: Ensure {{{ PKGNAME }}} is installed
package:
teacup-on-rockingchair marked this conversation as resolved.
Show resolved Hide resolved
name: "{{{ PKGNAME }}}"
state: present
{{% if OPERATION == "pattern match" %}}
when: {{{ VARIABLE }}} is regex("{{{ VALUE }}}")
{{% else %}}
when: {{{ VARIABLE }}} == "{{{ VALUE }}}"
{{% endif %}}
17 changes: 17 additions & 0 deletions shared/templates/package_installed_guard_var/bash.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# platform = multi_platform_sle
# reboot = false
# strategy = enable
# complexity = low
# disruption = low

{{{ bash_instantiate_variables(VARIABLE) }}}

{{% if OPERATION == "pattern match" %}}
if [[ "{{{ VALUE }}}" =~ ${{{ VARIABLE }}} ]]; then
Copy link
Contributor

@mpurg mpurg Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@teacup-on-rockingchair I think the operation here should be flipped.
The implementation searches for VARIABLE regex inside VALUE, instead of searching for VALUE regex in VARIABLE.
If VALUE=firewalld|nftables, then it will match when VARIABLE is set to any substring of VALUE, or an empty string, or regex special characters like ..

{{{ bash_package_install(package=PKGNAME) }}}
fi
{{% else %}}
if [ ${{{ VARIABLE }}} == {{{ VALUE }}} ]; then
{{{ bash_package_install(package=PKGNAME) }}}
fi
{{% endif %}}
26 changes: 26 additions & 0 deletions shared/templates/package_installed_guard_var/oval.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<def-group>
{{%- set variable_value_test_id = _RULE_ID + "_test_variable_" + VARIABLE -%}}
{{% if OPERATION is defined %}}
{{%- set variable_value_op = OPERATION -%}}
{{% else %}}
{{%- set variable_value_op = "equals" -%}}
{{% endif %}}
<definition class="compliance" id="{{{ _RULE_ID }}}"
version="1">
{{{ oval_metadata("The " + pkg_system|upper + " package " + PKGNAME + " should be installed.", affected_platforms=["multi_platform_sle"]) }}}
<criteria operator="OR" comment="package {{{ PKGNAME }}} is installed or not needed">
<criteria comment="{{{ PKGNAME }}} is not needed" operator="AND">
<criterion comment="variable {{{ VARIABLE }}} is set to {{{ VALUE }}}"
test_ref="{{{ variable_value_test_id }}}" negate="true"/>
</criteria>
<criteria comment="package {{{ PKGNAME }}} is installed and needed" operator="AND">
<criterion comment="package {{{ PKGNAME }}} is installed"
test_ref="test_package_{{{ PKGNAME }}}_installed" />
<criterion comment="variable {{{ VARIABLE }}} is set to {{{ VALUE }}}"
test_ref="{{{ variable_value_test_id }}}" />
</criteria>
</criteria>
</definition>
{{{ oval_test_external_variable_value(variable=VARIABLE, value=VALUE, test_id=variable_value_test_id, operation=variable_value_op) }}}
{{{ oval_test_package_installed(package=PKGNAME, evr=EVR, test_id="test_package_"+PKGNAME+"_installed") }}}
</def-group>
12 changes: 12 additions & 0 deletions shared/templates/package_installed_guard_var/template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import re


def preprocess(data, lang):
if "evr" in data:
evr = data["evr"]
if evr and not re.match(r'\d:\d[\d\w+.]*-\d[\d\w+.]*', evr, 0):
raise RuntimeError(
"ERROR: input violation: evr key should be in "
"epoch:version-release format, but package {0} has set "
"evr to {1}".format(data["pkgname"], evr))
return data
4 changes: 4 additions & 0 deletions shared/templates/package_installed_guard_var/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
supported_languages:
- ansible
- bash
- oval
18 changes: 18 additions & 0 deletions shared/templates/package_removed_guard_var/ansible.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# platform = multi_platform_sle
# reboot = false
# strategy = disable
# complexity = low
# disruption = low

{{{ ansible_instantiate_variables(VARIABLE) }}}

- name: Ensure {{{ PKGNAME }}} is removed
package:
teacup-on-rockingchair marked this conversation as resolved.
Show resolved Hide resolved
name: "{{{ PKGNAME }}}"
state: absent
when: {{{ VARIABLE }}} != "{{{ VALUE }}}"
{{% if OPERATION == "pattern match" %}}
when: {{{ VARIABLE }}} is not regex("{{{ VALUE }}}")
{{% else %}}
when: {{{ VARIABLE }}} != "{{{ VALUE }}}"
{{% endif %}}
23 changes: 23 additions & 0 deletions shared/templates/package_removed_guard_var/bash.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# platform = multi_platform_sle
# reboot = false
# strategy = disable
# complexity = low
# disruption = low

# CAUTION: This remediation script will remove {{{ PKGNAME }}}
# from the system, and may remove any packages
# that depend on {{{ PKGNAME }}}. Execute this
# remediation AFTER testing on a non-production
# system!

{{{ bash_instantiate_variables(VARIABLE) }}}

{{% if OPERATION == "pattern match" %}}
if ! [[ "{{{ VALUE }}}" =~ ${{{ VARIABLE }}} ]]; then
{{{ bash_package_remove(package=PKGNAME) }}}
fi
{{% else %}}
if [ ${{{ VARIABLE }}} != {{{ VALUE }}} ]; then
{{{ bash_package_remove(package=PKGNAME) }}}
fi
{{% endif %}}
Loading
Loading