Query Structure
A query has two parts:- Predicate: the rule name from your policy (e.g.,
has_permission
). - Constraints: values to match, or wildcards (
_
).
Constraint Types
Type | Format | Example | Description |
---|---|---|---|
Exact value | Type:value | User:alice | Match this value exactly |
Type wildcard | Type:_ | User:_ | Match any value of this type |
Universal wildcard | _ | _ | Match any value of any type |
Default types in CLI
When you omit the type in CLI queries, Oso Cloud assumesString
:
view
becomesString:view
admin
becomesString:admin
Important: Type constraints match exactly. Subclasses don’t match parent types, even with Polar’s
extends
feature.Common Query Patterns
Example policy:Check if a user has permission
Check if a user has permission
(no results)
.Find all users with a permission
Find all users with a permission
User:_
to match any user. Returns all users who can view the organization.List a user's permissions
List a user's permissions
Find all resources a user can access
Find all resources a user can access
_
matches any resource type, not just organizations.Global rules
Global rules
Global rules apply across the system and are not tied to specific resources.
How Query Results Work
Oso Cloud returns facts that satisfy your query constraints. Facts come from:- Literal facts – Defined directly in policies or added via the API.
- Inferred facts – Derived by evaluating policies. For example, this query:
alice
to user
and acme
to org
, then searches for:
Queries vs Other APIs
Queries form the basis for all Oso Cloud APIs:authorize
queries theallow
predicate with your parameters.list
queries with wildcards to find accessible resources.bulk-authorize
runs multiple authorization queries.
Environment Scope
Each query runs against a single environment containing:- Your Polar policies (authorization logic)
- Your facts (users, roles, and relationships)
Troubleshooting
No results returned?
No results returned?
- Check that your facts exist with
oso-cloud facts list
- Verify policy syntax with
oso-cloud policy validate
- Use wildcards to broaden your search
Unexpected results?
Unexpected results?
- Test individual policy rules in isolation
- Check fact relationships with targeted role/permission queries
- Use the policy editor’s test feature
Need help with queries? Schedule time with an Oso engineer - we’re happy to help.