Source-Level Authorization
The#authorize annotation controls who can access a source. This allows you to restrict which users or groups can query a source — even if do not have access to the package. The annotation takes a JavaScript boolean expression that determines whether access is granted.
When a request attempts to access a source with an #authorize annotation, the Credible service evaluates the boolean expression. If the expression evaluates to true, access is granted; otherwise, an authorization error is returned.
The Credible service provides two variables for authorization checks:
USER: A string containing the user ID associated with the requestJWT: A JSON object containing user attributes (see User Attributes below)
isMember(USER, 'group_name'), which returns true if the user access to the specified group — directly or transitively.
Combining with Row Filters
You can combine#authorize with a where: clause to both restrict access and filter which rows are visible:
User Attributes
User attributes are values associated with a user—such as their region, tenant, or department. They enable dynamic authorization checks and row-level filtering based on who is querying the data.How It Works
- Your service calls the Credible API to mint a JWT containing user attributes (e.g.,
region: 'west') - The user includes this JWT when making queries
- The JWT’s attributes can be used in authorization checks or can be bound to a Malloy parameter using the
#bindannotation.
Authorization with User Attributes
You can use JWT attributes directly in#authorize expressions to control source access:
role: 'admin'. If not, the request is denied.
Binding User Attributes to Parameters
The#bind annotation connects a JWT attribute to a source parameter. This parameter can then be used in a where: clause to automatically filter rows based on the user’s attributes.
region: 'west' in their JWT queries this source, the user_region parameter is automatically set to 'west', and they only see rows where sales_region = 'west'.
Example: Multi-Tenant Embedded Analytics
If you’re building an analytics dashboard for your customers (e.g., using the Publisher SDK), you can use attribute binding to ensure each customer only sees their own data:tenant_id: 'acme', they only see rows where customer_id = 'acme'. This ensures complete data isolation between tenants without requiring separate data sources.
Have custom access control requirements? Contact us to discuss your use case.