Liam Taylor
08/27/2025, 10:24 AMAsk Inkeep
08/27/2025, 10:24 AMLiam Taylor
08/27/2025, 10:24 AMPermit.filter_objects with this data and the rest of the required stuff, which return the filtered data set
• (if the data sent to permit is a subset of the data the full data set based on the filter_objects response
under the hood, my understanding is that permit
• makes an external API call to get relevant permissions
• filters the data in python code based on those permissions
currently our filtering is applied as the database layer. i'm worried that moving this to permit wouldn't be scalable based on latency of building in an external API request, the amount of data needing to be transferred (if all filtering logic is covered by permit, then that is effectively always an entire database table), and the efficiency of filtering large data sets in python.
can you advise to this end? i am very aware that i am possibly misinterpreting certain things. ideally i would be able to use permit's permissions to create appropriate SQL queries that reflect the permissions. this is in line with the source-level filtering references in this section of the docs - is there any guidance on implementing this? is this out of the box functionality?Ask Inkeep
08/27/2025, 10:24 AM@check_permit_permission decorator to your Django views (2) :
@check_permit_permission(action="read")
def list(self, request) :
queryset = self.get_queryset()
serializer = self.serializer_class(queryset, many=True)
return Response(serializer.data)
3. ​*Implementing the permission check middleware*​ (1) :
from permit.sync import Permit
from dotenv import load_dotenv
from django.http import JsonResponse
from django.views import View
load_dotenv()
permit = Permit(
pdp= os.getenv("permit_pdp_url") ,
token= os.getenv("permit_sdk_key")
)
class PatientDetailView(View) :
def get(self, request, patient_id) :
permitted = permit.check(request.user.email, "view", "patient_record")
if not permitted:
return JsonResponse({"error": "Access denied"}, status=403)
# Retrieve and serialize patient data
patient = Patient.objects.get(id=patient_id)
serialized_patient = PatientSerializer(patient) .data
return JsonResponse(serialized_patient, status=200)
(3)
Feel free to share your specific questions in the thread - I'm here to help with the implementation details!Ask Inkeep
08/27/2025, 10:25 AMAlon Boshi
08/27/2025, 10:27 AMLiam Taylor
08/27/2025, 10:29 AMLiam Taylor
08/27/2025, 10:30 AMOr Weis
08/27/2025, 10:36 AMGabriel L. Manor
08/27/2025, 4:17 PMSam Jakos
09/24/2025, 6:04 PMAsk Inkeep
09/24/2025, 6:04 PMpermit support automation2
09/24/2025, 6:04 PMAsk Inkeep
09/24/2025, 6:04 PMcompile API and is available within Permit's PDP (1) . It also notes that "Simplified Partial-evaluation" is described as "an upcoming feature in advanced stages of release, which includes built-in translation to SQL" .
For the most current approach, Permit offers "early access support for Postgres partial evaluation, enabling policy rules to be directly converted into SQL queries without requiring manual Rego or policy compilation" (2) .
Trino Integration for Database Filtering
The Trino integration works by introspecting your database schema and creating a comprehensive policy model in Permit (3) . Here's how it helps with filtering:
How Trino Setup Works:
permit env apply trino --url <http://localhost:8080> --user admin --api-key permit_key --catalog postgresql --schema public
This command maps your database structure to Permit resources :
• Tables → trino-table-<catalog>-<schema>-<table>
• Columns → trino-column-<catalog>-<schema>-<table>-<column>
• Views → trino-view-<catalog>-<schema>-<view>
Available Filtering Approaches
For database-level filtering instead of application-layer, you have these options (1) :
1. ​*PDP-Level Filtering Based on the Information Graph*​ - Returns pre-filtered objects based on data synchronized with the PDP in advance using functions like getUserPermissions and getAuthorizedUsers . The allowed objects returned from the authorization graph are added to the DB query before making the query .
2. *Source-Level Filtering (Partial Evaluation) * - The PDP returns a query basis (e.g., SQL) that is sent or appended to an existing query and sent to the database, which returns the relevant data pre-filtered . This capability exists in OPA under the compile API and is already available within Permit's PDP .
Example of Information Graph Approach:
Instead of bulk checking after fetching data, you can query permitted resources first (2) :
// Ask the PDP which 'documents' Alice can read (across tenants, or just one)
const userPermissions = await permit.getUserPermissions("<mailto:alice@example.com|alice@example.com>", [], [], ["document"]) ;
// Extract the allowed document IDs
const allowedDocIDs = userPermissions
.filter(entry => entry.resourceType === "document")
.map(entry => entry.resourceKey) ;
// Fetch only permitted documents from the DB
const permittedDocs = await db.Document.find({ id: { $in: allowedDocIDs } }) ;
This approach identifies the subset of authorized documents in advance, avoiding fetching irrelevant rows in the first place .
The Trino integration essentially creates the policy structure needed to support these filtering approaches by mapping your database schema to Permit's authorization model.Ask Inkeep
09/24/2025, 6:04 PMOr Weis
09/24/2025, 7:24 PMSam Jakos
09/24/2025, 7:54 PMOr Weis
09/24/2025, 8:19 PMSam Jakos
09/26/2025, 1:04 PMGabriel L. Manor
09/26/2025, 3:01 PMenv apply trino that implements the Trino schema as a Permit policy schema. Then, you can connect it to CI/CD or other automated workflows that listen to the schema changes. Read the docs here:
https://github.com/permitio/permit-cli?tab=readme-ov-file#env-apply-trino
We also have some built-in pdp functions to help with filtering, @Dan can shed some more light on it.