Skip to content

Fix EncryptedValue handling in lookup adapters#25244

Open
danotorrey wants to merge 3 commits intomasterfrom
fix/lookup-adapter-serialization
Open

Fix EncryptedValue handling in lookup adapters#25244
danotorrey wants to merge 3 commits intomasterfrom
fix/lookup-adapter-serialization

Conversation

@danotorrey
Copy link
Contributor

@danotorrey danotorrey commented Mar 6, 2026

Summary

Fixes two issues when editing lookup data adapters with encrypted fields (API tokens, passwords):

  1. Deserialization error on edit — Opening an existing adapter shows: "Couldn't deserialize value: {"is_set":true} (set_value must be a string and cannot be missing)" because a Formik validation race condition sends raw {"is_set": true} to the server before the form can convert it.

  2. Encrypted values silently cleared on save — Saving an adapter without resetting its token/password clears the encrypted value to {"is_set": false} because the backend never merges {"keep_value": true} with the existing DB record. This has existed since adapters first used EncryptedValue (~2021).

Affects all adapters with encrypted fields: GreyNoise Quick IP (api_token), GreyNoise Full IP (api_token), and LDAP (user_passwd).

Frontend: Add prepareConfig plugin hook to convert encrypted values synchronously before Formik initialization, preventing the race condition. Applied to GreyNoise Quick IP; removed LDAP-specific workaround from AdapterTypeSelect.

Backend: Add prepareConfigUpdate() to LookupDataAdapterConfiguration (same pattern as EventNotificationConfig.prepareConfigUpdate()) and call it in LookupTableResource.updateAdapter() to merge encrypted values from the existing DB record. Override in GreyNoiseQuickIPDataAdapter.Config.

See https://github.com/Graylog2/graylog-plugin-enterprise/pull/13445 for enterprise-side changes (GreyNoise Full IP + LDAP).

Test plan

  • Edit an existing adapter with a set token/password, save without resetting — value is preserved
  • Edit an existing adapter, reset and set a new token/password — new value is saved
  • Edit an existing adapter, reset and leave empty — value is cleared
  • Create a new GreyNoise Quick IP Lookup adapter — form works normally
  • Edit an existing LDAP adapter (with enterprise plugin changes) — no deserialization error

danotorrey and others added 3 commits March 5, 2026 21:10
Add `prepareConfig` plugin hook to transform EncryptedValue fields
before they enter Formik state. This prevents the auto-validation
useEffect from sending raw `{"is_set": true}` to the server, which
fails deserialization.

The Formik migration in AdapterFormFields introduced a validation
useEffect that fires before child fieldset effects can convert
encrypted values. Moving the conversion to a synchronous useMemo
in AdapterForm ensures values are transformed before any validation.
The LookupTableResource.updateAdapter() method was saving adapter configs
directly without merging EncryptedValue fields. When the client sent
{"keep_value": true}, the value was lost because the existing encrypted
value was never fetched from the database.

Add prepareConfigUpdate() to LookupDataAdapterConfiguration following the
same pattern as EventNotificationConfig.prepareConfigUpdate(). Override it
in GreyNoiseQuickIPDataAdapter.Config to preserve api_token on update.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@danotorrey danotorrey changed the title Fix EncryptedValue serialization in lookup adapter forms Fix EncryptedValue handling in lookup adapters Mar 6, 2026
@danotorrey danotorrey requested review from dennisoelkers and zeeklop and removed request for dennisoelkers March 6, 2026 22:20
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