- Evaluating to a boolean value to express authorization
- Filtering out rows representing unauthorized resources
Support for other databases
Support for other databases is under active development, including MySQL and MongoDB. If you use a different database and want to leverage Local Authorization, share your use case to help us prioritize integrations.When to use Local Authorization
- Your service uses a PostgreSQL database
-
All data needed to make authorization decisions is available:
- In the PostgreSQL database
- Through centralized authorization data
reader
andwriter
roles) can use Local Authorization once the tenant-level roles for users (managed by another service) are synchronized to Oso as centralized data. - Your database can handle the additional query load of making authorization checks.
-
Your authorization logic does not rely on any of these currently
unsupported features:
- Logic that grants access to all resources based on database data
- Inequality comparisons between Oso Cloud data and database data
-
Recursive logic that mixes centralized facts with database facts
-
For example:
This rule can be evaluated if both
has_relation
andhas_permission
facts are kept entirely local or entirely in Oso Cloud. It cannot be evaluated if one is local and the other is centralized.
-
For example:
Overview
At a high level, to use Local Authorization:- Configure how facts in your policy correlate to tables in your database using a Local Authorization config file.
- Call the local check API in your application’s authorization
enforcement code. This API returns a SQL expression –– either a full query or a
fragment to use in another query’s
WHERE
clause. - Use the returned SQL query fragment when querying the database stores your authorization data.
Config
When Oso evaluates authorization requests, it aggregates sets of facts that, if true, satisfy the request. With Local Authorization, Oso needs to translate facts into expressions your database can evaluate. For example,has_role(User{"alice"}, "admin", Organization{"acme"})
You provide this translation in a YAML configuration file:
facts
The facts
section is required and is where the majority of your configuration
logic lives. It contains one key per fact signature stored in your
database.
A fact signature consistes of:
- A predicate (e.g.
has_role
,has_relation
). - A parenthesized list of comma-separated arguments (e.g.
User:_
,String:admin
)
query
value that returns rows matching the signature.
The _
symbol in a fact signature indicates that the <id>
of the entity is a
variable returned by the query
. For example, the signature
Issue
that has a parent
Repository
”.
The query
value for a signature must return the same number of columns as
there are wildcards in the signature. For example:
Additional restrictions
- Fact signatures must be referenced in rules in your policy.
- Fact signatures also must not overlap. For example:
-
Each
query
must be aSELECT
statement (Technically a<query specification>
per SQl-92). Common table expressions (CTEs), subqueries, and set expressions likeUNION
are allowed, but they must also be aSELECT
. The following is not valid, because the CTE is anUPDATE
statement:
sql_types
sql_types
maps resource types in Oso Cloud (e.g. Issue
, Repository
) to their
database column types. This helps Oso generate queries that use indices
effectively.
This section is optional, but strongly recommended.
Example
has_relation
facts that associate issues with
their parent repositories.
Validate Local Authorization configuration
You can validate the configuration using the oso-cloud CLI. Include this check as part of your CI/CD pipeline. For more guidance, see CI and Testing.Guides
Local Check API
After configuring Local Authorization for your application, the local check API performs authorization using data distributed across Oso Cloud and your own database. The methods are documented under the appropriate Client SDK. Note that centralized facts still affects Local Authorization decisions.Related content
- For a comprehensive example of Local Authorization, see Ruby on Rails list filtering sample app
- Facts: The Oso Cloud data model
- Reference documentation
- Local Authorization Guide