-
Notifications
You must be signed in to change notification settings - Fork 4
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
WIP: Constraints #233
base: master
Are you sure you want to change the base?
WIP: Constraints #233
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,25 +161,25 @@ service_path_data = { | |
} | ||
|
||
test_policy_permissions_all { | ||
allow.allowed with request as {"user":"[email protected]", "action":"POST", "resource":"/v1/policies/", "tenant":"Tenant1", "service_path":"/"} with input.parsed_body as {"access_to":"test","resource_type":"entity"} with data as policy_data with bearer_token as bearer_token with testing as true | ||
check_policy with request as {"user":"[email protected]", "action":"POST", "resource":"/v1/policies/", "tenant":"Tenant1", "service_path":"/"} with input.parsed_body as {"access_to":"test","resource_type":"entity"} with policies as policy_data with bearer_token as bearer_token with testing as true | ||
} | ||
|
||
test_policy_permissions_one { | ||
allow.allowed with request as {"user":"[email protected]", "action":"GET", "resource":"/v1/policies/test", "tenant":"Tenant1", "service_path":"/"} with data as policy_data with bearer_token as bearer_token with testing as true | ||
check_policy with request as {"user":"[email protected]", "action":"GET", "resource":"/v1/policies/test", "tenant":"Tenant1", "service_path":"/"} with policies as policy_data with bearer_token as bearer_token with testing as true | ||
} | ||
|
||
test_tenant_permissions_all { | ||
allow.allowed with request as {"user":"[email protected]", "action":"GET", "resource":"/v1/tenants", "tenant":"Tenant1", "service_path":"/"} with data as tenant_data with bearer_token as bearer_token with testing as true | ||
check_policy with request as {"user":"[email protected]", "action":"GET", "resource":"/v1/tenants", "tenant":"Tenant1", "service_path":"/"} with policies as tenant_data with bearer_token as bearer_token with testing as true | ||
} | ||
|
||
test_tenant_permissions_one { | ||
allow.allowed with request as {"user":"[email protected]", "action":"PUT", "resource":"/v1/tenants/Tenant1", "tenant":"Tenant1", "service_path":"/"} with data as tenant_data with bearer_token as bearer_token with testing as true | ||
check_policy with request as {"user":"[email protected]", "action":"PUT", "resource":"/v1/tenants/Tenant1", "tenant":"Tenant1", "service_path":"/"} with policies as tenant_data with bearer_token as bearer_token with testing as true | ||
} | ||
|
||
test_service_path_permissions_all { | ||
allow.allowed with request as {"user":"[email protected]", "action":"GET", "resource":"/v1/tenants/Tenant1/service_paths", "tenant":"Tenant1", "service_path":"/"} with data as service_path_data with bearer_token as bearer_token with testing as true | ||
check_policy with request as {"user":"[email protected]", "action":"GET", "resource":"/v1/tenants/Tenant1/service_paths", "tenant":"Tenant1", "service_path":"/"} with policies as service_path_data with bearer_token as bearer_token with testing as true | ||
} | ||
|
||
test_service_path_permissions_one { | ||
allow.allowed with request as {"user":"[email protected]", "action":"PUT", "resource":"/v1/tenants/Tenant1/service_paths/foo/bar", "tenant":"Tenant1", "service_path":"/"} with data as service_path_data with bearer_token as bearer_token with testing as true | ||
check_policy with request as {"user":"[email protected]", "action":"PUT", "resource":"/v1/tenants/Tenant1/service_paths/foo/bar", "tenant":"Tenant1", "service_path":"/"} with policies as service_path_data with bearer_token as bearer_token with testing as true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package envoy.authz | ||
|
||
check_constraint(left, operator, right) { | ||
operator == "acl:operator:hasPart" | ||
contains(left, right) | ||
} | ||
|
||
check_constraint(left, operator, right) { | ||
operator == "acl:operator:eq" | ||
left == right | ||
} | ||
|
||
check_constraint(left, operator, right) { | ||
operator == "acl:operator:gt" | ||
left >= right | ||
} | ||
|
||
check_constraint(left, operator, right) { | ||
operator == "acl:operator:gteq" | ||
left >= right | ||
} | ||
|
||
check_constraint(left, operator, right) { | ||
operator == "acl:operator:lt" | ||
left < right | ||
} | ||
|
||
check_constraint(left, operator, right) { | ||
operator == "acl:operator:lteq" | ||
left <= right | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,15 @@ import input.attributes.request.http.method as method | |
import input.attributes.request.http.path as path | ||
import input.attributes.request.http.headers.authorization as authorization | ||
|
||
|
||
# Checks if the policy has the wildcard asterisks, thus matching paths to any entity or all | ||
path_matches_policy(entry, request) { | ||
entry.resource == "*" | ||
entry.resource_type == "entity" | ||
current_path := split(request.resource, "/") | ||
current_path[1] == "v2" | ||
current_path[2] == "entities" | ||
not entry.constraint | ||
} | ||
|
||
# Checks if the policy is a default | ||
|
@@ -31,6 +33,18 @@ path_matches_policy(entry, request) { | |
current_path[1] == "v2" | ||
current_path[2] == "entities" | ||
current_path[3] == entry.resource | ||
not entry.constraint | ||
} | ||
|
||
path_matches_policy(entry, request) { | ||
entry.resource_type == "entity" | ||
current_path := split(request.resource, "/") | ||
current_path[1] == "v2" | ||
current_path[2] == "entities" | ||
current_path[3] == entry.resource | ||
constraints := split(entry.constraint, " ") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if there's extra whitespace in the constraint? e.g. |
||
constraints[0] == "acl-oc:ResourceName" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how would we use this in teadal? every API would need to have its own rego file w/ a |
||
check_constraint(current_path[3], constraints[1], constraints[2]) | ||
} | ||
|
||
# Set the header link for the entities | ||
|
@@ -148,4 +162,4 @@ header_link = link { | |
current_path[2] == "subscriptions" | ||
not current_path[3] | ||
link := sprintf("<%s/me?resource=%s&&type=%s>; rel=\"acl\"", [api_uri,"*","subscription"]) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,37 @@ user_data = { | |
} | ||
} | ||
|
||
user_data_constraint = { | ||
"user_permissions": { | ||
"[email protected]": [ | ||
{ | ||
"action": "acl:Read", | ||
"resource": "test", | ||
"resource_type": "entity", | ||
"tenant": "Tenant1", | ||
"service_path": "/", | ||
"constraint": "acl-oc:ResourceName acl:operator:hasPart test" | ||
}, | ||
{ | ||
"action": "acl:Read", | ||
"resource": "foo", | ||
"resource_type": "entity", | ||
"tenant": "Tenant1", | ||
"service_path": "/", | ||
"constraint": "acl-oc:ResourceName acl:operator:eq foo" | ||
}, | ||
{ | ||
"action": "acl:Read", | ||
"resource": "6", | ||
"resource_type": "entity", | ||
"tenant": "Tenant1", | ||
"service_path": "/", | ||
"constraint": "acl-oc:ResourceName acl:operator:gt 5" | ||
} | ||
] | ||
} | ||
} | ||
|
||
group_data = { | ||
"group_permissions": { | ||
"/Group1": [ | ||
|
@@ -94,43 +125,63 @@ default_data = { | |
} | ||
|
||
test_user_permissions { | ||
allow.allowed with request as {"user":"[email protected]", "action":"GET", "resource":"/v2/entities/test", "tenant":"Tenant1", "service_path":"/"} with data as user_data with bearer_token as bearer_token with testing as true | ||
check_policy with request as {"user":"[email protected]", "action":"GET", "resource":"/v2/entities/test", "tenant":"Tenant1", "service_path":"/"} with policies as user_data with bearer_token as bearer_token with testing as true | ||
} | ||
|
||
test_user_permissions_contraint_1 { | ||
check_policy with request as {"user":"[email protected]", "action":"GET", "resource":"/v2/entities/test", "tenant":"Tenant1", "service_path":"/"} with policies as user_data_constraint with bearer_token as bearer_token with testing as true | ||
} | ||
|
||
test_user_permissions_contraint_2 { | ||
check_policy with request as {"user":"[email protected]", "action":"GET", "resource":"/v2/entities/foo", "tenant":"Tenant1", "service_path":"/"} with policies as user_data_constraint with bearer_token as bearer_token with testing as true | ||
} | ||
|
||
test_user_permissions_contraint_3 { | ||
not check_policy with request as {"user":"[email protected]", "action":"GET", "resource":"/v2/entities/foobar", "tenant":"Tenant1", "service_path":"/"} with policies as user_data_constraint with bearer_token as bearer_token with testing as true | ||
} | ||
|
||
test_user_permissions_contraint_4 { | ||
check_policy with request as {"user":"[email protected]", "action":"GET", "resource":"/v2/entities/6", "tenant":"Tenant1", "service_path":"/"} with policies as user_data_constraint with bearer_token as bearer_token with testing as true | ||
} | ||
|
||
test_user_permissions_contraint_4 { | ||
not check_policy with request as {"user":"[email protected]", "action":"GET", "resource":"/v2/entities/5", "tenant":"Tenant1", "service_path":"/"} with policies as user_data_constraint with bearer_token as bearer_token with testing as true | ||
} | ||
|
||
test_user_permissions_unathorized { | ||
not allow.allowed with request as {"user":"[email protected]", "action":"PATCH", "resource":"/v2/entities/test", "tenant":"Tenant1", "service_path":"/"} with data as user_data with bearer_token as bearer_token with testing as true | ||
not check_policy with request as {"user":"[email protected]", "action":"PATCH", "resource":"/v2/entities/test", "tenant":"Tenant1", "service_path":"/"} with policies as user_data with bearer_token as bearer_token with testing as true | ||
} | ||
|
||
test_user_permissions_entity_type { | ||
allow.allowed with request as {"user":"[email protected]", "action":"POST", "resource":"/v2/types/test", "tenant":"Tenant1", "service_path":"/"} with data as user_data with bearer_token as bearer_token with testing as true | ||
check_policy with request as {"user":"[email protected]", "action":"POST", "resource":"/v2/types/test", "tenant":"Tenant1", "service_path":"/"} with policies as user_data with bearer_token as bearer_token with testing as true | ||
} | ||
|
||
test_group_permissions { | ||
allow.allowed with request as {"user":"[email protected]", "action":"POST", "resource":"/v2/entities/test", "tenant":"Tenant1", "service_path":"/"} with data as group_data with bearer_token as bearer_token with testing as true | ||
check_policy with request as {"user":"[email protected]", "action":"POST", "resource":"/v2/entities/test", "tenant":"Tenant1", "service_path":"/"} with policies as group_data with bearer_token as bearer_token with testing as true | ||
} | ||
|
||
test_group_permissions_unathorized { | ||
not allow.allowed with request as {"user":"[email protected]", "action":"PATCH", "resource":"/v2/entities/test2", "tenant":"Tenant1", "service_path":"/"} with data as group_data with bearer_token as bearer_token with testing as true | ||
not check_policy with request as {"user":"[email protected]", "action":"PATCH", "resource":"/v2/entities/test2", "tenant":"Tenant1", "service_path":"/"} with policies as group_data with bearer_token as bearer_token with testing as true | ||
} | ||
|
||
test_role_permissions { | ||
allow.allowed with request as {"user":"[email protected]", "action":"GET", "resource":"/v2/entities/test", "tenant":"Tenant1", "service_path":"/"} with data as role_data with bearer_token as bearer_token with testing as true | ||
check_policy with request as {"user":"[email protected]", "action":"GET", "resource":"/v2/entities/test", "tenant":"Tenant1", "service_path":"/"} with policies as role_data with bearer_token as bearer_token with testing as true | ||
} | ||
|
||
test_role_permissions_unathorized { | ||
not allow.allowed with request as {"user":"[email protected]", "action":"PATCH", "resource":"/v2/entities/test2", "tenant":"Tenant1", "service_path":"/"} with data as role_data with bearer_token as bearer_token with testing as true | ||
not check_policy with request as {"user":"[email protected]", "action":"PATCH", "resource":"/v2/entities/test2", "tenant":"Tenant1", "service_path":"/"} with policies as role_data with bearer_token as bearer_token with testing as true | ||
} | ||
|
||
test_authenticated_agent_permissions { | ||
allow.allowed with request as {"user":"[email protected]", "action":"GET", "resource":"/v2/entities/test", "tenant":"Tenant1", "service_path":"/"} with data as authenticated_agent_data with bearer_token as bearer_token with testing as true | ||
check_policy with request as {"user":"[email protected]", "action":"GET", "resource":"/v2/entities/test", "tenant":"Tenant1", "service_path":"/"} with policies as authenticated_agent_data with bearer_token as bearer_token with testing as true | ||
} | ||
|
||
test_foaf_agent_permissions { | ||
allow.allowed with request as {"user":"[email protected]", "action":"GET", "resource":"/v2/entities/test", "tenant":"Tenant1", "service_path":"/"} with data as foaf_agent_data with testing as true | ||
check_policy with request as {"user":"[email protected]", "action":"GET", "resource":"/v2/entities/test", "tenant":"Tenant1", "service_path":"/"} with policies as foaf_agent_data with testing as true | ||
} | ||
|
||
test_default_agent_permissions { | ||
allow.allowed with request as {"user":"foobar", "action":"GET", "resource":"/v2/entities/test", "tenant":"Tenant1", "service_path":"/test/foobar"} with data as default_data with testing as true | ||
check_policy with request as {"user":"foobar", "action":"GET", "resource":"/v2/entities/test", "tenant":"Tenant1", "service_path":"/test/foobar"} with policies as default_data with testing as true | ||
} | ||
|
||
# test_api { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, but what about e.g. boolean operators? e.g. what would I do if I wanted to express a constraint like
(x < 5 && x > 10) || x > 20
...