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

[clean] Respect permissions of sanitised files #3292

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sos/cleaner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ def obfuscate_file(self, filename, short_name=None, arc_name=None):
% (short_name, err), caller=arc_name)
tfile.seek(0)
if subs:
shutil.copy(tfile.name, filename)
shutil.copyfile(tfile.name, filename)
tfile.close()

_ob_short_name = self.obfuscate_string(short_name.split('/')[-1])
Expand Down
18 changes: 18 additions & 0 deletions tests/cleaner_tests/basic_function_tests/report_with_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from sos_tests import StageOneReportTest, StageTwoReportTest

import re
from os import stat


class ReportWithMask(StageOneReportTest):
Expand All @@ -18,6 +19,17 @@ class ReportWithMask(StageOneReportTest):
"""

sos_cmd = '--mask -o host,networking'
hosts_obfuscated = None

def pre_sos_setup(self):
# obfuscate a random word from /etc/hosts and ensure the updated
# sanitised file has same permissions (a+r)
try:
self.hosts_obfuscated = open('/etc/hosts').read().strip('#\n').split()[-1]
except (FileNotFoundError, IndexError) as e:
self.warning(f"Unable to process /etc/hosts: {e}")
if self.hosts_obfuscated:
self.sos_cmd += f' --keywords={self.hosts_obfuscated}'

def test_mask_was_run(self):
self.assertOutputContains('Beginning obfuscation')
Expand Down Expand Up @@ -53,6 +65,12 @@ def test_mac_addrs_were_obfuscated(self):
mac = line.strip().split()[1]
assert mac.startswith('53:4f:53'), "Found unobfuscated mac addr %s" % mac

def test_perms_unchanged_on_modified_file(self):
if self.hosts_obfuscated:
imode_orig = stat('/etc/hosts').st_mode
imode_obfuscated = stat(self.get_name_in_archive('etc/hosts')).st_mode
self.assertEqual(imode_orig, imode_obfuscated)


class ReportWithCleanedKeywords(StageOneReportTest):
"""Testing for obfuscated keywords provided by the user
Expand Down