Skip to content

Preserve device credentials in registrar on settings validation errors - #1496

Merged
jamiebrind merged 4 commits into
faucetsdn:masterfrom
jamiebrind:fix-registrar-credentials-on-settings-error
Dec 1, 2026
Merged

jamiebrind merged 4 commits into
faucetsdn:masterfrom
jamiebrind:fix-registrar-credentials-on-settings-error

Conversation

@jamiebrind

Copy link
Copy Markdown
Collaborator

When LocalDevice.validateMetadata() threw a ValidationError (e.g. from validatePointTypes() in #1469), Registrar.initializeDevices() returned early before configure() and loadCredentials(), then still pushed UPDATE with credentials: []. In ZanzaraIotAccessProvider, the metadata.key_bytes fallback then overwrote auth_key with the private key bytes, breaking MQTT auth. Devices with settings errors now still report ERROR under settings while preserving their public key credentials.

Changes
LocalDevice.initialize(): call configure() before validateMetadata().
Registrar.initializeDevices(): remove the early return on settings errors so loadCredentials() and validateEnvelope() still run.
ZanzaraIotAccessProvider.toDeviceMap(): remove the metadata.key_bytes fallback into auth_key.
Tests: RegistrarTest.credentialsPreservedOnSettingsErrorTest and ZanzaraIotAccessProviderTest.testMetadataKeyBytesDoesNotOverwriteAuthKey.

…ting key_bytes to auth_key

Previously, when LocalDevice.validateMetadata() threw a ValidationError (e.g. from validatePointTypes), LocalDevice.initialize() exited before configure() and Registrar.initializeDevices() returned early, skipping loadCredentials(). Registrar then pushed UPDATE with empty credentials alongside metadata.key_bytes (the base64 PKCS#8 private key), and ZanzaraIotAccessProvider.toDeviceMap() wrote metadata.key_bytes into auth_key when credentials were empty—corrupting broker public keys.

- Call configure() before validateMetadata() in LocalDevice.initialize()
- Remove early return in Registrar.initializeDevices() so loadCredentials() still runs after settings validation errors
- Remove metadata.key_bytes fallback into auth_key in ZanzaraIotAccessProvider.toDeviceMap()
- Add unit tests in RegistrarTest and ZanzaraIotAccessProviderTest
@jamiebrind
jamiebrind requested a review from grafnu November 19, 2026 14:49
@noursaidi

Copy link
Copy Markdown
Collaborator

I think registrar needs to be updated too so that the private key is never transmitted to the cloud. An empty credential is also a valid case, and should result in credentials being removed if set. Are there tests which verify this behaviour?

@grafnu grafnu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Nour's comments about private keys is more important than mine. Is that something that's in-scope for this PR or is that getting out of hand? (The goal is to try and slowly improve the system, but not to make this PR stall out if it's unrelated...)

Jamie Brind added 2 commits November 25, 2026 12:39
…dentials-on-settings-error

# Conflicts:
#	udmis/src/main/java/com/google/bos/udmi/service/access/ZanzaraIotAccessProvider.java
#	udmis/src/test/java/com/google/bos/udmi/service/access/ZanzaraIotAccessProviderTest.java
#	validator/src/test/java/com/google/daq/mqtt/registrar/RegistrarTest.java
@jamiebrind

Copy link
Copy Markdown
Collaborator Author

I think Nour's comments about private keys is more important than mine. Is that something that's in-scope for this PR or is that getting out of hand? (The goal is to try and slowly improve the system, but not to make this PR stall out if it's unrelated...)

I don't think its in scope of this PR. @noursaidi how would we send keys to Zanzara if its not through Registrar. Or would we just send the public key, not the private.

@grafnu

grafnu commented Nov 25, 2026 via email

Copy link
Copy Markdown
Collaborator

@jamiebrind

jamiebrind commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator Author

@grafnu I can remove them uploading in this same PR, or create a new one..... should be a simple fix.

@grafnu

grafnu commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

@jamiebrind -- I'd like to move this through or move it to draft, or close it out, any outstanding blockers you need help with?

@jamiebrind

jamiebrind commented Nov 30, 2026 via email

Copy link
Copy Markdown
Collaborator Author

@jamiebrind

Copy link
Copy Markdown
Collaborator Author

I think registrar needs to be updated too so that the private key is never transmitted to the cloud. An empty credential is also a valid case, and should result in credentials being removed if set. Are there tests which verify this behaviour?

We can discuss this and create another PR as I believe this is out of scope for this PR.

…dentials-on-settings-error

# Conflicts:
#	udmis/src/test/java/com/google/bos/udmi/service/access/ZanzaraIotAccessProviderTest.java
@jamiebrind
jamiebrind merged commit b9cb17a into faucetsdn:master Dec 1, 2026
30 checks passed
@jamiebrind
jamiebrind deleted the fix-registrar-credentials-on-settings-error branch December 1, 2026 11:25
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.

3 participants