How anish-anish/opa-sql-governance works
This repository is a SQL governance PEP/PDP prototype. Its intended workflow inspects client SQL, requests an OPA decision using user and query attributes, rejects prohibited columns, and scopes authorized execution through PostgreSQL RLS. The graph also preserves the mock authorization service and the documented governance-contract and self-access capabilities. Source excerpts show SQL extraction, decision requests, SQL rewriting, database execution, and mock endpoints; the README documents native RLS and the real OPA deployment. The README describes an end-to-end path, but the shown sql_auth.py main exits before executing its rewritten query, so that connection is marked unverified.
Main entry points: sql_auth.py PEP workflow · column_extract.py SQL AST extractor · mock_opa_server.py Mock OPA API · query_executor.py Postgres executor
Components 15
SQL inspection
- PEP workflow
sql_auth.py - SQL AST extractor
column_extract.py - SQL rewriter
sql_auth.py
Policy authorization
- OPA PDP
- Rego policies
policy.rego - Policy data
policy_data.json - Mock OPA API
mock_opa_server.py
SQL execution
- Postgres executor
query_executor.py - PostgreSQL
- Native row security
demp.sql - Filtered results
Governance controls
- Governance contracts
mock_opa_server.py - Self-access rules
policy_data.json
Other components
- SQL client
- User profile
Connections 16
- SQL client → PEP workflow: submits SQL
README.md - PEP workflow → SQL AST extractor: extracts columns
sql_auth.py - SQL AST extractor → PEP workflow: returns references
sql_auth.py - User profile → PEP workflow: provides attributes
README.md - PEP workflow → OPA PDP: requests decision
sql_auth.py - OPA PDP → Rego policies: evaluates policies
README.md - OPA PDP → Policy data: uses policy data
README.md - PEP workflow → Mock OPA API: posts decision request
README.md - Mock OPA API → Governance contracts: returns decision
mock_opa_server.py - Self-access rules → OPA PDP: defines exceptions
README.md - OPA PDP → PEP workflow: returns decision
README.md - PEP workflow → SQL rewriter: builds scoped SQL
sql_auth.py - SQL rewriter → Postgres executor: passes authorized SQL
- Postgres executor → PostgreSQL: executes SQL
query_executor.py - PostgreSQL → Native row security: enforces row policies
README.md - Native row security → Filtered results: filters rows
README.md