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

object.subset: allow super to be array, and sub to be set #4858

Closed
anderseknert opened this issue Jul 7, 2022 · 1 comment · Fixed by #4865
Closed

object.subset: allow super to be array, and sub to be set #4858

anderseknert opened this issue Jul 7, 2022 · 1 comment · Fixed by #4865

Comments

@anderseknert
Copy link
Member

Currently, both arguments to object.subset must be of the same type. This makes sense, but there's one exception I think should be allowed. If the superset is an array, the subset should be allowed to be a set, meaning "if all items in sub are in super, with no consideration of ordering". This is a IMHO a nice construct:

allow if object.subset(input.user.roles, {"developer", "logs-reader"})

You can of course achieve this today by first converting input.user.roles to a set, but if we can remove an extra step for the likely most common operation, let's do it.

For anyone who wants to work on this, these are the steps I imagine would be needed:

  1. Allow first argument provided to be of type array, and the second argument to be of type set.
  2. Add a few test cases to assert this works as described above.
  3. Update the docs to reflect this.

Join the #development channel on the OPA Slack if you'd like to discuss the approach while working on this.

@charlesdaniels
Copy link
Contributor

Breadcrumbs:

We are getting enough cases it might be worth trying to refactor builtinObjectSubset to use a switch/case rather than a bunch of ifs.

x-color added a commit to x-color/opa that referenced this issue Jul 9, 2022
Add support for checking if `super` array contains
every element of `sub` set to object.subset.
object.subset allows `super` to be array and `sub` to be set.

Fixes: open-policy-agent#4858
Signed-off-by: x-color <36035885+x-color@users.noreply.github.com>
srenatus pushed a commit that referenced this issue Jul 11, 2022
Add support for checking if `super` array contains
every element of `sub` set to object.subset.
object.subset allows `super` to be array and `sub` to be set.

Fixes: #4858

Signed-off-by: x-color <36035885+x-color@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants