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

Closed
opened 2026-08-05 02:08:04 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/1095
Author: @Alpha5k
Created: 8/18/2023
Status: Closed

Base: mainHead: main


📝 Commits (1)

  • f7ae6f5 Fix bug with updating Keycloak user attributes

📊 Changes

1 file changed (+17 additions, -7 deletions)

View changed files

📝 management/server/idp/keycloak.go (+17 -7)

📄 Description

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/1095 **Author:** [@Alpha5k](https://github.com/Alpha5k) **Created:** 8/18/2023 **Status:** ❌ Closed **Base:** `main` ← **Head:** `main` --- ### 📝 Commits (1) - [`f7ae6f5`](https://github.com/netbirdio/netbird/commit/f7ae6f5b0e8ac954b33cd41dbab1cd4688fe82a3) Fix bug with updating Keycloak user attributes ### 📊 Changes **1 file changed** (+17 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `management/server/idp/keycloak.go` (+17 -7) </details> ### 📄 Description ## 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 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 02:08:04 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#13309