Git Product home page Git Product logo

skygear-rbac's Introduction

๐Ÿšฆ RBAC service for Skygear

NOTE: This service uses casbin as db name, all records e.g. policy, group are under casbin_rule table

Development

Requirements

  • Docker
  • Go 1.12

Get started

make setup-dev
# We use docker for our database for development
docker-compose up
# Run app
DATABASE_URL=postgresql://postgres:@localhost:5432/postgres?sslmode=disable go run main.go
# or
make run-dev

Testing

make test

Docker

docker pull oursky/skygear-rbac

docker run -e "DATABASE_URL=abc" oursky/skygear-rbac:latest

Current model

(
  (g(r.domain, p.domain) || g('root', r.sub)) && # request domain is SAME as policy domain (to disable inheritance of access rights)
  (
    (g2(r.sub, p.sub, r.domain) || (r.sub == p.sub && r.domain == p.domain)) || # request subject is assigned role/is the role in domain
    (g2(r.sub, p.sub, 'root') || (r.sub == p.sub && r.domain == 'root')) # request subject is assigned role/is the role in root
  )
) &&
(r.obj == p.obj || p.obj == '.*') &&  # request object matches policy
(r.act == p.act || p.act == '.*') && # request action matches policy
!g4(r.sub, 'disabled') && # subject in request is not disabled / archived
!g4(p.sub, 'disabled') # subject in policy is not disabled / archived

skygear-rbac's People

Contributors

cychiuae avatar inizio avatar rickmak avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

inizio cychiuae

skygear-rbac's Issues

Rewrite RBAC without Casbin?

Background

Initially we chose casbin because it provides the most flexibility in terms of authorization model.

Why Casbin might not be best solution

Confusing model

After using in project, the dynamic model syntax especially policy_matcher is actually confusing.

We might argue that the dynamic model is useful for projects that are at prototype stage. The problem is this library does not offer any way to migrate according to model changes. For example you cannot add another column in policy.

Bad performance

If we put the model aside, Casbin is no different from simply querying for object + subject + action (+ domain) and then return effect.

Policy matcher makes it impossible to perform pagination or filtering, since the matcher itself will be parsed into golang code and executed on each record.

The only thing people need to customize is inheritance, which seems better resolved by adding a table.

Also searching for all roles is not done with recursive query since they need to consider compatitablity among non-db adaptors.

Cannot be used in listing

It is fine to get each record, run enforce request on it. This however is not performant to apply on record listing.

One possible way to have per-record access control would be:

  1. User has a table which needs access control e.g. file
  2. User adds a JSON column 'access'
{
  "view": ["user_id1", "role_id1", "role_id2"]
}
  1. User provides a webhook for RBAC to update permissions
  2. When list the table, list of roles associated to user is fetched and user write their own query to match if the ids overlap with 'access'

[RBAC] Beta

  • Domain CRUD
  • Role CRUD
  • Policy CRUD
  • Enforce policy
  • Test cases

[RBAC] Provide useful error feedback

Tasks

  • Validate request params and return error if not accepted e.g. empty subject
  • Add logging
    • Request params
    • Enforcer errors e.g. Invalid policy format in persist storage
  • Return updated result for e.g. role assignments

Support Sentry in RBAC

Currently RBAC fails and screams silently, maybe add Sentry support so that it can scream in logs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.