Skip to content

Add cloud-controlled key rotation via download/blobset - #1512

Draft
khyatimahendru wants to merge 37 commits into
faucetsdn:masterfrom
khyatimahendru:spotter-key-rotation
Draft

khyatimahendru wants to merge 37 commits into
faucetsdn:masterfrom
khyatimahendru:spotter-key-rotation

Conversation

@khyatimahendru

@khyatimahendru khyatimahendru commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Adds cloud-controlled credential and private key rotation over the ephemeral download/blobset channel (download://_iot_endpoint_config), allowing the cloud to provision rotated credentials or PEM private keys without retaining secret material in config or relying on heterogeneous edge device key generation.

Depends on #1511

Key changes in this PR:

  • Schema & specification (schema/download_blobset.json, schema/configuration_endpoint.json, schema/envelope.json, docs/specs/blob_updates.md): Adds BlobsetDownload, adds download to Envelope.subType, and extends EndpointConfiguration with expiry (date-time) and ephemeral key_bytes (PEM private key material delivered over non-retained QoS 0 download/blobset).
  • Python clientlib & Spotter (clientlib/python/src/udmi/core/{device.py,messaging/mqtt_messaging_client.py}): Subscribes to download/# at MQTT QoS 0, handles config.blobset.blobs._iot_endpoint_config download:// URLs (phase: "apply" -> download/blobset -> canonical JSON SHA-256 and expiry validation -> atomic 0600 key file rotation with .bak backup and key_bytes stripping before persistence -> phase: "final" and connection reset), rejecting SHA-256 mismatches or expired payloads with status 500.
  • Tests (edge/spotter/tests/test_key_rotation.py, tests/schemas/download_blobset/): Covers QoS 0 subscription, happy-path private key rotation (permissions, backup, secret stripping), SHA-256 mismatch rejection, and expired credential rejection.

Verification

  • edge/spotter/bin/run_spotter_tests unit — 106 unit tests + 3 self-tests passed (exit 0)
  • bin/gencode check — schema/code/docs/presentation hashes verified (exit 0)
  • bin/test_schema — schema fixture validation passed (exit 0)
  • bin/test_generated_classes_py — passed (exit 0)
  • pylint --rcfile=pyproject.toml src/udmi/core/device.py src/udmi/core/messaging/mqtt_messaging_client.py — 10.00/10 (exit 0)

PR Stack

# PR Branch Summary
1 #1498 named-scans Named discovery scans schema, pubber, and sequencer
2 #1487 spotter-impl Spotter UDMI discovery & PCAP trace spec compliance
3 #1511 spotter-named-scans-parity Spotter named scans & Discovery Node feature parity
4 (this PR) spotter-key-rotation Cloud-controlled key rotation via download/blobset

Author Declaration

  • I have self-reviewed this PR.

Pull request created by Gemini

…Upload

- Add schema/upload_discovery.json defining DiscoveryUpload and ScanManifest for chunked packet capture streaming over upload/discovery.
- Add 'upload' to SubType enum in schema/envelope.json and remove legacy schema/events_streams.json.
- Regenerate Java and Python schema classes, HTML documentation, and .gencode_hash.txt.
- Add schema validation fixtures under tests/schemas/upload_discovery/ and document depth: 'trace' in docs/specs/discovery.md and docs/specs/discovery_bacnet.md.
- Ensure deterministic device ID ordering in SiteModel.getDeviceIds().
…entlib

- Add --upload_pubsub_topic_id support in MqttToPubSubBridge to route subType='upload' messages to a dedicated Pub/Sub publisher with graceful shutdown draining.
- Register uufi_upload flow in UdmiServicePod and udmis/etc/local_pod.json for local upload/# pass-through.
- Add publish_upload helper to clientlib BaseManager and include upload/# in MessageConnection default subscribe topics.
- Add unit tests in MqttToPubSubBridgeTest covering upload publisher routing and shutdown.
- Add PcapUploadHandler to reassemble gzip-compressed upload/discovery chunks in order, verify terminal SHA-256 digests, and archive .pcap and scan_manifest.json artifacts to GCS or local disk.
- Exclude subType='upload' messages from RawFallbackHandler so raw PCAP chunks are never persisted in udmi_messages.
- Add udmi_pcap_captures table in PostgresManager to track capture lifecycle metadata and URIs.
- Add trigger_bacnet_trace and get_pcap_capture tools across Butler discovery, ButlerProvider, ButlerMcpServer, and ButlerClient with unit tests and schema docs.
…CAP streaming

- Enforce strict UDMI discovery depth compliance ('buckets', 'entries', 'system', 'details', 'trace') across Spotter providers and fail fast on non-canonical legacy depths.
- Emit canonical '<TYPE>/<INSTANCE>' BACnet refs, hyphenated object types and ancillary keys, explicit families.ipv4.port (47808), ARP-resolved families.ethmac, and routed MS/TP '<net>:<mac>' bindings.
- Decode BACnet/IP BVLL Forwarded-NPDU real controller IPs/ports behind BBMDs, NPDU SNET/SADR MS/TP headers, and I-Am-Router-To-Network DNET lists in PassiveFamilyProvider.
- Implement raw-socket (SOCK_RAW) BACnet Who-Is and Who-Is-Router-To-Network discovery rounds during depth: 'trace' without binding UDP 47808, and stream gzipped DiscoveryUpload chunks with SHA-256 and ScanManifest over upload/discovery.
- Update reassemble_pcap, compare_field_parity, Spotter documentation, and unit/integration test suites.
…odel

- Lazily initialize Google Cloud Storage client in PcapUploadHandler._upload_to_gcs when BUTLER_PCAP_GCS_BUCKET is set and require sha256 on terminal EOF markers.
- Guard SpotterDiscoveryManager against superseded scan generation races when active scans are cancelled or replaced.
- Preserve BACnet I-Am enrichment and routed MS/TP re-emission across passive_sec holdoff intervals and bound I-Am-Router-To-Network parsing by bvlc_len.
- Issue per-range BACnet Who-Is discovery calls instead of collapsing disjoint addrs ranges and validate Nmap target specifications.
- Collect sorted device IDs into LinkedHashSet in SiteModel.getDeviceIds() and require connection spec in ButlerProvider.trigger_bacnet_trace.
- Wrap 101-character gracefulShutdown call in MqttToPubSubBridge.java to satisfy Checkstyle LineLength (<= 100 chars).
- Code-quote protocol and compression terms (BVLL, BBMD, NPDU, MS/TP, DNET, gzip) in docs/specs/discovery.md, docs/specs/discovery_bacnet.md, and docs/tools/spotter.md for Docs Spelling Checks.
Allow discovery configurations to define multiple independent scan schedules (such as concurrent periodic and on-demand scans, or distinct scans targeting the same protocol family) under `config.discovery.scans.<scan>`, reporting per-scan status in `state.discovery.scans.<scan>` and attributing emitted events via `scan` in `events_discovery`.

Named scans declare their target protocol via `family` in `config_discovery_family`, while legacy `config.discovery.families.<family>` entries preserve implicit key-based targeting and reject mismatched `family` overrides. `DiscoveryManager` coordinates both legacy family scans and named scans across shared protocol providers with mutual exclusion, preemption, and retry backoff.
Define named scans as a standalone primary mechanism in the discovery specs, schemas, and examples rather than framing them relative to legacy `families`. Extract scan scheduling into a concrete scheduler with FIFO deferral for busy sporadic scans, periodic retry semantics without implicit start-time fallback, and non-blocking host state locking so provider callbacks cannot deadlock `stopScan()` during config updates.
# Conflicts:
#	.gencode_hash.txt
Replace host-level lock hooks with a single-monitor outbox in DiscoveryScheduler and streamline DiscoveryManagerTest around behavioral coverage. Simplify periodic scheduling to target the next upcoming grid slot and skip busy periodic slots without emitting error noise, keeping the discovery spec and schema aligned.
# Conflicts:
#	.gencode_hash.txt
#	gencode/java/udmi/schema/DiscoveryEvents.java
#	gencode/python/udmi/schema/events_discovery.py
…it interface, exclude_capture_host, and I-Am manifest counts
…scans

Introduce a dedicated schema/config_discovery_scan.json (ScanDiscoveryConfig)
with required family for discovery.scans.<name>, remove family from
schema/config_discovery_family.json so legacy discovery.families.<family>
statically forbids it, regenerate Java/Python/HTML bindings, and update
DiscoveryScheduler, DiscoverySequences, DiscoveryManagerTest, and schema
error fixtures.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant