Fine-grained hierarchical RBAC for Litestar applications
Project description
litestar-permissions
Fine-grained hierarchical RBAC for Litestar applications.
Roles are scoped to resources and permissions inherit upward through the hierarchy. An org-admin role on Organization X grants those permissions on every project and application inside it. Built on SQLAlchemy 2.x, ships as a Litestar plugin.
Installation
uv add litestar-permissions
Quick Start
from litestar import Litestar, get
from litestar_permissions import PermissionsPlugin, PermissionsConfig, require_permission
from sqlalchemy.orm import DeclarativeBase
class Base(DeclarativeBase):
pass
config = PermissionsConfig(
hierarchy={"application": "project", "project": "organization"},
)
@get(
"/apps/{app_id:str}/deploy",
guards=[require_permission("application:deploy", resource_id_param="app_id")],
)
async def deploy(app_id: str) -> dict:
return {"status": "deploying"}
app = Litestar(
route_handlers=[deploy],
plugins=[PermissionsPlugin(config=config, base=Base)],
)
The plugin generates four SQLAlchemy tables (roles, permissions, role_permissions, user_role_assignments) bound to your Base. Guards check permissions at the resource scope, walking up the hierarchy to find matching role assignments.
How the Hierarchy Works
Define parent-child relationships between resource types:
PermissionsConfig(
hierarchy={
"application": "project", # application's parent is project
"project": "organization", # project's parent is organization
}
)
When checking application:deploy on a specific app, the resolver checks role assignments scoped to that app, then its parent project, then the parent org, then global. A match at any level grants the permission.
Development
make dev # install with all dev deps
make test # run tests
make lint # run prek hooks (ruff, ty, codespell)
make docs-serve # live-reload docs on localhost:8001
Documentation
Full docs at jacobcoffee.github.io/litestar-permissions.
License
MIT - see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file litestar_permissions-0.1.3.tar.gz.
File metadata
- Download URL: litestar_permissions-0.1.3.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d8d97a154569c5e6ceb1b7ebd524f93a0d18b3f20348c7902bc285df8a19123
|
|
| MD5 |
3be54cd000fb94c7fb7a9676b3d1209a
|
|
| BLAKE2b-256 |
8ba600fed455189d922457824c594a672ece08013957bafbf69183e4a078cc5a
|
Provenance
The following attestation bundles were made for litestar_permissions-0.1.3.tar.gz:
Publisher:
publish.yml on JacobCoffee/litestar-permissions
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
litestar_permissions-0.1.3.tar.gz -
Subject digest:
7d8d97a154569c5e6ceb1b7ebd524f93a0d18b3f20348c7902bc285df8a19123 - Sigstore transparency entry: 1002382425
- Sigstore integration time:
-
Permalink:
JacobCoffee/litestar-permissions@5a10cf9ad9cfb074ca4c06b8091ba0b2d4fda87a -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/JacobCoffee
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5a10cf9ad9cfb074ca4c06b8091ba0b2d4fda87a -
Trigger Event:
push
-
Statement type:
File details
Details for the file litestar_permissions-0.1.3-py3-none-any.whl.
File metadata
- Download URL: litestar_permissions-0.1.3-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff63c0c773a5bb21b624fb0a0bcb16b6e59cc825581c8e830e4365df5c8d2619
|
|
| MD5 |
ab2ee11a3d28682363068307a5e3efd4
|
|
| BLAKE2b-256 |
e1066c6f1ca3ef57a581fb2b6e8483005b7db6965c4e796a33ff843272d649d1
|
Provenance
The following attestation bundles were made for litestar_permissions-0.1.3-py3-none-any.whl:
Publisher:
publish.yml on JacobCoffee/litestar-permissions
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
litestar_permissions-0.1.3-py3-none-any.whl -
Subject digest:
ff63c0c773a5bb21b624fb0a0bcb16b6e59cc825581c8e830e4365df5c8d2619 - Sigstore transparency entry: 1002382434
- Sigstore integration time:
-
Permalink:
JacobCoffee/litestar-permissions@5a10cf9ad9cfb074ca4c06b8091ba0b2d4fda87a -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/JacobCoffee
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5a10cf9ad9cfb074ca4c06b8091ba0b2d4fda87a -
Trigger Event:
push
-
Statement type: