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

Ubuntu 24.04 6.1.2.1.2 Ensure systemd-journal-upload authentication #12852

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

Conversation

ericeberry
Copy link
Contributor

Description:

  • Ubuntu 24.04 6.1.2.1.2 Ensure systemd-journal-upload authentication is configured

Rationale:

  • Implemented Ubuntu 24.04 6.1.2.1.2 Ensure systemd-journal-upload authentication is configured

@ericeberry ericeberry requested a review from a team as a code owner January 17, 2025 23:02
Copy link

openshift-ci bot commented Jan 17, 2025

Hi @ericeberry. Thanks for your PR.

I'm waiting for a ComplianceAsCode member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@openshift-ci openshift-ci bot added the needs-ok-to-test Used by openshift-ci bot. label Jan 17, 2025
Copy link

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

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

Fedora Testing Environment
Open in Gitpod

Oracle Linux 8 Environment
Open in Gitpod

@dodys dodys self-assigned this Jan 20, 2025
@dodys dodys added Ubuntu Ubuntu product related. New Rule Issues or pull requests related to new Rules. Update Profile Issues or pull requests related to Profiles updates. CIS CIS Benchmark related. labels Jan 20, 2025
@dodys dodys added this to the 0.1.76 milestone Jan 20, 2025
Copy link
Contributor

@mpurg mpurg left a comment

Choose a reason for hiding this comment

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

minor changes

Copy link

github-actions bot commented Jan 21, 2025

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

Click here to see the full diff
New content has different text for rule 'xccdf_org.ssgproject.content_rule_systemd_journal_upload_server_tls'.
--- xccdf_org.ssgproject.content_rule_systemd_journal_upload_server_tls
+++ xccdf_org.ssgproject.content_rule_systemd_journal_upload_server_tls
@@ -1,6 +1,6 @@
 
 [title]:
-Configure systemd-journal-upload TLS parameters: ServerKeyFile,ServerCertificateFile and TrustedCertificateFile
+Configure systemd-journal-upload TLS parameters: ServerKeyFile, ServerCertificateFile and TrustedCertificateFile
 
 [description]:
 SUSE Linux Enterprise Micro 5 must offload rsyslog messages for networked systems in real time and

OCIL for rule 'xccdf_org.ssgproject.content_rule_systemd_journal_upload_server_tls' differs.
--- ocil:ssg-systemd_journal_upload_server_tls_ocil:questionnaire:1
+++ ocil:ssg-systemd_journal_upload_server_tls_ocil:questionnaire:1
@@ -1,5 +1,5 @@
 To ensure logs are sent securely to a remote host, examine the file
-/etc/systemd/journal-upload.conf.
+.
 ServerKeyFile should be present:
 ServerKeyFile=
 ServerCertificateFile should be present:

bash remediation for rule 'xccdf_org.ssgproject.content_rule_systemd_journal_upload_server_tls' differs.
--- xccdf_org.ssgproject.content_rule_systemd_journal_upload_server_tls
+++ xccdf_org.ssgproject.content_rule_systemd_journal_upload_server_tls
@@ -1,5 +1,7 @@
 # Remediation is applicable only in certain platforms
 if rpm --quiet -q kernel-default; then
+
+var_journal_upload_conf_file=''
 
 var_journal_upload_server_key_file=''
 
@@ -13,16 +15,16 @@
 # If the key exists, change it. Otherwise, add it to the config_file.
 # We search for the key string followed by a word boundary (matched by \>),
 # so if we search for 'setting', 'setting2' won't match.
-if LC_ALL=C grep -q -m 1 -i -e "^ServerKeyFile\\>" "/etc/systemd/journal-upload.conf"; then
+if LC_ALL=C grep -q -m 1 -i -e "^ServerKeyFile\\>" "$var_journal_upload_conf_file"; then
     escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output")
-    LC_ALL=C sed -i --follow-symlinks "s/^ServerKeyFile\\>.*/$escaped_formatted_output/gi" "/etc/systemd/journal-upload.conf"
+    LC_ALL=C sed -i --follow-symlinks "s/^ServerKeyFile\\>.*/$escaped_formatted_output/gi" "$var_journal_upload_conf_file"
 else
-    if [[ -s "/etc/systemd/journal-upload.conf" ]] && [[ -n "$(tail -c 1 -- "/etc/systemd/journal-upload.conf" || true)" ]]; then
-        LC_ALL=C sed -i --follow-symlinks '$a'\\ "/etc/systemd/journal-upload.conf"
+    if [[ -s "$var_journal_upload_conf_file" ]] && [[ -n "$(tail -c 1 -- "$var_journal_upload_conf_file" || true)" ]]; then
+        LC_ALL=C sed -i --follow-symlinks '$a'\\ "$var_journal_upload_conf_file"
     fi
     cce="CCE-94080-9"
-    printf '# Per %s: Set %s in %s\n' "${cce}" "${formatted_output}" "/etc/systemd/journal-upload.conf" >> "/etc/systemd/journal-upload.conf"
-    printf '%s\n' "$formatted_output" >> "/etc/systemd/journal-upload.conf"
+    printf '# Per %s: Set %s in %s\n' "${cce}" "${formatted_output}" "$var_journal_upload_conf_file" >> "$var_journal_upload_conf_file"
+    printf '%s\n' "$formatted_output" >> "$var_journal_upload_conf_file"
 fi
 
 var_journal_upload_server_certificate_file=''
@@ -37,16 +39,16 @@
 # If the key exists, change it. Otherwise, add it to the config_file.
 # We search for the key string followed by a word boundary (matched by \>),
 # so if we search for 'setting', 'setting2' won't match.
-if LC_ALL=C grep -q -m 1 -i -e "^ServerCertificateFile\\>" "/etc/systemd/journal-upload.conf"; then
+if LC_ALL=C grep -q -m 1 -i -e "^ServerCertificateFile\\>" "$var_journal_upload_conf_file"; then
     escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output")
-    LC_ALL=C sed -i --follow-symlinks "s/^ServerCertificateFile\\>.*/$escaped_formatted_output/gi" "/etc/systemd/journal-upload.conf"
+    LC_ALL=C sed -i --follow-symlinks "s/^ServerCertificateFile\\>.*/$escaped_formatted_output/gi" "$var_journal_upload_conf_file"
 else
-    if [[ -s "/etc/systemd/journal-upload.conf" ]] && [[ -n "$(tail -c 1 -- "/etc/systemd/journal-upload.conf" || true)" ]]; then
-        LC_ALL=C sed -i --follow-symlinks '$a'\\ "/etc/systemd/journal-upload.conf"
+    if [[ -s "$var_journal_upload_conf_file" ]] && [[ -n "$(tail -c 1 -- "$var_journal_upload_conf_file" || true)" ]]; then
+        LC_ALL=C sed -i --follow-symlinks '$a'\\ "$var_journal_upload_conf_file"
     fi
     cce="CCE-94080-9"
-    printf '# Per %s: Set %s in %s\n' "${cce}" "${formatted_output}" "/etc/systemd/journal-upload.conf" >> "/etc/systemd/journal-upload.conf"
-    printf '%s\n' "$formatted_output" >> "/etc/systemd/journal-upload.conf"
+    printf '# Per %s: Set %s in %s\n' "${cce}" "${formatted_output}" "$var_journal_upload_conf_file" >> "$var_journal_upload_conf_file"
+    printf '%s\n' "$formatted_output" >> "$var_journal_upload_conf_file"
 fi
 
 var_journal_upload_server_trusted_certificate_file=''
@@ -61,16 +63,16 @@
 # If the key exists, change it. Otherwise, add it to the config_file.
 # We search for the key string followed by a word boundary (matched by \>),
 # so if we search for 'setting', 'setting2' won't match.
-if LC_ALL=C grep -q -m 1 -i -e "^TrustedCertificateFile\\>" "/etc/systemd/journal-upload.conf"; then
+if LC_ALL=C grep -q -m 1 -i -e "^TrustedCertificateFile\\>" "$var_journal_upload_conf_file"; then
     escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output")
-    LC_ALL=C sed -i --follow-symlinks "s/^TrustedCertificateFile\\>.*/$escaped_formatted_output/gi" "/etc/systemd/journal-upload.conf"
+    LC_ALL=C sed -i --follow-symlinks "s/^TrustedCertificateFile\\>.*/$escaped_formatted_output/gi" "$var_journal_upload_conf_file"
 else
-    if [[ -s "/etc/systemd/journal-upload.conf" ]] && [[ -n "$(tail -c 1 -- "/etc/systemd/journal-upload.conf" || true)" ]]; then
-        LC_ALL=C sed -i --follow-symlinks '$a'\\ "/etc/systemd/journal-upload.conf"
+    if [[ -s "$var_journal_upload_conf_file" ]] && [[ -n "$(tail -c 1 -- "$var_journal_upload_conf_file" || true)" ]]; then
+        LC_ALL=C sed -i --follow-symlinks '$a'\\ "$var_journal_upload_conf_file"
     fi
     cce="CCE-94080-9"
-    printf '# Per %s: Set %s in %s\n' "${cce}" "${formatted_output}" "/etc/systemd/journal-upload.conf" >> "/etc/systemd/journal-upload.conf"
-    printf '%s\n' "$formatted_output" >> "/etc/systemd/journal-upload.conf"
+    printf '# Per %s: Set %s in %s\n' "${cce}" "${formatted_output}" "$var_journal_upload_conf_file" >> "$var_journal_upload_conf_file"
+    printf '%s\n' "$formatted_output" >> "$var_journal_upload_conf_file"
 fi
 
 else

OCIL for rule 'xccdf_org.ssgproject.content_rule_systemd_journal_upload_url' differs.
--- ocil:ssg-systemd_journal_upload_url_ocil:questionnaire:1
+++ ocil:ssg-systemd_journal_upload_url_ocil:questionnaire:1
@@ -1,5 +1,5 @@
 To ensure logs are sent to a remote host, examine the file
-/etc/systemd/journal-upload.conf.
+.
 URL should be present:
 URL=
       Is it the case that systemd-journal-upload URL is missing or commented in /etc/systemd/journal-upload.conf?

bash remediation for rule 'xccdf_org.ssgproject.content_rule_systemd_journal_upload_url' differs.
--- xccdf_org.ssgproject.content_rule_systemd_journal_upload_url
+++ xccdf_org.ssgproject.content_rule_systemd_journal_upload_url
@@ -1,5 +1,7 @@
 # Remediation is applicable only in certain platforms
 if rpm --quiet -q kernel-default; then
+
+var_journal_upload_conf_file=''
 
 var_journal_upload_url=''
 
@@ -13,16 +15,16 @@
 # If the key exists, change it. Otherwise, add it to the config_file.
 # We search for the key string followed by a word boundary (matched by \>),
 # so if we search for 'setting', 'setting2' won't match.
-if LC_ALL=C grep -q -m 1 -i -e "^URL\\>" "/etc/systemd/journal-upload.conf"; then
+if LC_ALL=C grep -q -m 1 -i -e "^URL\\>" "$var_journal_upload_conf_file"; then
     escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output")
-    LC_ALL=C sed -i --follow-symlinks "s/^URL\\>.*/$escaped_formatted_output/gi" "/etc/systemd/journal-upload.conf"
+    LC_ALL=C sed -i --follow-symlinks "s/^URL\\>.*/$escaped_formatted_output/gi" "$var_journal_upload_conf_file"
 else
-    if [[ -s "/etc/systemd/journal-upload.conf" ]] && [[ -n "$(tail -c 1 -- "/etc/systemd/journal-upload.conf" || true)" ]]; then
-        LC_ALL=C sed -i --follow-symlinks '$a'\\ "/etc/systemd/journal-upload.conf"
+    if [[ -s "$var_journal_upload_conf_file" ]] && [[ -n "$(tail -c 1 -- "$var_journal_upload_conf_file" || true)" ]]; then
+        LC_ALL=C sed -i --follow-symlinks '$a'\\ "$var_journal_upload_conf_file"
     fi
     cce="CCE-94081-7"
-    printf '# Per %s: Set %s in %s\n' "${cce}" "${formatted_output}" "/etc/systemd/journal-upload.conf" >> "/etc/systemd/journal-upload.conf"
-    printf '%s\n' "$formatted_output" >> "/etc/systemd/journal-upload.conf"
+    printf '# Per %s: Set %s in %s\n' "${cce}" "${formatted_output}" "$var_journal_upload_conf_file" >> "$var_journal_upload_conf_file"
+    printf '%s\n' "$formatted_output" >> "$var_journal_upload_conf_file"
 fi
 
 else

Copy link
Contributor

@mpurg mpurg left a comment

Choose a reason for hiding this comment

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

Changes needed

{{{ bash_instantiate_variables("var_journal_upload_server_key_file") }}}
{{{ bash_replace_or_append('/etc/systemd/journal-upload.conf', '^ServerKeyFile', "$var_journal_upload_server_key_file", '%s=%s') }}}
{{{ bash_replace_or_append('$var_journal_upload_conf_file', '^ServerKeyFile', "$var_journal_upload_server_key_file", '%s=%s') }}}
Copy link
Contributor

Choose a reason for hiding this comment

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

These changes would affect slmicro too.
Use a ubuntu-specific remediation file (ubuntu.sh) or place the code inside conditionals, e.g.

{{% if 'ubuntu' in product %}}
{{{ bash_instantiate_variables("var_journal_upload_conf_file") }}}
{{% else %}}
var_journal_upload_conf_file=/etc/systemd/journal-upload.conf
{{% endif %}}

That said, I couldn't find the XCCDF variable var_journal_upload_conf_file in the codebase.
If you want to introduce a new variable you need to create it, analogous to /linux_os/guide/system/logging/journald/var_journal_upload_url.var.

For this specific case, I wouldn't recommend using an XCCDF variable though, since config file locations are not something that we generally let the users specify at runtime. Config file paths are mostly hardcoded into the rules. If they differ across OS-es they can be defined via conditionals or via Jinja variables defined in product.yml files.

Copy link
Contributor Author

@ericeberry ericeberry Jan 22, 2025

Choose a reason for hiding this comment

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

This should be the file you were looking for (that I created): https://github.com/ComplianceAsCode/content/blob/53a6846f6f0f92cc4bbafd56246c32af110f6e8c/linux_os/guide/system/logging/journald/var_journal_upload_conf_file.var

Doesn't the default setting take care of the slmicro case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably 95% of the time, I would think they use the default filename (/etc/systemd/journal-update.conf). But I think the new way of configuring is to create a file in the /etc/systemd/journal-update.conf.d directory now. I needed to be able to change the name of the file for the tests so that I could specify files in the conf.d directory.


{{{ bash_instantiate_variables("var_journal_upload_conf_file") }}}
Copy link
Contributor

Choose a reason for hiding this comment

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

See first comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't setting the default in the var_journal_upload_conf_file.var handle the slmicro case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I compile slmicro5 and it looks like it is ok.

Copy link

codeclimate bot commented Jan 22, 2025

Code Climate has analyzed commit c15a18c 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 61.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
CIS CIS Benchmark related. needs-ok-to-test Used by openshift-ci bot. New Rule Issues or pull requests related to new Rules. Ubuntu Ubuntu product related. Update Profile Issues or pull requests related to Profiles updates.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants