Skip to content

Commit

Permalink
Merge pull request #2 from abbeylabs/rbac-abac-policies
Browse files Browse the repository at this point in the history
Add in_group and has_attribute policy functions
  • Loading branch information
Koshroy-Abbey authored Nov 21, 2023
2 parents 1d49a15 + 637e362 commit b5c7625
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/abbey/functions/has_attribute.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package abbey.functions

import future.keywords.if

# Function which checks whether a user has a given attribute.
# Attributes are found under a custom_attributes object under the
# abbey.identities object.
has_attribute(name, value) := true if {
data.system.abbey.identities.directory_sync_users.custom_attributes[name] == value
}
19 changes: 19 additions & 0 deletions src/abbey/functions/has_attribute_test.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package abbey.functions

import future.keywords.if

test_has_cost_center_engineering if {
has_attribute("cost_center_name", "Engineering") with data.system.abbey.identities.directory_sync_users.custom_attributes as {"department_name": "Engineering", "cost_center_name": "Engineering", "employee_type": "Manager"}
}

test_has_department_engineering if {
has_attribute("department_name", "Engineering") with data.system.abbey.identities.directory_sync_users.custom_attributes as {"department_name": "Engineering", "cost_center_name": "Engineering", "employee_type": "Manager"}
}

test_does_not_have_department_marketing if {
not has_attribute("department_name", "Marketing") with data.system.abbey.identities.directory_sync_users.custom_attributes as {"department_name": "Engineering", "cost_center_name": "Engineering", "employee_type": "Manager"}
}

test_does_not_have_employee_type_ic if {
not has_attribute("employee_type", "IC") with data.system.abbey.identities.directory_sync_users.custom_attributes as {"department_name": "Engineering", "cost_center_name": "Engineering", "employee_type": "Manager"}
}
11 changes: 11 additions & 0 deletions src/abbey/functions/in_group.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package abbey.functions

import future.keywords.if
import future.keywords.in

# Function which checks whether a user is in a given group.
# Groups are kept within an object called group_memberships in the
# system.abbey object
in_group(group_name) := true if {
group_name in data.system.abbey.group_memberships
}
11 changes: 11 additions & 0 deletions src/abbey/functions/in_group_test.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package abbey.functions

import future.keywords.if

test_in_group_engineering if {
in_group("Engineering") with data.system.abbey.group_memberships as ["Engineering", "R&D"]
}

test_not_in_group_marketing if {
not in_group("Marketing") with data.system.abbey.group_memberships as ["Engineering", "R&D"]
}

0 comments on commit b5c7625

Please sign in to comment.