It seems that backend_roles in roles_mapping.yml are ignored if authentication is done via KeyCloak. Same for and_backend_roles (whatever that is, see docs)
If the roles_key is in the config.yml then OpenSearch logs complain about “Failed to get roles from JWT claims with roles_key ‘roles’. Check if this key is correct and available in the JWT payload.”
If the roles_key is removed then the warning disappears but the backend_roles in roles_mapping.yml seems be to ignored.
If I set up a role in roles.yml other than the standard role admin then it’s also ignored.
If I set the roles_key to family_name and change my family name in KeyCloak to admin then the backend_role is correctly assigned
It seems to me that backend roles MUST be provided via KeyCloak. Is that correct or am I doing something wrong?
Thanks. As it turns out, it is not configured. But if I understand its function correctly (see here), this would enable KeyCloak to pass roles in the “access token”. I hope to rather set up users in the roles_mapping.yml because the implementation would be easier in our case.
To whom it may concern: I looked into the code and this doesn’t seem possible currently. There is no lookup of the internal file config for roles when using OpenID and no authz backend to handle this case. Roles must be set in the configured roles_key in the ID token.
Thanks for the reply. My issue is with the backend_roles, which you need to access the “Security” settings (to manage tenants and users).
As your screenshot shows, the role all_access is mapped to the user “pablo” and the backend_role “admin”.
In my expectation is would mean that if user “pablo” gets authenticated via KeyCloak that he will automatically get the role all_access and the backend_role “admin”. But to be assigned the backend_role “admin”, the KeyCloak ID Token has to have the field roles with the value “admin” (or at least I couldn’t get it to work without it).
Maybe it’s a feature and not a bug, but from the configuration as code perspective it would be beneficial to be able just to render this roles_mapping.yml file and have all the desired backend_role mappings included without the need to interact with an external entity additionally (i.e. KeyCloak), which is hard to manage. So it’s easier to delete all users and reapply them instead of having to deal with adding and deleting single users via some REST APIs. The security plugin actually works that way, see “A word of caution”.
We solved it now with the roles_key and the roles mapper in KeyCloak, which you mentioned in your first reply. Thanks a lot for your help!
@sergej I’ve placed an incorrect screenshot. There should be user1 instead of pablo.
User1 didn’t have any roles assigned in Keycloak as per my previous screenshots. OS assigned all_access based on the roles_mapping.yml.
And i created a keycloak mapping as described above. The mapping is done fine: if I assign a role in kc to a user, it gets mapped to that user when logged into opensearch-dashboard (seen through view roles and identities
However the roles dont seem to work accept for all_access
Same I would add mymail@mail.com to any other role in roles_mapping.yml i will not get to see any indices nor data.