Skip to content

Conversation

pafernanr
Copy link
Contributor

@pafernanr pafernanr commented Jul 29, 2025

Refer to 3919

  • New clean argument added --treat-certificates with next options:

    • obfuscate: (Default) convert certificates to text and let the method obfuscate_report do its job.
    • remove: Remove certificate files from the archive.
    • keep: Don't touch certificate files and keep them as is in the archive.
  • Notes:

    • Certificate files are identified by extension (.csr, .pem) and header:
      • r'-----BEGIN CERTIFICATE-----'
      • r'-----BEGIN [A-Z]+ PRIVATE KEY-----'
    • If openssl is not available and obfuscate is selected. It will be replaced by remove after show a WARNING message.
    • Certificate Key files are always removed.

Please place an 'X' inside each '[]' to confirm you adhere to our Contributor Guidelines

  • Is the commit message split over multiple lines and hard-wrapped at 72 characters?
  • Is the subject and message clear and concise?
  • Does the subject start with [plugin_name] if submitting a plugin patch or a [section_name] if part of the core sosreport code?
  • Does the commit contain a Signed-off-by: First Lastname [email protected]?
  • Are any related Issues or existing PRs properly referenced via a Closes (Issue) or Resolved (PR) line?
  • Are all passwords or private data gathered by this PR obfuscated?

Copy link

Congratulations! One of the builds has completed. 🍾

You can install the built RPMs by following these steps:

  • sudo yum install -y dnf-plugins-core on RHEL 8
  • sudo dnf install -y dnf-plugins-core on Fedora
  • dnf copr enable packit/sosreport-sos-4093
  • And now you can install the packages.

Please note that the RPMs should be used only in a testing environment.

@pafernanr pafernanr force-pushed the 3919_certificates_cleaner branch from 568d426 to 3474c83 Compare July 29, 2025 15:04
Comment on lines 581 to 598
if self.opts.treat_certificates == "obfuscate":
self.ui_log.warning(
"WARNING: certificate files that potentially contain "
"sensitive information will be CONVERTED to text and "
"OBFUSCATED in the final archive.\n"
)
elif self.opts.treat_certificates == "keep":
self.ui_log.warning(
"WARNING: certificate files that potentially contain "
"sensitive information will be KEPT in the final "
"archive as is.\n"
)
elif self.opts.treat_certificates == "remove":
self.ui_log.warning(
"WARNING: certificate files that potentially contain "
"sensitive information will be REMOVED in the final "
"archive.\n"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a thought / option to consider: do we really want a WARNING message (either one of those three) printed on every cleaner run?

continue
is_certificate = file_is_certificate(fname)
if is_certificate:
if is_certificate == "certificatekey":
Copy link
Contributor

Choose a reason for hiding this comment

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

In theory, key files should have been removed by report already. But surely they can remain also here, makes sense to remove them despite they dont usually contain any cleaner-sensitive data.

Comment on lines 737 to 742
archive.remove_file(short_name)
continue
if self.opts.treat_certificates == "keep":
continue
if self.opts.treat_certificates == "remove":
archive.remove_file(short_name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Originally, I thought we should put some debug message here "removing certificate file" or similar.

But a better approach is updating remove_file method in sos/cleaner/archives/__init__.py to have extra argument filetype=binary and replace:

self.log_info(f"Removing binary file '{fname}' from archive")

to:
self.log_info(f"Removing {filetype} file '{fname}' from archive")

(and call the method from here with proper argument)

sos_get_command_output(
f"openssl x509 -noout -text -in {str(fname)}",
to_file=f"{fname}.text")
shutil.move(f"{fname}.text", fname)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a thought / option to consider: should we keep original file's permissions and ownership? We are overwriting it here (which makes sense as well as we update the file content).

Copy link
Member

Choose a reason for hiding this comment

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

My only hangup here is actually dropping the .text suffix. I think if we're converting the cert file, then we should make that obvious, and I do like the idea of having a .text (or .txt if you prefer) appended to the filename.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree here, this behaviour can be confusing ("does the pem file really contain just text content, or..?").

Maybe worth appending the new filename to the log "Converting certificate .. above?

Gladly we do the change in cleaner and not in report where we would have to update filelist of collected files - here just removing the old file should be enough.

clean_grp.add_argument('--treat-certificates', default='obfuscate',
choices=['obfuscate', 'keep', 'remove'],
dest='treat_certificates',
help=('How to treat certificate files.'
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: Extra dot at the end. Same applies on two equivalent places later on.

return "certificate"
if re.search(r'-----BEGIN [A-Z]+ PRIVATE KEY-----', f.read()):
return "certificatekey"
return None
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a thought / option to consider: isnt this return redundant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, its is :) was added just to make lint happy

@pmoravec
Copy link
Contributor

I added several comments. Those starting "Just a thought / option to consider:" are really "just a thought" and nothing else - in those cases I am OK with the current change but maybe others can see the mentioned option as a better one?

@pmoravec
Copy link
Contributor

pmoravec commented Jul 30, 2025

The foreman tests failing is foreman infra issue: they have expired GPG key:

# curl https://archivedeb.theforeman.org/foreman.asc | gpg
gpg: WARNING: no command supplied.  Trying to guess what you mean ...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2460  100  2460    0     0  25696      0 --:--:-- --:--:-- --:--:-- 25894
pub   rsa4096 2021-07-23 [SCEA] [expired: 2025-07-24]
      5B7C3E5A735BCB4D615829DC0BDDA991FD7AAC8A
uid           Foreman Automatic Signing Key (2021) <[email protected]>
#

I am reporting this to the foreman team.

@ekohl
Copy link
Contributor

ekohl commented Jul 30, 2025

The foreman tests failing is foreman infra issue: they have expired GPG key:

I opened theforeman/foreman-infra#2280 for this.

@pafernanr pafernanr closed this Jul 30, 2025
@pafernanr pafernanr force-pushed the 3919_certificates_cleaner branch from cb4ddde to 7a1463f Compare July 30, 2025 15:27
@pafernanr pafernanr reopened this Jul 30, 2025
@pafernanr pafernanr closed this Jul 30, 2025
@pafernanr pafernanr force-pushed the 3919_certificates_cleaner branch from 3b5ee03 to 7a1463f Compare July 30, 2025 17:05
@pafernanr pafernanr reopened this Jul 30, 2025
@pafernanr pafernanr force-pushed the 3919_certificates_cleaner branch from f3fa9f7 to faab870 Compare August 1, 2025 12:25
Copy link
Contributor

@pmoravec pmoravec left a comment

Choose a reason for hiding this comment

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

ACK (up to the doubt about CodeQL warning).

Thanks Pablo for applying repetitive feedback! :)

@pmoravec pmoravec added Kind/Enhancement Reviewed/Needs 2nd Ack Require a 2nd ack from a maintainer Kind/cleaner cleaner component of sos labels Aug 1, 2025
@pafernanr
Copy link
Contributor Author

pafernanr commented Aug 1, 2025

@pmoravec all checks passed.

  • openssl command modified to "openssl storeutl -noout -text -certs /tmp/BUNDLE_FILE.crt"
  • That CodeQL warning didn't arise ¿? but "with open" code remains the same :)

@pafernanr pafernanr force-pushed the 3919_certificates_cleaner branch from ee8f7f0 to 1c04560 Compare August 1, 2025 15:51
@pafernanr pafernanr requested a review from bmr-cymru August 1, 2025 20:01
Copy link
Member

@TurboTurtle TurboTurtle left a comment

Choose a reason for hiding this comment

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

Ack up to my comment on the filename. I'd like to see us keep the .text/.txt, but willing to hear why that might not be a good idea.

sos_get_command_output(
f"openssl x509 -noout -text -in {str(fname)}",
to_file=f"{fname}.text")
shutil.move(f"{fname}.text", fname)
Copy link
Member

Choose a reason for hiding this comment

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

My only hangup here is actually dropping the .text suffix. I think if we're converting the cert file, then we should make that obvious, and I do like the idea of having a .text (or .txt if you prefer) appended to the filename.

Copy link
Contributor

@pmoravec pmoravec left a comment

Choose a reason for hiding this comment

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

Sorry @pafernanr for yet another nitpick change requested. This slipped down among the reviews..

@pafernanr pafernanr force-pushed the 3919_certificates_cleaner branch from 475e389 to 3c96a3c Compare September 15, 2025 07:01
@pafernanr
Copy link
Contributor Author

Hi all, last commit behaves as you requested. .pem files are renamed to .pem.text when using sos report --clean --treat-certificates obfuscate

sos/utilities.py Outdated
:returns: The type of the certificate or ``None``
:rtype: ``string`` or ``None``
"""
if fname[-4:] in [".csr", ".pem"]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we check against .crt suffix as well? E.g. various Satellite-related certificates (though afaik neither of them being collected by sos, in neither of plenty locations) have that suffix.

(tiny update: even sosreport from Satellite can contain ./etc/pki/pulp/qpid/ca.crt until Qpid broker is deprecated in Sat)

@pmoravec
Copy link
Contributor

Apart of the .crt suffix, two nitpicks:

  • Please merge the two commits
  • The WARNING messages shall be wrapped to 80chars like e.g. print_disclaimer in sos/cleaner/__init__.py

@pafernanr pafernanr force-pushed the 3919_certificates_cleaner branch from 4126e80 to 803e6fe Compare September 15, 2025 08:22
Signed-off-by: Pablo Fernández Rodríguez <[email protected]>
@pafernanr pafernanr force-pushed the 3919_certificates_cleaner branch from 803e6fe to e506c7f Compare September 15, 2025 08:35
@TurboTurtle TurboTurtle added Reviewed/Ready for Merge Has been reviewed, ready for merge and removed Reviewed/Needs 2nd Ack Require a 2nd ack from a maintainer labels Sep 19, 2025
@TurboTurtle
Copy link
Member

LGTM, however if you could please rebase on current main to pull in the temporary disabling of Fedora tests in our suite, that will let the rest of the CI run, which does include some sanity testing for cleaner.

@TurboTurtle
Copy link
Member

Friendly reminder ping to please rebase on current main and repush so we can get a sanity run of the test suite.

@pafernanr pafernanr force-pushed the 3919_certificates_cleaner branch from 748e8ad to e506c7f Compare October 2, 2025 07:33
Copy link
Contributor

@pmoravec pmoravec left a comment

Choose a reason for hiding this comment

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

ACK, we just should drop the internal merge commit when we will do merge into upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Kind/cleaner cleaner component of sos Kind/Enhancement Reviewed/Ready for Merge Has been reviewed, ready for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants