From beac1212fe34634e0ee218ccfaef9720b0e7e529 Mon Sep 17 00:00:00 2001 From: Jake Hunsaker Date: Thu, 18 Feb 2021 13:29:48 -0500 Subject: [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 --- sos/cleaner/mappings/hostname_map.py | 17 ++++++++++++++--- 1 file 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): -- cgit