-
Notifications
You must be signed in to change notification settings - Fork 24
feat: extend phonehome facts with pseudonymization #1034
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e40da63
feat(print-phonehome): cluster/node/module ui_name
DavidePrincipi 7c2fce3
feat(print-phonehome): string pseudonymization
DavidePrincipi 1e9fc99
feat(get-facts): return additional ansible facts
DavidePrincipi ebd1114
feat(print-phonehome): user_domains facts
DavidePrincipi 5e31cc5
chore: move user_domains under cluster
DavidePrincipi 4f38553
feat(get-facts): cluster leader ID
DavidePrincipi 0acdaf2
feat(print-phonehome): available sw update status
DavidePrincipi 78cb530
feat(get-facts): node default IP address
DavidePrincipi ed68fb3
feat(print-phonehome): application FQDNs
DavidePrincipi f479091
fix(agent.facts): non-fatal with missing seed
DavidePrincipi 5eb9c5c
feat(get-facts): node creation_date
DavidePrincipi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| # | ||
| # Copyright (C) 2026 Nethesis S.r.l. | ||
| # SPDX-License-Identifier: GPL-3.0-or-later | ||
| # | ||
|
|
||
| # Fact collection helpers | ||
|
|
||
| import warnings | ||
| import uuid | ||
| import hashlib | ||
| import ipaddress | ||
|
|
||
| PSEUDO_ENFORCING = True | ||
| PSEUDO_SEED = '0000' | ||
|
|
||
| def init_pseudonymization(enforce, rdb): | ||
| global PSEUDO_ENFORCING, PSEUDO_SEED | ||
| seed = rdb.get('cluster/anon_seed') | ||
| if seed: | ||
| PSEUDO_SEED = seed | ||
| elif enforce: | ||
| warnings.warn("Generating an unstable, temporary seed for pseudonymization") | ||
| PSEUDO_SEED = str(uuid.uuid4()) | ||
| PSEUDO_ENFORCING = enforce | ||
|
|
||
| def has_subscription(rdb): | ||
| provider = rdb.hget('cluster/subscription', 'provider') | ||
| return provider in ["nscom", "nsent"] | ||
|
|
||
| def pseudo_string(val, maxlen=12): | ||
| """Calculate a stable pseudonym of the given string""" | ||
| if val and PSEUDO_ENFORCING: | ||
| hashed_val = hashlib.sha256((PSEUDO_SEED + val).encode('utf-8')).hexdigest() | ||
| return hashed_val[0:maxlen] | ||
| else: | ||
| return val | ||
|
|
||
| def pseudo_domain(val): | ||
| """Calculate a stable pseudonym of the given domain, keeping the TLD in clear text""" | ||
| if not val or not PSEUDO_ENFORCING: | ||
| return val | ||
|
|
||
| try: | ||
| domain, suffix = val.rsplit(".", 1) | ||
| return pseudo_string(domain, 8) + '.' + suffix | ||
| except ValueError: | ||
| return pseudo_string(val) | ||
|
|
||
| def pseudo_ip(val): | ||
| """Calculate a stable pseudonym of the given IPv4 or IPv6 address, | ||
| preserving only private vs public scope | ||
| """ | ||
| if not val or not PSEUDO_ENFORCING: | ||
| return val | ||
|
|
||
| try: | ||
| ip = ipaddress.ip_address(val) | ||
| except ValueError: | ||
| return val | ||
|
|
||
| digest = hashlib.sha256((PSEUDO_SEED + ip.exploded).encode('utf-8')).digest() | ||
|
|
||
| if isinstance(ip, ipaddress.IPv4Address): | ||
| if ip.is_private: | ||
| # 10.0.0.0/8 | ||
| host = int.from_bytes(digest[:3], byteorder='big') | ||
| pseudo_int = (10 << 24) | host | ||
| else: | ||
| # 1.0.0.0/8 (public) | ||
| host = int.from_bytes(digest[:3], byteorder='big') | ||
| pseudo_int = (1 << 24) | host | ||
|
|
||
| return str(ipaddress.IPv4Address(pseudo_int)) | ||
|
|
||
| else: | ||
| if ip.is_private: | ||
| # fc00::/7 (ULA) | ||
| host = int.from_bytes(digest[:15], byteorder='big') | ||
| pseudo_int = (0xfc << 120) | host | ||
| else: | ||
| # 2000::/3 (global unicast) | ||
| host = int.from_bytes(digest[:15], byteorder='big') | ||
| pseudo_int = (0x2 << 124) | host | ||
|
|
||
| return str(ipaddress.IPv6Address(pseudo_int)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.