Skip to main content

Simple RBAC library

Project description

rbact

A simple RBAC library with different ORM adapters

  • has sync and async implementation
  • supports peewee/peewee_async
  • stores access data in normal form
  • doesn't use cache (at least right now), so doesn't need to reload data and performs best with small role inheritance tree

Content

Installation

pip install rbact

Docs

Peewee hello world

from peewee import PostgresqlDatabase
import rbact

db = PostgresqlDatabase('my_app', user='postgres', password='secret',
                           host='10.1.0.9', port=5432)

adapter = rbact.peewee.PeeweeAdapter(db)
adapter.create_tables()
inspector = rbact.Inspector(adapter)
result = inspector.has_access('user', 'resource', 'write')

With peewee your application needs to close connections explicitly. adapter.create_tables() and inspector.has_access() methods follow this logic and don't close connections by themselves.

Peewee async example with a connection pool and model extensions

import peewee as pw
from peewee_async import PooledPostgresqlDatabase, Manager
from rbact import peewee_async as rbact_peewee, AsyncInspector

db = PooledPostgresqlDatabase('my_app', user='postgres', password='secret',
                           host='10.1.0.9', port=5432)
db_manager = Manager(db)

# model extension
class Users(rbact_peewee.Users):
    class Meta:
        table_name = 'custom_users'
    email = pw.TextField()

async def main():
    loader = rbact_peewee.ModelsLoader(db_manager.database, users_model=Users)
    adapter = rbact_peewee.AsyncPeeweeAdapter(db_manager, models_loader=loader)
    inspector = AsyncInspector(adapter)
    result = await inspector.has_access('user', 'resource', 'write')

How it works?

Rbact uses 4 tables to store data, default tables look like this: Tables All these tables can be created automatically with adapter.create_tables(). You can extend any table using inheritance but default columns mustn't be changed.

Rbact rules examples

The user who wants to access, the object (or resource) to which access is requested, the action that the user wants to do

analyst, company_metrics, read
employee, /api/write_task, write 

Superuser

from peewee import PostgresqlDatabase
import rbact

db = PostgresqlDatabase('my_app', user='postgres', password='secret',
                           host='10.1.0.9', port=5432)

adapter = rbact.peewee.PeeweeAdapter(db)
inspector = rbact.Inspector(adapter)
inspector.superuser = 'root'  # default value is admin
inspector.superuser = None  # disable superuser

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rbact-1.0.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

rbact-1.0.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file rbact-1.0.0.tar.gz.

File metadata

  • Download URL: rbact-1.0.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for rbact-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a2cccd6c27369fd4e39858582b767fa713104591c2e48b2450a141ad64c8fe9d
MD5 f20271c924914a012aadfecacc8557d8
BLAKE2b-256 557b14250503e3bb6b48aef5ea10d45d09dd62ec32a7bf98c03e0244e5ba7755

See more details on using hashes here.

File details

Details for the file rbact-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: rbact-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for rbact-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 45339360413dcf4a07c6c0029d6bb00c53da3830cf7789a9cf8db68d70b246c8
MD5 52c9e55e908e44583259e5cd49baeda9
BLAKE2b-256 787cffc2aadd125c4cb55ea6c7517568661c5d7521a4c8efab9bbd9320c70d57

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page