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:
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
Metadata
Release files for rbact 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| rbact-1.0.0.tar.gz | 6.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rbact-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.8 kB
Release files / rbact-1.0.0.tar.gz
| Download URL | rbact-1.0.0.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a2cccd6c27369fd4e39858582b767fa713104591c2e48b2450a141ad64c8fe9d
|
|
BLAKE2b-256 checksum How to use checksums |
557b14250503e3bb6b48aef5ea10d45d09dd62ec32a7bf98c03e0244e5ba7755
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / rbact-1.0.0-py3-none-any.whl
| Download URL | rbact-1.0.0-py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
45339360413dcf4a07c6c0029d6bb00c53da3830cf7789a9cf8db68d70b246c8
|
|
BLAKE2b-256 checksum How to use checksums |
787cffc2aadd125c4cb55ea6c7517568661c5d7521a4c8efab9bbd9320c70d57
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for rbact 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.