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

rsyslog_files_permissions: Consider the last field in the config line the log file path #9750

Merged
merged 2 commits into from
Nov 4, 2022

Conversation

yuumasato
Copy link
Member

Description:

  • Fix path filtering in the Bash remediation.
    • It was assuming that the log file path is always the second field in the config line. But this assumption breaks when there are conditionals.
    • The log file path is always the last field in the config line.

Rationale:

@yuumasato yuumasato changed the title Rsyslog cloudinit case rsyslog_files_permissions: Consider the last field in the config line the log file path Nov 1, 2022
@yuumasato yuumasato requested a review from mildas November 1, 2022 11:06
@github-actions
Copy link

github-actions bot commented Nov 1, 2022

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

@yuumasato
Copy link
Member Author

yuumasato commented Nov 1, 2022

@lonicerae Hi, would you mind looking at the PR? Thanks.
Edit: As you recently proposed fixes to this rule, I thought that your input could be interesting.

@yuumasato yuumasato added bugfix Fixes to reported bugs. Bash Bash remediation update. labels Nov 1, 2022
@github-actions
Copy link

github-actions bot commented Nov 1, 2022

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_rsyslog_files_permissions' differs.
--- xccdf_org.ssgproject.content_rule_rsyslog_files_permissions
+++ xccdf_org.ssgproject.content_rule_rsyslog_files_permissions
@@ -58,7 +58,7 @@
 then
 NORMALIZED_CONFIG_FILE_LINES=$(sed -e "/^[#|$]/d" "${LOG_FILE}")
 LINES_WITH_PATHS=$(grep '[^/]*\s\+\S*/\S\+$' <<< "${NORMALIZED_CONFIG_FILE_LINES}")
- FILTERED_PATHS=$(awk '{if(NF>=2&&($2~/^\//||$2~/^-\//)){sub(/^-\//,"/",$2);print $2}}' <<< "${LINES_WITH_PATHS}")
+ FILTERED_PATHS=$(awk '{if(NF>=2&&($NF~/^\//||$NF~/^-\//)){sub(/^-\//,"/",$NF);print $NF}}' <<< "${LINES_WITH_PATHS}")
 CLEANED_PATHS=$(sed -e "s/[\"')]//g; /\\/etc.*\.conf/d; /\\/dev\\//d" <<< "${FILTERED_PATHS}")
 MATCHED_ITEMS=$(sed -e "/^$/d" <<< "${CLEANED_PATHS}")
 # Since above sed command might return more than one item (delimited by newline), split the particular

@mildas mildas self-assigned this Nov 1, 2022
@yuumasato
Copy link
Member Author

@brett060102 You may be interested in this fix as well.

@mildas
Copy link
Contributor

mildas commented Nov 1, 2022

@yuumasato @ggbecker Any idea what is wrong with Automatus?

@yuumasato
Copy link
Member Author

@yuumasato @ggbecker Any idea what is wrong with Automatus?

No idea, automatus on containers work locally for me.

I have removed some old comments from the test scenario, and pushed again.
Let's see how the tests go.

These tests configure an rsyslog conf file similar to the ones used to
filter cloudinit entries in "21-cloudinit.conf".
An rsyslog config line can have more than two fields, and the last one
will actually be the field with the log file path.
@codeclimate
Copy link

codeclimate bot commented Nov 3, 2022

Code Climate has analyzed commit be4b176 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 46.7%.

View more on Code Climate.

Copy link
Contributor

@mildas mildas left a comment

Choose a reason for hiding this comment

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

I've tested it on CS8 and CS9 images, works well. Thank you for the fix @yuumasato !

@mildas mildas merged commit dbc3091 into ComplianceAsCode:master Nov 4, 2022
@yuumasato yuumasato deleted the rsyslog_cloudinit_case branch November 4, 2022 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bash Bash remediation update. bugfix Fixes to reported bugs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants