Support fine grained user permissions #160
sriramsub
started this conversation in
Feature design
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This proposal is subjected to change. We are documenting the design publicly to get feedback and design together with the community.
User authorization
Nile provides an easy way to add basic authorization to your application.
In the future, we’ll provide the ability to add more sophisticated permissions (see design below).
Basic authorization
Currently, Nile supports simple user authorization via SQL, the SDK, and NextJS middleware, which seamlessly integrates authentication with authorization. To authorize by user, you must set a user context.
💡 Due to current limitations in Nile, you must set a tenant context (link to tenant isolation) before setting the user context.With both the user and tenant context set, subsequent queries return data that only the specified user can access, only if they’re part of the specified tenant.
In SQL
The user context is set via the
nile.user_idvariable.SDK
Permissions
In the future, Nile will provide the ability to configure advanced permissions for your application. Below is an initial design. Suggestions and feedback are greatly appreciated.
Terminology
There are several key concepts in Nile permissions:
Resource - What is being accessed. Initially, we plan to support rows.
Principal - Who accesses a resource. We plan to start with users but hope to support many different kinds of principals in the future (i.e. developers, service accounts, etc).
Action - Something a principal does on a resource (i.e.
closeonissues,readonrepos).Role - A named grouping of actions and optional conditions, like
maintainer, oradmin.High-level overview
The steps to setting up permissions in Nile are:
Creating tables
Let’s imagine we’re GitHub and would like to implement access control in our application.
First, we need to create some tables:
Defining actions
In Nile, permissions are enforced on each SQL query. When Nile receives a query like
UPDATE issues SET closed = true WHERE id = '123', it has to know what to enforce access control for. Defining actions on resources is the first step to setting up access control in Nile.API
Using the API, we’ll define a
closeaction onissuesthat get enforced on queries that try to update theclosedcolumn totrue:create→INSERTread→SELECTupdate→UPDATEdelete→DELETECreating policies
A policy is how you define permissions in Nile and consists of actions and conditions.
A policy consists of
allowanddenyblocks.allowpermissions mean a principal is allowed to perform that action, and permissions in “deny” means a principal is denied (even if a matchingallowpermission is found).Here’s a simple policy that allows deleting issues:
Here’s a policy that allows a principal to close issues where the
stalefield is true. Conditions are expressed in SQL (think what comes afterWHERE).Assigning policies
You can assign policies directly principals. In the future, we hope to support more flexible policy assignments using conditions.
Creating roles
Roles are a useful way to group policies. Here’s an issue maintainer role that allows a principal to delete and close stale issues:
Assigning roles
You can assign roles to individual principals. In the future, we hope to support more flexible role assignments using conditions.
Beta Was this translation helpful? Give feedback.
All reactions