Skip to content

Fix PSK proxy re-sync: tls_psk_identity overwritten with empty value (#141) - #145

Open
tomehb wants to merge 2 commits into
OpensourceICTSolutions:mainfrom
tomehb:fix/proxy-tls-psk-identity-writeonly
Open

tomehb wants to merge 2 commits into
OpensourceICTSolutions:mainfrom
tomehb:fix/proxy-tls-psk-identity-writeonly

Conversation

@tomehb

@tomehb tomehb commented Sep 8, 2026

Copy link
Copy Markdown

Fixes #141

Problem

Re-syncing a proxy that uses PSK encryption fails with:

ValidationError: {'tls_psk_identity': ['TLS PSK Identity must be provided when using PSK encryption.']}

Zabbix >= 5.4 does not return tls_psk_identity from proxy.get (it is write-only, the same as tls_psk). ProxySync.sync_from_zabbix() fell back to '' when the key was missing, wiping the identity that had just been pushed to Zabbix. The subsequent save() then failed full_clean() because tls_accept still contained the PSK flag.

This also broke host sync for any host behind a PSK proxy, because SyncHostJob.sync_host() syncs the proxy first and the proxy sync raised before the host was reached.

Changes

nbxsync/utils/sync/proxysync.py: tls_psk_identity now keeps the NetBox value unless Zabbix actually returns one, matching the existing write-only handling of tls_psk.

nbxsync/models/sync_info.py: update_sync_info() now falls back to a direct queryset update if save() raises ValidationError. ZabbixProxy.save() runs full_clean(), so when the sync failed because the object was invalid, the except branch's call to update_sync_info() re-ran full_clean() and raised again. The job died in the RQ failed registry and last_sync_message stayed at "Never synced", which is why the failure in #141 was invisible in the UI. The happy path is unchanged.

Tests

  • test_sync_from_zabbix_keeps_tls_psk_identity_when_not_returned: a payload without tls_psk_identity leaves the existing identity untouched.
  • test_update_sync_info_persists_when_object_fails_validation: update_sync_info(success=False, message='x') persists the message on a ZabbixProxy whose full_clean() fails.

Both new tests fail on main and pass with this branch. The two affected test modules (25 tests) pass against a NetBox install running Django 6.0.

…m Zabbix (OpensourceICTSolutions#141)

Zabbix >= 5.4 no longer returns tls_psk_identity from proxy.get, so the
previous fallback to '' wiped the identity on every re-sync and the
subsequent save() failed full_clean() for proxies using PSK encryption.
Keep the NetBox value unless Zabbix actually returns one, matching the
existing write-only handling of tls_psk.
…fails

ZabbixProxy.save() runs full_clean(), so recording a failed sync on an
object that is itself invalid raised a second ValidationError and the
message was never written. Fall back to a direct queryset update so the
outcome is always persisted. Happy path is unchanged.

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.

ProxySync.sync_from_zabbix() overwrites tls_psk_identity with empty value, breaking re-sync of proxies using PSK encryption

1 participant