FFFF Cannot set empty value for field "Kerberos principal attribute" using REST API · Issue #28011 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Cannot set empty value for field "Kerberos principal attribute" using REST API #28011

Closed as not planned

Description

@hoepfnerj

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

I cannot set the field "Kerberos principal attribute" in the "LDAP User Federation" section to an empty value using the REST API (POST /auth/admin/realms). It only works if I set it to an empty value using the UI.

When I use the REST API and set the field "krbPrincipalAttribute" to an empty string, then this empty string is used in the AD filter ([&(=john@KEYCLOAK.ORG)..)] which obviously does not work. In the database table "component_config" a row with name "krbPrincipalAttribute" and an empty "value" exists.

If I set the field "krbPrincipalAttribute" to null when using the REST API, then it is simply ignored.

If I use the UI and set the field to an empty value it works as expected. In this case the database table "component_config" does not contain a row with name "krbPrincipalAttribute".

It might have to do with this change:
57e51e9

Is there some other way I can get this setting to work using the REST API? Btw. I did not see the field "krbPrincipalAttribute" in the REST documentation, I infered it from the payload of the UI.

Version

24.0.1

Regression

  • The issue is a regression

Expected behavior

Using the REST API, creating a realm with field "krbPrincipalAttribute" with an empty string should behave the same way as setting the field "Kerberos principal attribute" to an empty value in the UI.

Actual behavior

An empty string is used as if this was an attribute in the AD resulting in an invalid filter.

Log message: Could not query server using DN [OU=X,DC=Y,DC=Z] and filter [(&(=john@KEYCLOAK.ORG)...

How to Reproduce?

Create a realm using the REST API (POST /auth/admin/realms) and set the JSON field "/userFederationProviders/0/config/krbPrincipalAttribute" to an empty string. Compare the behavior when setting the field ""Kerberos principal attribute" to an empty value using the UI.

Anything else?

In version 22.0.4 this field did not exist in the UI and therefore it was not an issue for me.

Activity

  1. added
    kind/bug
    on Mar 18, 2024
  2. added
    area/admin/api
    on Mar 18, 2024
  3. vramik commented on Mar 21, 2024

    @vramik
    Contributor

    @mposolda could you please take a look? To me it sounds like a bug as there is different behavior when you call REST API directly and when done via UI. But I'm not sure what the expected behavior should be. Thanks

  4. mposolda commented on Mar 21, 2024

    @mposolda
    Contributor

    @hoepfnerj One thing to note: Admin console UI is just a "wrapper" over the REST API. Admin console always calls REST API under the covers. So if something works with admin console, but does not work for you with REST API, it can rather indicate that you are using REST API in somehow wrong way...

    Could you try to check some browser plugin (For instance some developer console plugins for Chrome or FF) and check what REST requests are called by admin console? Then you can compare the difference between your REST API usage and maybe it can give some insight why the update work for you with the UI, but doesn't work with your REST API calls.

    Any info here would be useful.

  5. hoepfnerj commented on Mar 22, 2024

    @hoepfnerj
    Author

    @mposolda Thanks for the quick reply and explanation. I am currently using the realm endpoint POST /admin/realms to create a realm. The payload includes the JSON attribute userFederationProviders for the user federation part. If I try to set the field "Kerberos principal attribute" to an empty value by setting the JSON attribute userFederationProviders[0].config.krbPrincipalAttribute to an empty string the result is not the same as when I change it in the UI. The UI seems to use a different endpoint PUT /admin/realms/<realm>/components/<user_federation_id>. So these two approaches do not seem to be compatible.

  6. rmartinc commented on Mar 22, 2024

    @rmartinc
    Contributor

    @hoepfnerj I think that the update realm endpoint does not manage userFederationProviders at all (the same way than rolesor groups that are on there for import/export). Does it even create a new provider if you add a new one?

    As @mposolda commented you better use the specific components endpoint as the admin console does.

  7. hoepfnerj commented on Mar 22, 2024

    @hoepfnerj
    Author

    @rmartinc yes, I was always using this endpoint to create the userFederationProviders along with the realms. The userFederationProviders field is part of the RealmRepresentation. It does create everything as expected, even the krbPrincipalAttribute when setting it to some non-empty value. However, the result differs between the mentioned API endpoints when setting the value to an empty string.

    I can use the other endpoint as a workaround, but the API does not seem to be consistent.

  8. mposolda commented on Mar 26, 2024

    @mposolda
    Contributor

    @hoepfnerj Thanks for the clarification. This have very low priority as the proper endpoint for updating user storage providers is components endpoint mentioned by @rmartinc and that is also what admin console is using.

    We should perhaps clarify a docs that realm endpoint is not the best one for this use-case. PR might be welcome to fix this, but just in case that it doesn't have other side-effects (EG. requirement to create all ComponentFactory instances for the callbacks etc).

  9. 3 remaining items

  10. keycloak-github-bot commented on Mar 26, 2024

    @keycloak-github-bot

    Due to the amount of issues reported by the community we are not able to prioritise resolving this issue at the moment.

    If you are affected by this issue, upvote it by adding a 👍 to the description. We would also welcome a contribution to fix the issue.

  11. hoepfnerj commented on Mar 27, 2024

    @hoepfnerj
    Author

    @mposolda I found another bug regarding this field when using the UI:

    1. create a new LDAP user federation, set "Allow Kerberos authentication" to true, leave the field "Kerberos principal attribute" empty and save.
    2. open the newly created LDAP user federation: the field "Kerberos principal attribute" now has the value "userPrincipalName" instead of being empty.

    The only way to set this field to an empty value is to edit it again after creation, set to value to empty and save it again. So when creating a new LDAP user federation, it must first be saved (POST) and then edited again (PUT).

  12. rmartinc commented on Apr 1, 2024

    @rmartinc
    Contributor

    @hoepfnerj I think that this configuration attribute has a default value in the onCreate method. The default value for AD is userPrincipalName. That's why it's created with that value when null is sent (but just on create, if you update later you can set to null as you have experienced).

    And my previous comment about the endpoint was for update. The create/import endpoint creates the ldap provider but the update does not update them. And I think the issue is the same for the endpoint. This specific attribute has a default value so null is always transformed into the default value on create (no matter how you create it).

    We can think about removing the default assignment in the onCreate method, but, AFAIK in AD the userPrincipalName is the correct attribute for the kerberos login. Why is that value wrong for you? Is there any error when you assign that value instead of leving the attribute empty?

  13. hoepfnerj commented on Apr 2, 2024

    @hoepfnerj
    Author

    @rmartinc The krbPrincipalAttribute attribute was added to Keycloak after version 22 and changed the way how the user lookup in LDAP is done. The tooltip of the attribute explains the behavior when the attribute is set to an empty string, which was the default behavior in Keycloak <= 22:

    Name of the LDAP attribute, which refers to Kerberos principal. This is used to lookup appropriate LDAP user after successful Kerberos/SPNEGO authentication in Keycloak. When this is empty, the LDAP user will be looked based on LDAP username corresponding to the first part of his Kerberos principal. For instance, for principal 'john@KEYCLOAK.ORG', it will assume that LDAP username is 'john'.

    This commit seems to have introduced this change:
    57e51e9

  14. rmartinc commented on Apr 2, 2024

    @rmartinc
    Contributor

    @hoepfnerj Yes, the addition of the attribute for kerberos was added to fix an issue when the kerberos setup is more complicated (there are several issues, for example #20045). Now the solution is more robust.

    As you mention the backwards compatibility was added to work with previous configurations (in which the attribute was not set for sure). As the use of the attribute is more robust it was decided to setup that attribute by default (waht you are complaining in this issue). But my question is still the same, why do you want to remove the default kerberos attribute for AD? Is it not working? Is there any issue if you maintain the default userPrincipalName?

    As I commented we can remove the default value, but at that moment it was decided that adding the default value was better than using the old empty solution that generated some issues. And that's why we are asking.

  15. hoepfnerj commented on Apr 2, 2024

    @hoepfnerj
    Author

    @rmartinc I just tested both settings with our AD. The LDAP operations are as follows:

    1. Setting "Kerberos principal attribute" = "userPrincipalName":
      The LDAP search is: userPrincipalName=<username>@<kerberos-realm> which returns 0 results and then it aborts with the message: "Not found LDAP user with kerberos principal [<username>@<kerberos-realm>]. Kerberos principal attribute is [userPrincipalName]".
    2. Setting "Kerberos principal attribute" to empty:
      The LDAP search is: sAMAccountName=<username> which matches and then it continues.

    The second one is what I need, since the userPrincipalName in our case contains the email address, which does not contain the username nor the kerberos realm.

  16. rmartinc commented on Apr 3, 2024

    @rmartinc
    Contributor

    The error in (1) means that the search in LDAP for a user with filter userPrincipalName=<username>@<kerberos-realm> returned nothing and it cannot link the principal to a user. What is the userPricipalName in your AD for that user? Is it different?

  17. hoepfnerj commented on Apr 3, 2024

    @hoepfnerj
    Author

    Yes in our case the userPrincipalName contains the email address, something like firstname.lastname@company.com. But Keycloak expects something like username@kerberos-realm.

  18. rmartinc commented on Apr 12, 2024

    @rmartinc
    Contributor

    I brought up this issue in the weekly meeting.

    Little summary about the behavior. The ldap federation factory has an onCreate method that initializes some defaults in the provider when it's created (default mappers and other things). Among those defaults it configures the kerberos attribute (if null is passed) based on the ldap vendor. That's why the field Kerberos principal attribute is always filled to userPrincipalName for AD or krbPrincipalName for RHDS if none is passed when creating it. The default value can be changed after creation. The issue here is that the userPrincipalName is not the default in AD. The field is modified for the user to other value different to the UPN. Therefore there is no attribute with the UPN that can be configured to look for users. That's why the config option is needed to be configured empty and search using the username (stripping the kerberos realm).

    We discussed about the following three alternatives:

    1. Do nothing and continue assigning the default value.
    2. Revert back and not configure anything by default. Set the default value only at admin console level (not at java/REST level).
    3. Do a weird thing and assume old behavior using a fixed string or similar (legacy_username for example).

    Option(3) is a horrible workaround so we just discussed options (1) and (2). It was decided that the default value continues, option (1), because almost all ldap/kerberos installations will work with that configuration. The attribute can still be updated after creation to remove it if necessary.

    As usual we can reconsider this if a lot of people complain about the decision. Closing the issue for now as not planned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/admin/apihelp wantedkind/bugpriority/lowstatus/auto-bumpstatus/auto-expireteam/core-clients

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0