Skip to content

realm_client is computed into a client's attributes and then persisted on save #52173

Closed

Description

@xgp

Before reporting an issue

  • I have read and understood the above terms for submitting issues, and I understand that my issue may be closed without action if I do not follow them.

Area

admin/api

Describe the bug

ModelToRepresentation.toRepresentation(ClientModel, KeycloakSession) inserts a computed
entry into the client's attribute map:

rep.getAttributes().put(Constants.REALM_CLIENT,
        String.valueOf(isRealmClient(clientModel.getClientId(), clientModel.getRealm(), session)));

(Constants.REALM_CLIENT is "realm_client".)

Nothing ever stored that attribute — it is derived from the clientId and the realm. But
RepresentationToModel.updateClient copies rep.getAttributes() into the model wholesale, so a
plain read-modify-write of a client persists it.

That is exactly what the admin console does on every save, so in practice every client an
administrator has ever edited carries a stored realm_client attribute that was computed rather
than configured.

Version

26.7.1

Regression

  • The issue is a regression

Expected behavior

reading a client and writing it back unchanged changes nothing

Actual behavior

it persists a derived attribute

How to Reproduce?

CID=$(kcadm.sh get clients -r demo -q clientId=account --fields id --format csv --noquotes)

kcadm.sh get clients/$CID -r demo > client.json     # note: attributes.realm_client is present
kcadm.sh update clients/$CID -r demo -f client.json # write it straight back, changing nothing

Then look at the client's stored attributes (for example in CLIENT_ATTRIBUTES): realm_client
is now a row, where before the round trip it was not.

Anything else?

It is harmless at runtime, because every read recomputes the value. It matters to anything that
compares a client with itself — export/import diffing, GitOps-style config management, drift
detection — because a no-op save produces a real change. It also means the attribute can go
stale: it is written once and never recomputed on disk, so a stored realm_client=false survives
even if the answer would now be different.

Suggested fix

Either exclude Constants.REALM_CLIENT when RepresentationToModel.updateClient copies
attributes, or move it out of attributes and onto ClientRepresentation as a read-only field
so that it cannot be written back. The first is the smaller change and keeps the representation
compatible.

Activity

  1. added
    kind/bug
    on Aug 28, 2026
  2. added theissue type on Aug 28, 2026
  3. added
    area/admin/api
    on Aug 28, 2026
  4. added a commit that references this issue on Aug 31, 2026
    1e3472b
  5. added
    priority/important
    on Aug 31, 2026
  6. ahus1 commented on Aug 31, 2026

    @ahus1
    Member

    @xgp - thank you for the fix. Please provide a backport for the release/26.7 release branch so we can include this in an upcoming patch release.

    Pinging @mposolda and @graziang for visibility as this is a regression from #29413

  7. xgp commented on Aug 31, 2026

    @xgp
    ContributorAuthor
  8. added a commit that references this issue on Aug 31, 2026
    337454e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Fields

    No fields configured for bug.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions