You signed in with another tab or window. Reload to refres
8000
h your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
User attributes with a text more than 255 characters #9758
we need to have user attributes with a text more than 255 characters.
Discussion
No response
Motivation
we want to have user attributes with a text more than 255 characters.
Details
Implementation:
when creating user attributes, the value field is limited to 255 characters, we want to remove this limitation by changing the type of the field "value" in the table "user_attribute" from varchar(255) to TEXT.
Reacted by MrDiba, simse07, Paul, Scott Leggett, Muhammed Yalçın Kuru, Ondrej Tomcik, Michael Wälischmiller, Martin Schneider, Daniyar Akkuliyev, fuesec and 19 more
I'm running into the exact same issue as linked above.
Nothing crazy, just trying to store the link to the profile image as a user attribute:
We are not asking for 10k chars in a user attribute, but storing a link should surely be possible, no?
Edit:
I'm not sure if I didn't create even bigger issues for the future, but I altered the data type of the table. (Using the build in h2 database and the normal keycloak docker image)
Getting a sql shell
cd /opt/jboss/keycloak
java -cp ./modules/system/layers/base/com/h2database/h2/main/h2-*.jar org.h2.tools.Shell -url "jdbc:h2:./standalone/data/keycloak;AUTO_SERVER=TRUE" -user sa -password sa
We also faced with same issue while importing LDAP users. Keycloak writes LDAP_ENTRY_DN to user attributes by default. Thus, value might exist the 255 chars and import fails.
To expand on @iudex- 's answer, if using mysql as a backend the workaround requires an extra step to recreate an index:
alter table USER_ATTRIBUTE drop index IDX_USER_ATTRIBUTE_NAME;
alter table USER_ATTRIBUTE modify VALUE TEXT(100000) CHARACTER SET utf8 COLLATE utf8_general_ci;
alter table USER_ATTRIBUTE ADD KEY `IDX_USER_ATTRIBUTE_NAME` (`NAME`, VALUE(400));
In this example I set the max size of the chunk of text to 100K characters (equivalent to mediumtext type); note that in order to ease indexing only the 400 first characters will be used to build the index. Adapt these values as seems sensible in your use cases.
I am using "openssh-lpk" schema on my OpenLDAP to store the users SSH public keys. With the 255 character limit its impossible to map this into Keycloak. That is yet another very simple and legitimate use case which needs the character limit to be increased or removed.
In case anyone needs the postgres variant for the same solution provided by @mhuin -
DROP INDEX idx_user_attribute_name;
ALTER TABLE user_attribute ALTER COLUMN value SET DATA TYPE VARCHAR(10000);
CREATE INDEX idx_user_attribute_name ON user_attribute (name, left(value, 1000));
Removes the index, changes the type to 10k characters and creates an index on the first 1k characters of the value.
Hoping this can be officially supported in the future by keycloak.
Reacted by marcelomagalhaes-ilia and Laurent Mignon (ACSONE)
Is it good to solve the problem this way? Since this requires modify the data type of a database field, will it cause any trouble in the future? (I've already tested that this change won't cause any problem for the automatic db migration from 18.0.2 to 21.1.1 by runing keycloak 21.1.1 directly on the database after making this db column datatype change)
Activity
meden commentedon Feb 2, 2022
For some context: https://issues.redhat.com/browse/KEYCLOAK-9515
meden commentedon Mar 29, 2022
Here another valid use case. In this case this issue breaks an officially supported broker integration.
iudex- commentedon Apr 8, 2022
I'm running into the exact same issue as linked above.
Nothing crazy, just trying to store the link to the profile image as a user attribute:


We are not asking for 10k chars in a user attribute, but storing a link should surely be possible, no?
Edit:
I'm not sure if I didn't create even bigger issues for the future, but I altered the data type of the table. (Using the build in h2 database and the normal keycloak docker image)
Getting a sql shell
to run this sql command (docs):
and check on it:
myalcinkuru commentedon Sep 5, 2022
We also faced with same issue while importing LDAP users. Keycloak writes LDAP_ENTRY_DN to user attributes by default. Thus, value might exist the 255 chars and import fails.
mhuin commentedon Sep 12, 2022
To expand on @iudex- 's answer, if using mysql as a backend the workaround requires an extra step to recreate an index:
In this example I set the max size of the chunk of text to 100K characters (equivalent to mediumtext type); note that in order to ease indexing only the 400 first characters will be used to build the index. Adapt these values as seems sensible in your use cases.
Iodun commentedon Nov 2, 2022
I am using "openssh-lpk" schema on my OpenLDAP to store the users SSH public keys. With the 255 character limit its impossible to map this into Keycloak. That is yet another very simple and legitimate use case which needs the character limit to be increased or removed.
kapalex commentedon Feb 6, 2023
In case anyone needs the postgres variant for the same solution provided by @mhuin -
Removes the index, changes the type to 10k characters and creates an index on the first 1k characters of the value.
Hoping this can be officially supported in the future by keycloak.
vramik commentedon Feb 6, 2023
Capability to store long attribute values will be supported in new store. There is no plan to add support to legacy store regarding it.
hmlnarik commentedon Feb 6, 2023
Duplicate of https://issues.redhat.com/browse/KEYCLOAK-9515. Thank you for your requirement. As @vramik mentioned above, this will only be addressed in the new store.
zhengyang1988 commentedon Jun 14, 2023
I found the following solution for this problem on stackoverflow:
https://stackoverflow.com/questions/44851052/max-size-of-custom-user-attribute-in-keycloak#:~:text=Keycloak%27s%20attribute%20values%20maximum%20length,the%20field%20type%20to%20text%20.
Is it good to solve the problem this way? Since this requires modify the data type of a database field, will it cause any trouble in the future? (I've already tested that this change won't cause any problem for the automatic db migration from 18.0.2 to 21.1.1 by runing keycloak 21.1.1 directly on the database after making this db column datatype change)
ahus1 commentedon Aug 3, 2023
As the new store hasn't arrived yet, re-opening it for evaluating it.
We're investigating if the column can be enlarged; still it wouldn't hold unlimited amount of text.
14 remaining items
User attribute value length extension
User attribute value length extension