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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

teacup-on-rockingchair
Copy link
Contributor

@teacup-on-rockingchair teacup-on-rockingchair commented Apr 14, 2024

Description:

  • Make sure that behaviour of rules about nftables,iptables and firewalld are mutually exclusive and the default behaviour of the checks and remediations is based on external interactive variable, that is part of the profile definition

Rationale:

  • Add oval macro to check external variable vs expected value
  • Add variable to set default firewall technology used
  • Set relevant values for SLE platforms
  • Templates for pkg installed/removed and svc enabled/disabled, guarded by ext varaiable
  • The idea is the oval checks and remediation to check provided external variable, and thus honour if really to check/install/remove certain package or service
  • Enable nftable service on SLE only if active firewall technology is set to be nftables
  • Disable nftable service on SLE only if active firewall technology is set to be firewalld or iptables
  • Removing nftable package on SLE makes sense only if active firewall technology is set to be firewalld or iptables
  • Installing iptables package on SLE only if active firewall technology is set to be iptables
  • Enable iptables service on SLE only if active firewall technology is set to be iptables
  • Disable firewalld service on SLE only if active firewall technology is set to be nftables or iptables
  • Removing package on SLE makes sense only if active firewall technology is set to be nftables or iptables
  • Enable firewalld service on SLE only if active firewall technology is set to be firewalld
  • Installing firewalld package on SLE only if active firewall technology is set to be firewalld

Review Hints:

  • For now the proposed change is applied to SLE platforms only, and if proves to be a good approach can distribute to other platforms also
  • The use case would be that the user will have in its profile defined default firewall technology, one of iptables,nftables,ufw, firewalld ,and if the system has been modified a non-default option for that, one can use scap-workbench or similar tool, or define a new alternative profile to the original one (CIS is currently the one having conflicting rules ) , or via command line arguments of the oscap tool, if that is the weapon of choice to run checks and remediations.

@teacup-on-rockingchair teacup-on-rockingchair added Ansible Ansible remediation update. OVAL OVAL update. Related to the systems assessments. Bash Bash remediation update. SLES SUSE Linux Enterprise Server product related. New Template Issues or pull requests related to new Templates. labels Apr 14, 2024
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Used by openshift-ci bot. label Apr 14, 2024
Copy link

openshift-ci bot commented Apr 14, 2024

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

Copy link

Start a new ephemeral environment with changes proposed in this pull request:

rhel8 (from CTF) Environment (using Fedora as testing environment)
Open in Gitpod

Fedora Testing Environment
Open in Gitpod

Oracle Linux 8 Environment
Open in Gitpod

Copy link

github-actions bot commented Apr 14, 2024

This datastream diff is auto generated by the check Compare DS/Generate Diff

Click here to see the full diff
bash remediation for rule 'xccdf_org.ssgproject.content_rule_service_iptables_enabled' differs.
--- xccdf_org.ssgproject.content_rule_service_iptables_enabled
+++ xccdf_org.ssgproject.content_rule_service_iptables_enabled
@@ -1,5 +1,5 @@
 # Remediation is applicable only in certain platforms
-if ( rpm --quiet -q iptables && rpm --quiet -q kernel ); then
+if ( [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ] && rpm --quiet -q iptables ); then
 
 SYSTEMCTL_EXEC='/usr/bin/systemctl'
 "$SYSTEMCTL_EXEC" unmask 'iptables.service'

ansible remediation for rule 'xccdf_org.ssgproject.content_rule_service_iptables_enabled' differs.
--- xccdf_org.ssgproject.content_rule_service_iptables_enabled
+++ xccdf_org.ssgproject.content_rule_service_iptables_enabled
@@ -30,8 +30,8 @@
       masked: false
     when:
     - '"iptables" in ansible_facts.packages'
-  when: ( "iptables" in ansible_facts.packages and "kernel" in ansible_facts.packages
-    )
+  when: ( ansible_virtualization_type not in ["docker", "lxc", "openvz", "podman",
+    "container"] and "iptables" in ansible_facts.packages )
   tags:
   - CCE-85961-1
   - NIST-800-53-AC-4

Platform has been changed for rule 'xccdf_org.ssgproject.content_rule_service_iptables_enabled'
--- xccdf_org.ssgproject.content_rule_service_iptables_enabled
+++ xccdf_org.ssgproject.content_rule_service_iptables_enabled
@@ -1,3 +1,3 @@
+oval:ssg-installed_env_is_a_machine:def:1
 oval:ssg-package_iptables:def:1
 oval:ssg-service_disabled_firewalld:def:1
-oval:ssg-system_with_kernel:def:1

bash remediation for rule 'xccdf_org.ssgproject.content_rule_service_nftables_enabled' differs.
--- xccdf_org.ssgproject.content_rule_service_nftables_enabled
+++ xccdf_org.ssgproject.content_rule_service_nftables_enabled
@@ -1,5 +1,5 @@
 # Remediation is applicable only in certain platforms
-if ( rpm --quiet -q nftables && rpm --quiet -q kernel ); then
+if ( [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ] && rpm --quiet -q nftables ); then
 
 SYSTEMCTL_EXEC='/usr/bin/systemctl'
 "$SYSTEMCTL_EXEC" unmask 'nftables.service'

ansible remediation for rule 'xccdf_org.ssgproject.content_rule_service_nftables_enabled' differs.
--- xccdf_org.ssgproject.content_rule_service_nftables_enabled
+++ xccdf_org.ssgproject.content_rule_service_nftables_enabled
@@ -25,8 +25,8 @@
       masked: false
     when:
     - '"nftables" in ansible_facts.packages'
-  when: ( "nftables" in ansible_facts.packages and "kernel" in ansible_facts.packages
-    )
+  when: ( ansible_virtualization_type not in ["docker", "lxc", "openvz", "podman",
+    "container"] and "nftables" in ansible_facts.packages )
   tags:
   - CCE-86725-9
   - enable_strategy

Platform has been changed for rule 'xccdf_org.ssgproject.content_rule_service_nftables_enabled'
--- xccdf_org.ssgproject.content_rule_service_nftables_enabled
+++ xccdf_org.ssgproject.content_rule_service_nftables_enabled
@@ -1,3 +1,3 @@
+oval:ssg-installed_env_is_a_machine:def:1
 oval:ssg-package_nftables:def:1
 oval:ssg-service_disabled_firewalld:def:1
-oval:ssg-system_with_kernel:def:1

Copy link

github-actions bot commented Apr 14, 2024

🤖 A k8s content image for this PR is available at:
ghcr.io/complianceascode/k8scontent:11818
This image was built from commit: f2480f3

Click here to see how to deploy it

If you alread have Compliance Operator deployed:
utils/build_ds_container.py -i ghcr.io/complianceascode/k8scontent:11818

Otherwise deploy the content and operator together by checking out ComplianceAsCode/compliance-operator and:
CONTENT_IMAGE=ghcr.io/complianceascode/k8scontent:11818 make deploy-local

@jan-cerny jan-cerny changed the title Firewall technology related rules per service and package change logic accprding to interactive profile variable Firewall technology related rules per service and package change logic according to interactive profile variable Apr 15, 2024
@teacup-on-rockingchair teacup-on-rockingchair marked this pull request as ready for review April 15, 2024 15:30
@teacup-on-rockingchair teacup-on-rockingchair requested a review from a team as a code owner April 15, 2024 15:30
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Used by openshift-ci bot. label Apr 15, 2024
@teacup-on-rockingchair teacup-on-rockingchair marked this pull request as draft April 16, 2024 14:29
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Used by openshift-ci bot. label Apr 16, 2024
@teacup-on-rockingchair teacup-on-rockingchair marked this pull request as ready for review April 22, 2024 12:22
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Used by openshift-ci bot. label Apr 22, 2024
@teacup-on-rockingchair
Copy link
Contributor Author

/test all

@teacup-on-rockingchair teacup-on-rockingchair added this to the 0.1.73 milestone Apr 30, 2024
@vojtapolasek vojtapolasek modified the milestones: 0.1.73, 0.1.74 Apr 30, 2024
@marcusburghardt
Copy link
Member

/packit build

@teacup-on-rockingchair teacup-on-rockingchair force-pushed the firewall_by_profile_variable branch from 6188277 to fc100a9 Compare May 2, 2024 10:49
@openshift-merge-robot openshift-merge-robot added the needs-rebase Used by openshift-ci bot. label May 9, 2024
@dodys
Copy link
Contributor

dodys commented May 10, 2024

should we change this pr to work across different vendors?
@marcusburghardt @Mab879 @Xeicker

@Xeicker
Copy link
Contributor

Xeicker commented May 16, 2024

should we change this pr to work across different vendors? @marcusburghardt @Mab879 @Xeicker

For the moment it is not necessary for Oracle Linux

@teacup-on-rockingchair teacup-on-rockingchair force-pushed the firewall_by_profile_variable branch from fc100a9 to 87ba124 Compare May 21, 2024 03:40
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Used by openshift-ci bot. label May 21, 2024
@marcusburghardt marcusburghardt self-assigned this May 31, 2024
@Mab879 Mab879 modified the milestones: 0.1.74, 0.1.75 Jul 29, 2024
@jan-cerny
Copy link
Collaborator

ping

@teacup-on-rockingchair teacup-on-rockingchair force-pushed the firewall_by_profile_variable branch from 87ba124 to f2480f3 Compare October 7, 2024 10:51
@Mab879 Mab879 modified the milestones: 0.1.75, 0.1.76 Nov 6, 2024
… by ext varaiable

The idea is the oval checks and remediation to check provided external variable, and thus honour if really to check/install/remove certain package or service
…echnology is set to be firewalld or iptables
Given variable should actually mark the state in which package should not be removed because it is needed by the setup
@teacup-on-rockingchair teacup-on-rockingchair force-pushed the firewall_by_profile_variable branch from f2480f3 to 504b19e Compare December 2, 2024 08:27
Copy link

codeclimate bot commented Dec 2, 2024

Code Climate has analyzed commit 504b19e and detected 6 issues on this pull request.

Here's the issue category breakdown:

Category Count
Duplication 6

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 60.9% (0.0% change).

View more on Code Climate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ansible Ansible remediation update. Bash Bash remediation update. New Template Issues or pull requests related to new Templates. OVAL OVAL update. Related to the systems assessments. SLES SUSE Linux Enterprise Server product related.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants