Privacy hardening, remote-peer IP masking and review fixes

- Add privacy projection (core/privacy.py), private report storage, bounded
  process capture; omit identities, free text and unapproved paths
- Mask remote peer IPs: only loopback/host/wildcard stay numeric, others are
  reduced to remote_scope private/public (schema + scoring updated)
- Map ss TCP states to canonical names; ASCII-only numeric fields; fix
  "Microsoft Visual C++" product matching (Python and PowerShell)
- Merge 7fed3b9: -Diagnostic switch, serialization exit code 3, PS7 module
  path, UI error detail; keep hardened task/certificate collectors
- Add audit docs, privacy docs and regression tests

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-04 18:50:24 -08:00
parent 7fed3b9ab9
commit 610a3bb447
51 changed files with 2719 additions and 604 deletions

View File

@@ -13,6 +13,18 @@ def inventory_schema():
def validate_inventory(data):
# Validate depth and timestamps without optional third-party format plugins.
from samsara.core.privacy import safe_time
def visit(value, depth=0):
if depth>20: raise ValueError('Inventory nesting exceeds its limit.')
if isinstance(value,dict):
for key,item in value.items():
if key in ('collected_at','started_at','completed_at','activity_observed_at') and safe_time(item) is None:
raise ValueError('Inventory timestamp is invalid.')
visit(item,depth+1)
elif isinstance(value,list):
for item in value: visit(item,depth+1)
visit(data)
validator = Draft202012Validator(inventory_schema(), format_checker=FormatChecker())
if not validator.is_valid(data):
raise ValueError('Inventory does not match the v1 schema; required fields, types or check statuses are invalid.')
@@ -32,10 +44,6 @@ SERVER_FIELDS = {'hostname', 'platform', 'operating_system', 'os_version', 'os_b
def restrict_inventory_fields(data, local_source=None):
"""Keep only metadata fields; never serialize raw CIM/task/service objects."""
data["server"] = {key: value for key, value in data["server"].items() if key in SERVER_FIELDS}
if local_source:
data["server"]["collection_source"] = local_source
data["inventory"] = {section: [{key: value for key, value in row.items() if key in ALLOWED[section]}
for row in rows] for section, rows in data["inventory"].items()}
return data
"""Compatibility entry point: all callers now receive the privacy projection."""
from samsara.core.privacy import minimize_inventory
return minimize_inventory(data, trusted_source=local_source)