Keycloak user profile and custom user attributes

How to define the attributes Keycloak stores for each user with the declarative user profile, including validation, required fields per context, view and edit permissions and unmanaged attributes.

On this page

Keycloak user profile: which user attributes you need and when to define them

The declarative user profile is Keycloak's mechanism for deciding which attributes each user record holds, how those values are validated, and which fields are required in each context. Identity teams need it once department, employee ID, locale or customer tier must be consistent across every application that signs users in, because without a single definition each client tends to invent its own copy of the data. The profile governs more than storage: it also controls who can view and edit each attribute, so the same definition answers both the data-quality question and the access question. It is configured in the realm's user profile settings, which the Keycloak server administration guide documents.

Start with a list of attributes that applications actually read from tokens or make decisions on, and write down, for each one, where its value comes from (the user, an administrator, an upstream identity provider or an HR system). Then decide the context in which each field matters: user self-registration, the account console, administrator editing, or identity provider first login. A field that is mandatory at registration but unavailable to users in the account console will cause support tickets, so the required-per-context decision should be made attribute by attribute. Confirm in your target release which validators and permission settings are available, since these are the parts most likely to be tested in a security review.

Keep the attribute list short at the start. Every attribute you define becomes something that must be validated, documented, mapped into tokens where needed and reviewed when the profile changes. Attributes that no application consumes are better left out until a consumer exists. Before the build starts, ask your partner or internal team to confirm the attribute inventory, the owner of each value, and the upgrade test that will cover profile changes after each Keycloak minor release.

Configuration options for user profile attributes and when each fits

This table compares the main settings Keycloak's declarative user profile offers for each custom attribute, with the situations each one suits and what it costs to change later. Read each row as a decision: pick the setting that matches who needs the data and where it must appear, then check the change cost before the attribute reaches production users. Changes to attribute names and types are the costliest to undo once data exists.

SettingWhen it fitsCost to change later
Attribute name and display labelStable identifiers that tokens, applications and directory sync depend on, plus labels users read on formsRenaming an attribute strands existing values and breaks mappers and clients that read the old name; relabeling is low cost
ValidatorsFormat, length or allowed-value rules such as email shape, phone format or a fixed list of departmentsTightening a validator can leave existing users with values that fail on their next save; plan a data check first
Required per contextFields that must exist for admin-created users, self-registration or account updates, which can differ by contextAdding a requirement forces existing users to supply data at their next sign-in; test each context separately
View permission by role (user, admin)Data users should see about themselves, such as a display preference, while internal fields stay hiddenLow cost to change, but applications reading the attribute from tokens may need mapper updates if visibility shifts
Edit permission by role (user, admin)Fields users may correct themselves versus fields only administrators or HR-driven processes should changeMoving edit rights to admins later creates support load and may need a process change; confirm who owns the data
Unmanaged attribute policy (disabled, enabled, admin-edit, admin-view)Disabled suits strict schemas; the other options fit legacy data or quick prototypes that must store extra values without declaring themEnabling unmanaged attributes later is easy, but removing them after apps depend on them is hard; confirm the exact option behavior in the current docs
Group-based attribute visibilityAttributes that only certain groups, such as support staff or a regional team, should read or editGroup membership changes are ongoing work; the cost is in keeping group design and attribute rules aligned
Registration form inclusionData needed at sign-up, such as a company code or accepted terms reference, collected once from new usersAdding a field to the form does not backfill existing users, so plan a separate collection path for them

Setting up custom user attributes in Keycloak step by step

This sequence takes custom attributes from an inventory of what applications need to a tested user profile, with each step ending in a check that the attribute behaves as intended in every place it appears.

  1. Inventory the attributes each application needs

    Start by listing every piece of user data that an application, process or downstream system reads today or will read after launch, such as department, cost center, preferred language or a customer reference. For each item, record which application uses it, whether it is needed at sign-in, and whether it already lives in an HR or directory system. Review the list with the application owners and the identity team together. The step is done when every attribute has a named consumer and a named source of truth, and any attribute with no consumer is removed from scope.

  2. Assign ownership and sensitivity to each attribute

    For each attribute, decide who is allowed to set it (the user, an administrator, or a synchronized source such as a directory), who may view it, and how sensitive it is under your data classification policy. Attributes sourced from HR or a directory should usually be read-only in Keycloak so that the source of truth stays authoritative. Write these decisions in a short table that the security and compliance reviewers can sign off. The step is done when the table exists, has an owner for every row, and has been approved by the people responsible for personal data.

  3. Define attributes in the user profile on a non-production realm

    Open the realm settings in a non-production realm, go to the user profile configuration, and add each attribute with its display name and attribute key. The declarative user profile is stored as configuration, so keep the JSON under version control and apply changes through the same path you use for other realm configuration. Do not create attributes first in a production realm and tidy up later. The step is done when a test user can be created with the new attributes present in the admin console and the exported profile configuration matches the table from the previous step.

  4. Set validation rules and required contexts

    For each attribute, configure the validators that match its format, such as length, pattern or email, and set whether it is required in each context: user administration, self-registration, and the account console where applicable. Required in one context but optional in another is a common design, for example an HR-synced attribute that administrators must fill in but users never edit. Test the validators with both valid and invalid sample values. The step is done when an invalid value is rejected with a clear message in the admin console and in the account console, and a missing required field blocks saving in each context you configured.

  5. Set view and edit permissions per attribute

    Assign the permissions you decided in the second step to each attribute for each role that touches the profile. Give the user role edit rights only where the user should change the value, give administrators the access they need, and make sure attributes that should stay private are not visible to self-service pages. Permissions must be checked in each surface separately, because the account console, the registration form and the admin console can behave differently. The step is done when you have signed in as a user with each role and confirmed that visible fields and editable fields match the permission table exactly.

  6. Decide whether unmanaged attributes are needed

    Keycloak can store attributes that are not in the user profile, called unmanaged attributes, and their handling is controlled per realm with a policy. Use managed attributes for any value your applications depend on, because they receive validation, permissions and consistent display. Enable unmanaged attributes only where a specific integration needs free-form data, and document the reason and the policy setting. If you enable them, confirm which pages show them and whether users can edit them. The step is done when every unmanaged attribute in use is listed with a justification and its visibility has been tested.

  7. Expose attributes to tokens with protocol mappers

    For each attribute an application must read, add a user attribute protocol mapper to the relevant client or client scope, set the claim name the application expects, and choose whether the claim goes into the ID token, access token or userinfo response. Include only the claims that each client needs, because every extra claim is visible to the application that receives the token. Sign in as a test user through the application and decode the token in a test environment to confirm the claim appears with the expected name and value. The step is done when the claim is present for the intended client and absent from clients that should not receive it.

  8. Test registration, account and admin flows end to end

    Run a scripted set of test cases covering self-registration with a new user, a profile edit in the account console, an administrator edit in the admin console, a missing required value, an invalid value and a token check for each mapped claim. Record the results against the attribute table so each row is marked as passed for every surface where it appears. Repeat the tests after any change to the profile configuration, theme or mapper, because those changes can alter what users see. The step is done when all cases pass in the non-production realm and the same configuration has been exported ready for promotion.

How attributes flow from the user profile to the login, account and token

The flow starts with the user profile definition, which sets each attribute's validation, required state and per-context visibility. That definition shapes the registration and login forms, the account console and the admin console, where users and administrators read and edit values. Protocol mappers then decide which stored attributes appear as claims in the token a client receives. Unmanaged attributes follow a separate path that bypasses the profile, so check whether each one is intended to reach a token before relying on it.

Attribute flow from the declarative user profile to forms, consoles and client tokens.

Security risks in user attribute design

User attributes look like harmless profile data, but in Keycloak they feed tokens, self-service screens and admin workflows. The risks below share one root cause: an attribute's visibility, editability and trust level are set by its profile configuration, and a permissive default in any of these areas can expose data or let a user change something that decides access.

Sensitive attributes visible to users

Attributes set with a view permission broader than needed appear in self-service views and can reach client applications through token mappers. Keep internal notes, risk scores, HR identifiers and vetting flags out of the user-facing context entirely, and set the view and edit permissions per context. Check the account console and each client's token contents with a test user to confirm that nothing sensitive appears where a user or relying party can read it.

Keycloak docs

Users editing authorization attributes

If a user can edit an attribute such as role, tier, plan or department, and an application or mapper trusts that value, the user can grant themselves access. Mark these attributes as admin-only edit, and do not map them into tokens as a basis for authorization unless the source is a trusted admin or federation process. Verify with a non-admin test account that the account console and registration form reject writes to these fields.

Keycloak docs

Unmanaged attributes accepting arbitrary input

Unmanaged attributes let users store values that the user profile does not declare, so no validator runs on them. Any application that reads such a value without its own checks inherits whatever the user typed. Keep unmanaged attribute handling disabled unless a specific use case requires it, and if you enable it, restrict who can edit those values and ensure no authorization decision depends on them. Confirm in the admin console that unmanaged attributes are off for each realm you run.

Personal data minimization

Every attribute you declare is personal data you must protect, back up, export and eventually delete. Collect only the fields a service needs, make optional fields optional on every context, and avoid storing values that a federated identity provider already holds. Review the attribute list against your data processing purpose before go-live, and confirm that tokens carry only the claims each client requires.

Audit trail for admin edits

When an administrator changes a user's attributes, the change should be attributable and reviewable. Enable admin event logging with details for the realm, and forward those events to your log platform so that changes to privileged attributes can be traced to a named administrator. Test by editing a test user's attribute as an admin and confirming the event appears with the actor, the target user and the changed field.

Attribute values in logs and exports

Attribute values can leak through application logs, event listeners, backups and admin exports even when the console hides them. Decide which attributes may appear in event payloads, mask sensitive values in any custom listener or integration, and restrict access to exported realm data. Verify by triggering an attribute change and searching your log and event pipelines for the test value.

Questions teams ask before defining user attributes

What makes the cost of defining Keycloak user attributes go up?

The biggest drivers are the number of attributes, how many contexts each one must behave differently in, and how many applications read them. Every attribute needs a validation rule, a required-or-optional decision for registration, the account console and admin console, and a view and edit permission for each audience. Cost also rises when attributes must be synchronized from an HR system or directory, because the mapping, conflict handling and test cases multiply. Ask any partner to show the attribute inventory and the contexts it covers before they quote, so the scope is written down rather than assumed.

How does user federation change the work for user attributes?

When users come from LDAP, Active Directory or an upstream identity provider, some attributes are owned by that source and cannot be edited in Keycloak. The work then includes deciding which attributes Keycloak mirrors, which it stores locally, and how mappers handle updates on each login or sync. Each federated attribute adds a test case for first login, change in the source, and removal in the source. Confirm with the directory owner which fields are authoritative before the Keycloak profile is designed, because a field edited in the wrong place will be overwritten.

How many applications consuming claims affect the effort?

Every application that reads an attribute from the token adds a claim mapping, a client scope decision and a test. Attributes that reach tokens also need a review for data minimization, because a claim sent to a public client is visible to anyone who holds the token. A small set of internal applications is usually simple to cover. Many applications with different claim formats, or with a mix of public and confidential clients, take more time to test and document. Ask for a list of consuming applications with the claims each one expects.

Do theme and registration form changes add to the work?

Yes. Showing a new attribute on the registration page or in the account console means the user profile definition and the theme templates must agree. A theme that was written against one set of fields will need updating when fields are added, renamed or made required. Custom registration logic, such as extra checks, is a separate piece of work with its own testing. Ask whether the theme is already customized, because overrides to templates increase the cost of each future Keycloak upgrade and each attribute change.

What testing scope should the attribute project include?

Testing should cover each attribute in each context: registration, first login, profile edit by the user, edit by an administrator, and read by each consuming application. It should also cover invalid input, required-field rules, unmanaged attributes if they are enabled, and what happens to existing users when a rule changes. Include test users with realistic but synthetic data, and include users from each federated source if federation is in use. Testing effort scales with the number of attributes multiplied by the number of contexts, so the test plan should be drafted alongside the attribute inventory.

How long does defining user attributes take?

No duration is given here, because the answer depends on the factors above and on how quickly the client can make decisions. The critical path usually runs through the attribute inventory and the data owner sign-offs, not through the Keycloak configuration itself. Ask a partner for a timeline that lists the decisions it depends on, the people who must make each decision, and the test environment dates. A timeline without named dependencies is a sign that the scope is not yet clear.

What does the client need to provide before work starts?

The client needs an attribute inventory listing each field, its meaning, its source of truth, whether it is personal data, and who may see or edit it. It also needs named data owners who can approve validation rules and visibility decisions, a list of consuming applications with the claims they expect, and a set of test users in a non-production realm. Access to the current Keycloak version and any custom theme is also required. Without these, the work stalls at the decision stage.

Can an internal team define user attributes without a partner?

Yes, a team with Keycloak administration experience can define the declarative user profile on its own, provided it has the attribute inventory, data owner decisions and test plan in place. The areas where internal teams most often need outside help are the federation mapping, the theme and registration changes, and the upgrade planning for customized templates. Teams that do the work alone should document each attribute decision and test case, so the next Keycloak upgrade can be checked against the same record.

Keeping attribute definitions stable across Keycloak upgrades

User profile definitions are configuration, and they have to survive three things: Keycloak upgrades, realm exports and imports, and changes made by different administrators over time. Treat the attribute declarations in the user profile as code that belongs in version control alongside the rest of the realm configuration. A change to a required attribute, a validator or an edit permission can lock existing users out of their accounts or block logins until they supply data they never had to provide before. Before any change ships, decide which existing users it affects, whether they will be prompted on next sign-in, and how you will handle users who cannot satisfy the new rule.

Before each upgrade, read the upgrade notes for every minor release between your current version and the target, starting with the 26.8 notes, which cover enforced SMTP StartTLS, mandatory signature validation of backchannel logout tokens from external providers and login failures persisted to the database by default. The Keycloak upgrading guide explains how schema migration runs and which options change behavior. Confirm with your own team which of these notes touch your realms, especially if you rely on custom attribute flows, and record the decision in the change ticket. Note that the Keycloak Operator documentation recommends manual approval mode for operator updates, so upgrades to attribute-bearing realms should not happen automatically.

Recommend keeping the realm configuration in version control, exporting it on a schedule, and replaying your attribute tests against a staging realm built from that export before production. Each test should cover registration, profile update, account self-service and an admin-created user, with a user who has the attribute set and one who does not. Keep the test results with the upgrade record, because they are the evidence that the definitions behaved the same after the change. Ask your vendor or internal platform team to confirm how the exported realm file handles user profile settings in the version you run, since export behavior is the first thing to verify in staging.

How DeployOpen scopes user profile and attribute work

User profile work touches the login, registration, account and admin screens at once, so the scope is agreed in writing before any realm changes are made. The cards below follow the order we use: inventory the attributes, design who sees and edits them, implement in your own Keycloak, test every flow, then hand the result over.

Attribute inventory

We start by listing every attribute your applications and back-office systems need, with its source of truth, data type, format rules and owner. Many gaps appear here: a value that one team stores in a group, a field that a downstream system expects in a different format, or an attribute that duplicates an identity provider claim. Each attribute gets a decision: keep it in the user profile, map it from an identity provider, or leave it in the application. Ask for this inventory as a named deliverable in your quote.

Contexts and permissions design

The same attribute can be required on registration, optional in the account console, and read-only for administrators. We write a matrix that maps each attribute to each context and to each role that can view or edit it, so a user cannot change a field that drives access decisions. Confirm this matrix with your security and compliance leads before implementation, because it becomes the evidence that attribute changes are controlled.

Keycloak docs

Implementation in your Keycloak

The user profile configuration is built in your own Keycloak instance, in the environment your team operates, and kept in configuration that can be reviewed and promoted between environments. We do not hold your realm settings or user data outside your infrastructure. Ask whether the configuration will be stored in version control and how it moves from test to production, since manual edits in the admin console are hard to repeat after an upgrade.

Testing across registration and account flows

Each attribute is tested in every flow where it appears: self-registration, first login, the account console, administrator edits and token output. We check that validation messages display correctly, that required fields enforce the intended contexts, and that unmanaged attributes behave as designed. Testing results are recorded per attribute so a later change to one field can be retested without repeating the whole plan.

Handover documentation

At handover, your team receives the attribute inventory, the contexts and permissions matrix, the configuration source, the test records and a short runbook for adding a new attribute. The runbook explains how a change is reviewed, tested and released, and which upgrade checks cover the user profile. Ask whether the handover includes a walkthrough with the administrators who will maintain the realm.

Fixed scope and retainers

Most engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts, and a quote follows from that written scope. Attribute changes often continue after launch as new applications connect, so ongoing support is available as a retainer for changes, upgrade checks and retesting. Ask for the retainer terms in writing, including what counts as a change and how upgrade testing is billed.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.