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

Prevent quoting issues in rule firewalld-backend #10820

Merged
merged 2 commits into from
Jul 14, 2023

Conversation

jan-cerny
Copy link
Collaborator

We will set the no_quotes parameter of the template to avoid issues that can be caused by extra quotes in the configuration file.

For example, setting CleanupOnExit='no' causes this problem:

Jul 11 10:22:20 fedora firewalld[117694]: WARNING: CleanupOnExit ''no'' is not valid, using default value True

The default for the FirewallBackend option is nftables, adding quotes will not cause a problem, until firewalld decides in future to change the defaults.

Jul 11 10:25:18 fedora firewalld[118127]: WARNING: FirewallBackend ''nftables'' is not valid, using default value nftables

We have seen similar things with journald rules, where it actually caused troubles, check:
https://bugzilla.redhat.com/show_bug.cgi?id=2193169

@github-actions
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

@github-actions
Copy link

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_firewalld-backend' differs.
--- xccdf_org.ssgproject.content_rule_firewalld-backend
+++ xccdf_org.ssgproject.content_rule_firewalld-backend
@@ -16,10 +16,10 @@
 if [ -z "$line_number" ]; then
     # There was no match of '^#\s*FirewallBackend', insert at
     # the end of the file.
-    printf '%s\n' "FirewallBackend='nftables'" >> "/etc/firewalld/firewalld.conf"
+    printf '%s\n' "FirewallBackend=nftables" >> "/etc/firewalld/firewalld.conf"
 else
     head -n "$(( line_number - 1 ))" "/etc/firewalld/firewalld.conf.bak" > "/etc/firewalld/firewalld.conf"
-    printf '%s\n' "FirewallBackend='nftables'" >> "/etc/firewalld/firewalld.conf"
+    printf '%s\n' "FirewallBackend=nftables" >> "/etc/firewalld/firewalld.conf"
     tail -n "+$(( line_number ))" "/etc/firewalld/firewalld.conf.bak" >> "/etc/firewalld/firewalld.conf"
 fi
 # Clean up after ourselves.

ansible remediation for rule 'xccdf_org.ssgproject.content_rule_firewalld-backend' differs.
--- xccdf_org.ssgproject.content_rule_firewalld-backend
+++ xccdf_org.ssgproject.content_rule_firewalld-backend
@@ -12,7 +12,7 @@
   - no_reboot_needed
   - restrict_strategy
 
-- name: Setting shell-quoted shell-style assignment of 'FirewallBackend' to 'nftables'
+- name: Setting unquoted shell-style assignment of 'FirewallBackend' to 'nftables'
     in '/etc/firewalld/firewalld.conf'
   block:
 
@@ -39,7 +39,7 @@
       path: /etc/firewalld/firewalld.conf
       create: true
       regexp: ^\s*FirewallBackend=
-      line: FirewallBackend="nftables"
+      line: FirewallBackend=nftables
       state: present
       insertbefore: ^# FirewallBackend
       validate: /usr/bin/bash -n %s

@Mab879 Mab879 self-assigned this Jul 11, 2023
@Mab879 Mab879 added this to the 0.1.69 milestone Jul 11, 2023
@Mab879 Mab879 added the bugfix Fixes to reported bugs. label Jul 11, 2023
@Mab879
Copy link
Member

Mab879 commented Jul 11, 2023

Should we add tests like in #10817 and #10818?

@jan-cerny
Copy link
Collaborator Author

@Mab879 I have add a small test scenario.

@Mab879
Copy link
Member

Mab879 commented Jul 14, 2023

Can you please rebase this PR? That should fix the CI.

We will set the no_quotes parameter of the template to avoid
issues that can be caused by extra quotes in the configuration
file.

For example, setting `CleanupOnExit='no'` causes this problem:

```
Jul 11 10:22:20 fedora firewalld[117694]: WARNING: CleanupOnExit ''no'' is not valid, using default value True
```

The default for the `FirewallBackend` option is `nftables`, adding
quotes will not cause a problem, until firewalld decides in future to
change the defaults.

```
Jul 11 10:25:18 fedora firewalld[118127]: WARNING: FirewallBackend ''nftables'' is not valid, using default value nftables
```

We have seen similar things with journald rules, where it actually
caused troubles, check:
https://bugzilla.redhat.com/show_bug.cgi?id=2193169
@jan-cerny
Copy link
Collaborator Author

I have rebased this PR on the top of the latest upstream master branch.

@codeclimate
Copy link

codeclimate bot commented Jul 14, 2023

Code Climate has analyzed commit 3e51b8e and detected 0 issues on this pull request.

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 53.4% (0.0% change).

View more on Code Climate.

Copy link
Member

@Mab879 Mab879 left a comment

Choose a reason for hiding this comment

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

Waving Automatus tests as they pass locally.

$ ./automatus.py rule --libvirt qemu:///system automatus_rhel_9_latest_2 --remediate-using ansible --datastream ../build/ssg-rhel9-ds.xml firewalld-backend    
Setting console output to log level INFO
INFO - The base image option has not been specified, choosing libvirt-based test environment.
INFO - Logging into /home/mburket/review/ComplianceAsCode/content/tests/logs/rule-custom-2023-07-14-1515/test_suite.log
INFO - xccdf_org.ssgproject.content_rule_firewalld-backend
INFO - Script quoted.fail.sh using profile (all) OK
INFO - Script missing.fail.sh using profile (all) OK
INFO - Script correct_value.pass.sh using profile (all) OK
INFO - Script wrong_value.fail.sh using profile (all) OK

@Mab879 Mab879 merged commit 1c06241 into ComplianceAsCode:master Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fixes to reported bugs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants