-
Notifications
You must be signed in to change notification settings - Fork 710
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
Mab879
merged 21 commits into
ComplianceAsCode:master
from
teacup-on-rockingchair:firewall_by_profile_variable
Jan 21, 2025
Merged
Changes from all 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 660e7f8
Add variable to set default firewall technology used
teacup-on-rockingchair dc4a098
Set relevant values for SLE platforms
teacup-on-rockingchair 64885fd
Templates for pkg installed/removed and svc enabled/disabled, guarded…
teacup-on-rockingchair 9aa0beb
Enable nftable service on SLE only if active firewall technology is s…
teacup-on-rockingchair 22ac8fd
Disable nftable service on SLE only if active firewall technology is …
teacup-on-rockingchair 99243ab
Removing nftable package on SLE makes sense only if active firewall t…
teacup-on-rockingchair 3a65275
Installing iptables package on SLE only if active firewall technology…
teacup-on-rockingchair 93fc615
Enable iptables service on SLE only if active firewall technology is …
teacup-on-rockingchair 53f09ca
Disable firewalld service on SLE only if active firewall technology i…
teacup-on-rockingchair 55fd107
Removing package on SLE makes sense only if active firewall technolo…
teacup-on-rockingchair 67b3616
Enable firewalld service on SLE only if active firewall technology is…
teacup-on-rockingchair 7df2ff6
Installing firewalld package on SLE only if active firewall technolog…
teacup-on-rockingchair 75126ba
Fix bash template to produce shellcheck compliant code
teacup-on-rockingchair e8ef4d7
Package removed template guarded is with inverted logic
teacup-on-rockingchair 6ae92ca
Invert the logic for variable dependency for service disabled rules
teacup-on-rockingchair 8f0fdfe
Replace machine with more relevant system_with_kernel platform
teacup-on-rockingchair 55f0f79
Update shared/templates/package_removed_guard_var/ansible.template
teacup-on-rockingchair b7a296e
Update shared/templates/service_enabled_guard_var/ansible.template
teacup-on-rockingchair b96d658
Update shared/templates/package_installed_guard_var/ansible.template
teacup-on-rockingchair 440dd03
Simplify template removing obsolete oval < 5.11 version support
teacup-on-rockingchair File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
linux_os/guide/system/network/var_network_filtering_service.var
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
shared/templates/package_installed_guard_var/ansible.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
ansible.builtin.package: | ||
name: "{{{ PKGNAME }}}" | ||
state: present | ||
{{% if OPERATION == "pattern match" %}} | ||
when: {{{ VARIABLE }}} is regex("{{{ VALUE }}}") | ||
{{% else %}} | ||
when: {{{ VARIABLE }}} == "{{{ VALUE }}}" | ||
{{% endif %}} |
17 changes: 17 additions & 0 deletions
17
shared/templates/package_installed_guard_var/bash.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{{{ bash_package_install(package=PKGNAME) }}} | ||
fi | ||
{{% else %}} | ||
if [ ${{{ VARIABLE }}} == {{{ VALUE }}} ]; then | ||
{{{ bash_package_install(package=PKGNAME) }}} | ||
fi | ||
{{% endif %}} |
26 changes: 26 additions & 0 deletions
26
shared/templates/package_installed_guard_var/oval.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
shared/templates/package_removed_guard_var/ansible.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
ansible.builtin.package: | ||
name: "{{{ PKGNAME }}}" | ||
state: absent | ||
when: {{{ VARIABLE }}} != "{{{ VALUE }}}" | ||
{{% if OPERATION == "pattern match" %}} | ||
when: {{{ VARIABLE }}} is not regex("{{{ VALUE }}}") | ||
{{% else %}} | ||
when: {{{ VARIABLE }}} != "{{{ VALUE }}}" | ||
{{% endif %}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %}} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 whenVARIABLE
is set to any substring of VALUE, or an empty string, or regex special characters like.
.