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

rego working tests #675

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions trino docker/OPA_Tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: "3.9"
services:
opaservice:
container_name: opa_tests
image: openpolicyagent/opa:latest
ports:
- 9090:8181
command:
- "test"
- "testting"
- "-v"
volumes:
- ./opa/config.yaml:/config.yaml
- ./opa/log.properties:/etc/log.properties
- ./rego:/testting


13 changes: 13 additions & 0 deletions trino docker/OPA_Tests/opa/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
services:
acmecorp:
url: https://host.docker.internal:7157/api/OPA/BundleGetv2
allow_insecure_tls : true

bundles:
authz:
service: acmecorp
resource: somedir/bundle.tar.gz
persist: true
polling:
min_delay_seconds: 60
max_delay_seconds: 120
1 change: 1 addition & 0 deletions trino docker/OPA_Tests/opa/log.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.trino=DEBUG
35 changes: 35 additions & 0 deletions trino docker/OPA_Tests/rego/Policy.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package policy

import rego.v1

default allow := false

#allow all highest level access
allow if {
input.action.operation == "ExecuteQuery"
}

#allow catalog - only iceberg
allow if {
input.action.operation == "AccessCatalog"
input.action.resource.catalog.name == "iceberg"
}

allow if {
input.action.operation == "SelectFromColumns"
user_in_correct_group
}

default user_roles := false

groups_for_object contains group if {
some i
data.Perms[i].Project == input.action.resource.table.schemaName
group := data.Perms[i].Group
}

user_in_correct_group if {
some i, j
data.GroupMembers[i].Username == input.context.identity.user
data.GroupMembers[i].Group = groups_for_object[j]
}
107 changes: 107 additions & 0 deletions trino docker/OPA_Tests/rego/Policy_test.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package policy

data = {
"Perms": [{
"Project": "sail0675v",
"Group": "SAIL_0675_Developer",
"PermType": "rw",
"Object": ""
}
],
"GroupMembers": [{
"Group": "SAIL_0675_Developer",
"Username": "rawlinga"
}
]
}


intput = {
"context": {
"identity": {
"user": "rawlinga",
"groups": []
},
"softwareStack": {
"trinoVersion": "444"
}
},
"action": {
"operation": "SelectFromColumns",
"resource": {
"table": {
"catalogName": "postgresql",
"schemaName": "sail0675v",
"tableName": "cool",
"columns": ["aaaaaa", "id"]
}
}
}
}

test_Default {
allow
with input as intput
with data as data
}


intput2 = {
"context": {
"identity": {
"user": "rawlinga",
"groups": []
},
"softwareStack": {
"trinoVersion": "444"
}
},
"action": {
"operation": "SelectFromColumns",
"resource": {
"table": {
"catalogName": "postgresql",
"schemaName": "nottheOne",
"tableName": "cool",
"columns": ["aaaaaa", "id"]
}
}
}
}

test_schemaName_diff {
not allow
with input as intput2
with data as data
}



intpu3 = {
"context": {
"identity": {
"user": "bob",
"groups": []
},
"softwareStack": {
"trinoVersion": "444"
}
},
"action": {
"operation": "SelectFromColumns",
"resource": {
"table": {
"catalogName": "postgresql",
"schemaName": "sail0675v",
"tableName": "cool",
"columns": ["aaaaaa", "id"]
}
}
}
}

test_user_not_in {
not allow
with input as intpu3
with data as data
}
14 changes: 14 additions & 0 deletions trino docker/OPA_Tests/rego/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Perms": [{
"Project": "sail0675v",
"Group": "SAIL_0675_Developer",
"PermType": "rw",
"Object": ""
}
],
"GroupMembers": [{
"Group": "SAIL_0675_Developer",
"Username": "rawlinga"
}
]
}
1 change: 1 addition & 0 deletions trino docker/OPA_Tests/run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker-compose up
Loading