Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Question about and_backend_roles support for creating a role mapping #4084

Closed
rblcoder opened this issue Feb 29, 2024 · 11 comments
Closed
Labels
bug Something isn't working triaged Issues labeled as 'Triaged' have been reviewed and are deemed actionable.

Comments

@rblcoder
Copy link

rblcoder commented Feb 29, 2024

What is the bug?
While creating a role mapping and specifying and_backend_roles, the data specified as and_backend_roles does not seem to have any effect.

How can one reproduce the bug?
Steps to reproduce the behavior:
When I try to create a role mapping using the API


PUT _plugins/_security/api/rolesmapping/all_access
{
  "backend_roles" : [ "admin", "hr1"],
   "and_backend_roles" : [ "it1" ]
 
}

The UI only shows admin and hr1 mapped to all_access

Also if I execute the API as follows

PUT _plugins/_security/api/rolesmapping/all_access
{

   "and_backend_roles" : [  "admin", "hr1","it1" ]
 
}

the admin user loses access.

What is the expected behavior?
The entities specified in and_backend_roles also need to be mapped to the role.
If this is not supposed to be so, please remove all reference to this
https://github.com/search?q=org%3Aopensearch-project+and_backend_roles&type=code

What is your host/environment?

  • PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
    NAME="Debian GNU/Linux"
    VERSION_ID="11"
    VERSION="11 (bullseye)"
    VERSION_CODENAME=bullseye
    ID=debian
  • Version 2.12.0
  • Plugins

Do you have any screenshots?
[
role_mapping_and_backend_role
]

Do you have any additional context?
Add any other context about the problem.

@rblcoder rblcoder added bug Something isn't working untriaged Require the attention of the repository maintainers and may need to be prioritized labels Feb 29, 2024
@stephen-crawford
Copy link
Contributor

[Triage] Hi @rblcoder, thanks for filing this issue. @cwperks to follow up, but this looks like an issue around the documentation of the feature.

@stephen-crawford stephen-crawford added triaged Issues labeled as 'Triaged' have been reviewed and are deemed actionable. and removed untriaged Require the attention of the repository maintainers and may need to be prioritized labels Mar 4, 2024
@cwperks
Copy link
Member

cwperks commented Mar 4, 2024

Hi @rblcoder , thank you for creating an issue. The and_backend_roles feature is supported, but there is no documentation on the website and there is no UX support around the feature currently.

and_backend_roles is similar to backend_roles, but in order for a user to be mapped to the OpenSearch Role (opposed to backend role), the user must have all backend roles in the list, hence AND backend roles. It looks like this feature has existed for a while in the security plugin so it should have associated documentation and perhaps UX for the feature as well.

For the example you provided:

PUT _plugins/_security/api/rolesmapping/all_access
{

   "and_backend_roles" : [  "admin", "hr1","it1" ]
 
}

In order for a user to be mapped successfully to all_access they would need to have admin AND hr1 AND it1.

@rblcoder
Copy link
Author

rblcoder commented Mar 5, 2024

@cwperks Thank you for your reply. The purpose behind and_backend_roles is still not clear to me. Please share link for documentation and also examples. In my example admin, hr1, it1 are users. I am able to map them to the role all_access using backend_roles. Needed to understand about and_backend_roles.

@cwperks
Copy link
Member

cwperks commented Mar 5, 2024

@rblcoder backend_roles are roles extracted from an external Identity Provider (or added manually via OpenSearch Dashboards onto internal users).

If you want to directly map users to roles than you would use user mapping like this:

PUT _plugins/_security/api/rolesmapping/all_access
{
   "users" : [ "admin", "hr1", "it1"]
}

Backend roles are typically used when you have OpenSearch Dashboards configured with a Single Sign-On provider and the user (and their attributes like roles) are external to OpenSearch and instead defined in a central Identity Provider (IdP). When authenticated, OpenSearch will get the user's roles from that external IdP and those are referred to as backend roles - opposed to roles defined in OpenSearch. To map backend roles to roles defined in OpenSearch, you can either use direct backend_roles mapping (i.e. if the user has this backend role X then map the user to OpenSearch role Y) or use and_backend_roles if you require the user to have multiple backend roles in order to be mapped to a role. In the case of and_backend_roles the user needs to have all backend roles in the list in order to be mapped to the respective OpenSearch role.

Effectively, and_backend_roles mapping would be the same as backend_roles mapping if the list only contained a single backend role, but if and_backend_roles is configured with multiple backend roles then the user needs to have all of them to be mapped.

I will create an issue on the documentation-website to go over role mapping in more detail. Currently role mapping supports 4 different methods:

  1. Direct user mapping
  2. Backend Role mapping
  3. AND Backend Role mapping - user needs all backend roles to be mapped
  4. Host mapping - map requests coming from specific IP address(es) or hostname(s) to particular role

@rblcoder
Copy link
Author

Thank you @cwperks for your reply. Could you please also point to the code implementation and unit tests for and_backend_roles so that we can understand it better?

@cwperks
Copy link
Member

cwperks commented Mar 20, 2024

The implementation for and_backend_roles is here. I am not seeing any corresponding tests to the feature.

@rblcoder
Copy link
Author

@cwperks ConfigModelV7 extends ConfigModel. Could you please share the code flow for creating the roles mapping when the create roles mapping rest api is called and also evaluating the same for checking permissions?

@stephen-crawford stephen-crawford changed the title [BUG] Is and_backend_roles supported for creating a role mapping [BUG] Question about and_backend_roles support for creating a role mapping Mar 22, 2024
@cwperks
Copy link
Member

cwperks commented Mar 26, 2024

RolesMappingApi Handler: https://github.com/opensearch-project/security/blob/main/src/main/java/org/opensearch/security/dlic/rest/api/RolesMappingApiAction.java

The actual mapping of the roles occurs here. The mapped roles are used to evaluate whether a user is permitted to perform the given transport action or not.

@rblcoder
Copy link
Author

In the following, all the users from roleMapValue.getUsers() are added to users

for (String u : roleMapValue.getUsers()) {

In the following, all the backend roles from roleMapValue.getBackend_roles() are added to bars

for (String bar : roleMapValue.getBackend_roles()) {

In the following all the and_backend_roles from roleMapValue.getAnd_backend_roles() are added to abars

I am trying to understand what is happening here

for (String p : WildcardMatcher.getAllMatchingPatterns(userMatchers, user.getName())) {
securityRoles.addAll(users.get(p));
}
for (String p : WildcardMatcher.getAllMatchingPatterns(barMatchers, user.getRoles())) {
securityRoles.addAll(bars.get(p));
}
for (List<WildcardMatcher> patterns : abars.keySet()) {
if (patterns.stream().allMatch(p -> p.matchAny(user.getRoles()))) {
securityRoles.addAll(abars.get(patterns));
}
}

Whatever is matching between userMatchers and user.getName(), the corresponding role to which the user is been mapped is added to securityRoles

Similarly with barMatchers and user.getRoles()

For abars and user.getRoles(), every backend_role in abars needs to be present in user.getRoles() for the mapping to work.

@rblcoder
Copy link
Author

Have created an issue to support the same in dashboards.

@rblcoder
Copy link
Author

@cwperks Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triaged Issues labeled as 'Triaged' have been reviewed and are deemed actionable.
Projects
None yet
Development

No branches or pull requests

3 participants