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

[sudo] Capture sudo and sudoers debug log files #3765

Merged
merged 1 commit into from
Sep 7, 2024

Conversation

jcastill
Copy link
Member

Capture sudo and sudoers debug log files.


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-3765
  • And now you can install the packages.

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

log_file_sudoers = "/var/log/sudoers_debug"
try:
with open(config_file, 'r', encoding='UTF-8') as cfile:
for line in cfile.read().splitlines():
Copy link
Member

Choose a reason for hiding this comment

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

for line in cfile: will iterate over the file without reading the entire thing into memory at once, and will automatically split on newlines.

Comment on lines 32 to 39
words = line.split('=')
if words[0].strip() == 'Debug':
if words[1].strip() == 'sudo':
log_file_sudo = words[2].strip()
if words[1].strip() == 'sudoers.so':
log_file_sudoers = words[2].strip()
except IOError as error:
self._log_error(f'Could not open conf file {config_file}: '
f'{error}')

if not self.get_option("all_logs"):
self.add_copy_spec([log_file_sudo, log_file_sudoers])
else:
self.add_copy_spec([log_file_sudo+'*', log_file_sudoers+'*'])

Copy link
Member

Choose a reason for hiding this comment

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

log_files = ['/var/log/sudo_debug', '/var/log/sudoers_debug']
with open(config_file, 'r', encoding='UTF-8') as cfile:
    for line in cfile:
        if line.startswith('Debug'):
            log_files.append(line.split()[2])

if not self.get_option('all_logs'):
    self.add_copy_spec(log_files)
else:
    self.add_copy_spec([f"{log}*" for log in log_files]

We don't seem to actually care which file is for sudo or sudoers, as we are just passing the filepaths on regardless. With this we also get the other subsystems which are probably valuable if someone has gone through the effort of separating them out. And if the defaults don't exist, add_copy_spec() gracefully skips them.

With the above, we also don't spuriously split the line before we determine if we care about the line by it being started with the Debug keyword. Also, on my Fedora and RHEL boxes locally none of the config files use = as a delimiter, so not sure why we want to split on that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice, I'll make these changes.
Regarding the = that was an oversight on my side when copying from another plugin. Fixed in the next force push.

Capture sudo and sudoers debug log files.

Signed-off-by: Jose Castillo <[email protected]>
@arif-ali
Copy link
Member

arif-ali commented Sep 2, 2024

/packit rebuild-failed

@TurboTurtle TurboTurtle merged commit 8fab338 into sosreport:main Sep 7, 2024
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants