diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2021-02-18 13:29:48 -0500 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2021-02-22 10:33:26 -0500 |
commit | beac1212fe34634e0ee218ccfaef9720b0e7e529 (patch) | |
tree | eda0c1dbb01481d60607e0e736a4c2249ba796dc | |
parent | 7ac0fdbc4a7467ffdf54a96fa4dced11a6be22ed (diff) | |
download | sos-beac1212fe34634e0ee218ccfaef9720b0e7e529.tar.gz |
[hostname_map] Fix duplicating entries of domains
The previous commit bf622ae was to address an issue where the system's
hostname would not be obfuscated if the host plugin was not run for an
sos execution (provided that it was previously run at least once to
generate the initial obfuscation).
While this commit solved that particular problem, it injected the
domains into the "intermediary" dicts used by the mapping in a way that
meant after a certain number of further subsequent runs without the host
plugin, we'd end up duplicating our TLDs.
E.G. 'example.com' being obfuscated as 'obfuscatedomain0.com' would
eventually produce 'obfuscateddomain0.com.com'.
Correct this injection to ensure consistent obfuscation regardless of
the number of future executions without the host plugin.
Related: #2406
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r-- | sos/cleaner/mappings/hostname_map.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/sos/cleaner/mappings/hostname_map.py b/sos/cleaner/mappings/hostname_map.py index bb756e5d..8739cb4e 100644 --- a/sos/cleaner/mappings/hostname_map.py +++ b/sos/cleaner/mappings/hostname_map.py @@ -51,10 +51,21 @@ class SoSHostnameMap(SoSMap): else: # strip the host name and trailing top-level domain so that # we in inject the domain properly for later string matching - _domain = '.'.join(domain.split('.')[1:-1]).strip() - if not _domain: + + # note: this is artificially complex due to our stance on + # preserving TLDs. If in the future the project decides to + # obfuscate TLDs as well somehow, then this will all become + # much simpler + _domain_to_inject = '.'.join(domain.split('.')[1:-1]) + if not _domain_to_inject: continue - self._domains[_domain] = self.dataset[domain] + for existing_domain in self.dataset.keys(): + _existing = '.'.join(existing_domain.split('.')[:-1]) + if _existing == _domain_to_inject: + _ob_domain = '.'.join( + self.dataset[existing_domain].split('.')[:-1] + ) + self._domains[_domain_to_inject] = _ob_domain self.set_initial_counts() def load_domains_from_options(self, domains): |