[PR #1095] Fix bug with updating Keycloak user attributes #3000

Open
opened 2025-11-20 08:04:38 -05:00 by saavagebueno · 0 comments
Owner

Original Pull Request: https://github.com/netbirdio/netbird/pull/1095

State: closed
Merged: No


Describe your changes

When using Keycloak as an IdP, NetBird will attempt to write the attributes wt_pending_invite and wt_account_id to the user's profile the first time they log in. This is done through the Keycloak Admin REST API via a PUT request to /admin/{realm}/users/{id}. However, an undocumented function of this API endpoint is it overwrites all attributes on the account, including the email, firstName, and lastName fields. If these fields are not specified in the request it overwrites them to blank values.

This can be replicated by creating an account in Keycloak, then logging into a NetBird instance for the first time. You will see that after login the name and email fields are now blank along with any custom attributes in the profile.

Since the Keycloak API doesn't have a PATCH endpoint, we can fix this by getting the user's profile first then appending the attributes to it.

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • Extended the README / documentation, if necessary
**Original Pull Request:** https://github.com/netbirdio/netbird/pull/1095 **State:** closed **Merged:** No --- ## Describe your changes When using Keycloak as an IdP, NetBird will attempt to write the attributes `wt_pending_invite` and `wt_account_id` to the user's profile the first time they log in. This is done through the Keycloak Admin REST API via a PUT request to `/admin/{realm}/users/{id}`. However, an undocumented function of this API endpoint is it overwrites *all* attributes on the account, including the `email`, `firstName`, and `lastName` fields. If these fields are not specified in the request it overwrites them to blank values. This can be replicated by creating an account in Keycloak, then logging into a NetBird instance for the first time. You will see that after login the name and email fields are now blank along with any custom attributes in the profile. Since the Keycloak API doesn't have a PATCH endpoint, we can fix this by getting the user's profile first then appending the attributes to it. ### Checklist - [X] Is it a bug fix - [ ] Is a typo/documentation fix - [ ] Is a feature enhancement - [ ] It is a refactor - [ ] Created tests that fail without the change (if possible) - [ ] Extended the README / documentation, if necessary
saavagebueno added the pull-request label 2025-11-20 08:04:38 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: SVI/netbird#3000