Skip to content

Instantly share code, notes, and snippets.

@marcaurele
Created March 24, 2021 09:04
Show Gist options
  • Save marcaurele/acec7f73b0b5510e4590a6f4f545388d to your computer and use it in GitHub Desktop.
Save marcaurele/acec7f73b0b5510e4590a6f4f545388d to your computer and use it in GitHub Desktop.
Example REGO rule
package httpapi.authorization.project
import input
# Very important!, default to deny!
default allow_reading = false
default allow_editing = false
default allow_processing = false
role_allow_processing = {"MANAGER", "OWNER"}
role_allow_editing = {"EDITOR"} | role_allow_processing
role_allow_reading = {"READER"} | role_allow_editing
allow_processing {
some uuid # for a given uuid
input.method == "POST" # if the method is POST
input.path = ["project", uuid, "processing"] # for the given uuid in the path
input.project.uuid == uuid # the given uuid matched the project uuid
membership := input.user.memberOf[_] # a membership exists in the list of the user where
membership.type == "ORG" # it contains a entity of type ORG and
role_allow_processing[membership.role] # the membership role is in the set of allowed role for processing
# membership.role == "OWNER" # it has the role OWNER and
membership.uuid == input.project.organization.uuid # the entity uuid matches the project organization uuid
}
allow_editing {
some uuid # for a given uuid
input.method == "POST" # if the method is POST
input.path = ["project", uuid] # for the given uuid in the path
input.project.uuid == uuid # the given uuid matched the project uuid
membership := input.user.memberOf[_] # a membership exists in the list of the user where
membership.type == "ORG" # it contains a entity of type ORG and
role_allow_editing[membership.role] # the membership role is in the set of allowed role for processing
membership.uuid == input.project.organization.uuid # the entity uuid matches the project organization uuid
}
allow_reading {
some uuid # for a given uuid
input.method == "GET" # if the method is GET
input.path = ["project", uuid] # for the given uuid in the path
input.project.uuid == uuid # the given uuid matched the project uuid
membership := input.user.memberOf[_] # a membership exists in the list of the user where
membership.type == "ORG" # it contains a entity of type ORG and
role_allow_reading[membership.role] # it has a role in the allowed for reading
membership.uuid == input.project.organization.uuid # the entity uuid matches the project organization uuid
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment