|
|
89c8f0 |
From 7e471676fe41dab155a939c60446cc7b7dab773b Mon Sep 17 00:00:00 2001
|
|
|
89c8f0 |
From: Jake Hunsaker <jhunsake@redhat.com>
|
|
|
89c8f0 |
Date: Tue, 20 Jul 2021 11:09:29 -0400
|
|
|
89c8f0 |
Subject: [PATCH] [username parser] Load usernames from `last` for LDAP users
|
|
|
89c8f0 |
|
|
|
89c8f0 |
AD/LDAP users are not reported into `lastlog` generally, however they
|
|
|
89c8f0 |
are reported in `last`. Conversely, `last` does not report local users
|
|
|
89c8f0 |
who have not logged in but still exist.
|
|
|
89c8f0 |
|
|
|
89c8f0 |
In order to obfuscate both kinds of users, we need to look at both
|
|
|
89c8f0 |
sources.
|
|
|
89c8f0 |
|
|
|
89c8f0 |
For this, first allow parsers to specify multiple prep files. Second,
|
|
|
89c8f0 |
update the username parser to search through all `lastlog` collections
|
|
|
89c8f0 |
as well as the `last` collection.
|
|
|
89c8f0 |
|
|
|
89c8f0 |
Also includes a small update to the username parser's prep loading logic
|
|
|
89c8f0 |
to ensure we are iterating over each username discovered only once.
|
|
|
89c8f0 |
|
|
|
89c8f0 |
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
|
|
|
89c8f0 |
---
|
|
|
89c8f0 |
sos/cleaner/__init__.py | 38 ++++++++++++++------------
|
|
|
89c8f0 |
sos/cleaner/parsers/__init__.py | 2 +-
|
|
|
89c8f0 |
sos/cleaner/parsers/username_parser.py | 24 +++++++++++++---
|
|
|
89c8f0 |
3 files changed, 42 insertions(+), 22 deletions(-)
|
|
|
89c8f0 |
|
|
|
89c8f0 |
diff --git a/sos/cleaner/__init__.py b/sos/cleaner/__init__.py
|
|
|
89c8f0 |
index ca5f93e5..6aadfe79 100644
|
|
|
89c8f0 |
--- a/sos/cleaner/__init__.py
|
|
|
89c8f0 |
+++ b/sos/cleaner/__init__.py
|
|
|
89c8f0 |
@@ -518,23 +518,27 @@ third party.
|
|
|
89c8f0 |
for _parser in self.parsers:
|
|
|
89c8f0 |
if not _parser.prep_map_file:
|
|
|
89c8f0 |
continue
|
|
|
89c8f0 |
- _arc_path = os.path.join(_arc_name, _parser.prep_map_file)
|
|
|
89c8f0 |
- try:
|
|
|
89c8f0 |
- if is_dir:
|
|
|
89c8f0 |
- _pfile = open(_arc_path, 'r')
|
|
|
89c8f0 |
- content = _pfile.read()
|
|
|
89c8f0 |
- else:
|
|
|
89c8f0 |
- _pfile = archive.extractfile(_arc_path)
|
|
|
89c8f0 |
- content = _pfile.read().decode('utf-8')
|
|
|
89c8f0 |
- _pfile.close()
|
|
|
89c8f0 |
- if isinstance(_parser, SoSUsernameParser):
|
|
|
89c8f0 |
- _parser.load_usernames_into_map(content)
|
|
|
89c8f0 |
- for line in content.splitlines():
|
|
|
89c8f0 |
- if isinstance(_parser, SoSHostnameParser):
|
|
|
89c8f0 |
- _parser.load_hostname_into_map(line)
|
|
|
89c8f0 |
- self.obfuscate_line(line)
|
|
|
89c8f0 |
- except Exception as err:
|
|
|
89c8f0 |
- self.log_debug("Could not prep %s: %s" % (_arc_path, err))
|
|
|
89c8f0 |
+ if isinstance(_parser.prep_map_file, str):
|
|
|
89c8f0 |
+ _parser.prep_map_file = [_parser.prep_map_file]
|
|
|
89c8f0 |
+ for parse_file in _parser.prep_map_file:
|
|
|
89c8f0 |
+ _arc_path = os.path.join(_arc_name, parse_file)
|
|
|
89c8f0 |
+ try:
|
|
|
89c8f0 |
+ if is_dir:
|
|
|
89c8f0 |
+ _pfile = open(_arc_path, 'r')
|
|
|
89c8f0 |
+ content = _pfile.read()
|
|
|
89c8f0 |
+ else:
|
|
|
89c8f0 |
+ _pfile = archive.extractfile(_arc_path)
|
|
|
89c8f0 |
+ content = _pfile.read().decode('utf-8')
|
|
|
89c8f0 |
+ _pfile.close()
|
|
|
89c8f0 |
+ if isinstance(_parser, SoSUsernameParser):
|
|
|
89c8f0 |
+ _parser.load_usernames_into_map(content)
|
|
|
89c8f0 |
+ for line in content.splitlines():
|
|
|
89c8f0 |
+ if isinstance(_parser, SoSHostnameParser):
|
|
|
89c8f0 |
+ _parser.load_hostname_into_map(line)
|
|
|
89c8f0 |
+ self.obfuscate_line(line)
|
|
|
89c8f0 |
+ except Exception as err:
|
|
|
89c8f0 |
+ self.log_debug("Could not prep %s: %s"
|
|
|
89c8f0 |
+ % (_arc_path, err))
|
|
|
89c8f0 |
|
|
|
89c8f0 |
def obfuscate_report(self, report):
|
|
|
89c8f0 |
"""Individually handle each archive or directory we've discovered by
|
|
|
89c8f0 |
diff --git a/sos/cleaner/parsers/__init__.py b/sos/cleaner/parsers/__init__.py
|
|
|
89c8f0 |
index 3076db39..af6e375e 100644
|
|
|
89c8f0 |
--- a/sos/cleaner/parsers/__init__.py
|
|
|
89c8f0 |
+++ b/sos/cleaner/parsers/__init__.py
|
|
|
89c8f0 |
@@ -50,7 +50,7 @@ class SoSCleanerParser():
|
|
|
89c8f0 |
skip_line_patterns = []
|
|
|
89c8f0 |
skip_files = []
|
|
|
89c8f0 |
map_file_key = 'unset'
|
|
|
89c8f0 |
- prep_map_file = 'unset'
|
|
|
89c8f0 |
+ prep_map_file = []
|
|
|
89c8f0 |
|
|
|
89c8f0 |
def __init__(self, conf_file=None):
|
|
|
89c8f0 |
# attempt to load previous run data into the mapping for the parser
|
|
|
89c8f0 |
diff --git a/sos/cleaner/parsers/username_parser.py b/sos/cleaner/parsers/username_parser.py
|
|
|
89c8f0 |
index 96ce5f0c..b142e371 100644
|
|
|
89c8f0 |
--- a/sos/cleaner/parsers/username_parser.py
|
|
|
89c8f0 |
+++ b/sos/cleaner/parsers/username_parser.py
|
|
|
89c8f0 |
@@ -25,13 +25,24 @@ class SoSUsernameParser(SoSCleanerParser
|
|
|
89c8f0 |
|
|
|
89c8f0 |
name = 'Username Parser'
|
|
|
89c8f0 |
map_file_key = 'username_map'
|
|
|
89c8f0 |
- prep_map_file = 'sos_commands/login/lastlog_-u_1000-60000'
|
|
|
89c8f0 |
+ prep_map_file = [
|
|
|
89c8f0 |
+ 'sos_commands/login/lastlog_-u_1000-60000',
|
|
|
89c8f0 |
+ 'sos_commands/login/lastlog_-u_60001-65536',
|
|
|
89c8f0 |
+ 'sos_commands/login/lastlog_-u_65537-4294967295',
|
|
|
89c8f0 |
+ # AD users will be reported here, but favor the lastlog files since
|
|
|
89c8f0 |
+ # those will include local users who have not logged in
|
|
|
89c8f0 |
+ 'sos_commands/login/last'
|
|
|
89c8f0 |
+ ]
|
|
|
89c8f0 |
regex_patterns = []
|
|
|
89c8f0 |
skip_list = [
|
|
|
89c8f0 |
'core',
|
|
|
89c8f0 |
'nobody',
|
|
|
89c8f0 |
'nfsnobody',
|
|
|
89c8f0 |
- 'root'
|
|
|
89c8f0 |
+ 'shutdown',
|
|
|
89c8f0 |
+ 'reboot',
|
|
|
89c8f0 |
+ 'root',
|
|
|
89c8f0 |
+ 'ubuntu',
|
|
|
89c8f0 |
+ 'wtmp'
|
|
|
89c8f0 |
]
|
|
|
89c8f0 |
|
|
|
89c8f0 |
def __init__(self, conf_file=None, opt_names=None):
|
|
|
89c8f0 |
@@ -44,11 +54,17 @@ class SoSUsernameParser(SoSCleanerParser):
|
|
|
89c8f0 |
"""Since we don't get the list of usernames from a straight regex for
|
|
|
89c8f0 |
this parser, we need to override the initial parser prepping here.
|
|
|
89c8f0 |
"""
|
|
|
89c8f0 |
+ users = set()
|
|
|
89c8f0 |
for line in content.splitlines()[1:]:
|
|
|
89c8f0 |
- user = line.split()[0]
|
|
|
89c8f0 |
+ try:
|
|
|
89c8f0 |
+ user = line.split()[0]
|
|
|
89c8f0 |
+ except Exception:
|
|
|
89c8f0 |
+ continue
|
|
|
89c8f0 |
if user in self.skip_list:
|
|
|
89c8f0 |
continue
|
|
|
89c8f0 |
- self.mapping.get(user)
|
|
|
89c8f0 |
+ users.add(user)
|
|
|
89c8f0 |
+ for each in users:
|
|
|
89c8f0 |
+ self.mapping.get(each)
|
|
|
89c8f0 |
|
|
|
89c8f0 |
def parse_line(self, line):
|
|
|
89c8f0 |
count = 0
|
|
|
89c8f0 |
--
|
|
|
89c8f0 |
2.31.1
|
|
|
89c8f0 |
|