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] Can't use multiple roles with DLS permissions on the same Index #2556

Open
sbeginCoveo opened this issue Mar 15, 2023 · 9 comments
Open
Labels
bug Something isn't working CCI College Contributor Initiative good first issue These are recommended starting points for newcomers looking to make their first contributions. triaged Issues labeled as 'Triaged' have been reviewed and are deemed actionable.

Comments

@sbeginCoveo
Copy link

What is the bug?
When a user is bound to two roles using DLS permissions on the same index, only one DLS policy is taken into account.
Each role with DLS permissions works independently as expected, but they won't combine in the typical additive fashion.

How can one reproduce the bug?
Steps to reproduce the behavior:
1: create a "global" role with READ on index pattern * and the following DLS:

{
  "bool": {
    "must_not": {
      "match": {
        "sensitive": true
      }
    }
  }
}

2: create a higher privileged role on any indices (example-*) with some catch-all DLS policy:

{
  "bool": {
    "must": {
      "match_all": {}
    }
  }
}

3: Query that example-* index pattern using the a User bound to both roles. Observe that you will not have any logs that contains "sensitive": true

What is the expected behavior?
The policies to be additive (combine each DLS statement in an OR query)

What is your host/environment?

  • Provider: AWS Opensearch
  • Version: OpenSearch 2.3
  • Plugins: unsure

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

The codebase seems to indicate selection of a single arbitrary DLS policy for each index:

String dlsEval = SecurityUtils.evalMap(filterLevelQueries, index);

Same issue described here

@sbeginCoveo sbeginCoveo added bug Something isn't working untriaged Require the attention of the repository maintainers and may need to be prioritized labels Mar 15, 2023
@scrawfor99
Copy link
Collaborator

[Triage] Hi @sbeginCoveo, thank you for taking the time to file this issue. As a follow-up did you have any thoughts on how you would handle a negative and positive permission being "added?" What would that look like in the proposed solution. We are happy to review any pull requests to this issue.

@scrawfor99 scrawfor99 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 20, 2023
@sbeginCoveo
Copy link
Author

sbeginCoveo commented Mar 21, 2023

In theory, there should be no concept of a "negative" permission. As in adding a role to a user should not "remove" access to anything. Permissions should always be additive. What should exist, though, is a negative filter for permissions, such as matching logs that don't have some field.

For example here's a quick pseudo-code boolean "sum":

PermissionA = (! log.sensitive) # negative lookup non-sensitive access to all indicies
PermissionB = (true) # match_all privileged role for single index

Sum = PermissionA || PermissionB

I hope that clears up the confusion!

@scrawfor99
Copy link
Collaborator

Hi @sbeginCoveo, thank you for your prompt reply. That does clarify things. I can see how this would be preferable and the expected behavior. I am surprised it is not already haha. Would you be interested in making a contribution towards this effort? If so, I would be happy to help you along the way. If not, I will add a label for our college contributor initiative since it seems like this should be a pretty straightforward change.

@sbeginCoveo
Copy link
Author

Thanks @scrawfor99 for the follow-up! I personally don't feel confident enough in Java to make a proper contribution. I also don't have the ide or the tooling in place to make the changes in a timely fashion

@scrawfor99
Copy link
Collaborator

Hi @sbeginCoveo, no worries. Thank you for letting me know. I am going to mark this as a good issue for a first time contributor and will leave some notes later today about what changes will be required. After that, the issue should be addressed before too long. If you need this change expedited, please follow-up here and I will try to find the time to fix it for you myself.

@scrawfor99 scrawfor99 added good first issue These are recommended starting points for newcomers looking to make their first contributions. CCI College Contributor Initiative labels Mar 23, 2023
@scrawfor99
Copy link
Collaborator

Hi @sbeginCoveo, I have been taking a look at this for you but am having issues reproducing the issue. I have created two roles and assigned them to a user DlsTest without any other roles. I then went and created an index my_index1 and populated it with data. When I query the indices using the Query Workbench, I get the same results as an admin or as the new user.

Here are the two roles:
Screenshot 2023-03-23 at 12 47 43 PM
Screenshot 2023-03-23 at 12 47 29 PM

Here are the query results:
Screenshot 2023-03-23 at 12 42 27 PM

This looks to me that the Dls patterns are additive. It seems that the extra permissions from the HigherPriv role is working as expected. Perhaps, I have misunderstood the issue?

@peternied
Copy link
Member

@scrawfor99 Is there a test case in our repository that proves this scenario works? I think that might be easier to have a PR with a reproduction of the issue to refine the scenario, what do you think?

@sbeginCoveo
Copy link
Author

Since only one DLS statement is taken into account, it could be that the match_all is the one being used when "merging" the two roles. My reproduction procedure may be wrong if let's say the permissions are sorted in a different way. We seemed to have inconsistent results (using the api, and the dashboard discovery) before we decided to read some of the source code

It may be better to have two "non-overlapping" DLS statements to make sure the union of roles works as expected

@scrawfor99
Copy link
Collaborator

Hi @peternied, I don't believe we have a test that covers this type of scenario. I think it would be wise to add one however and will take a look.

Hi @sbeginCoveo, thank you for the follow-up. That makes sense and is likely to be the case. I just wanted to confirm with you that I was understanding your reproduction steps for the time being. I will continue to take a look and let you know if anything comes up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working CCI College Contributor Initiative good first issue These are recommended starting points for newcomers looking to make their first contributions. triaged Issues labeled as 'Triaged' have been reviewed and are deemed actionable.
Projects
None yet
Development

No branches or pull requests

3 participants