Skip to main content

varco-casbin

Casbin policy-engine authorization backend for varco — ACL, RBAC, and ABAC with dynamic, persisted policies and a ready-made REST management router.

varco_casbin implements the backend-agnostic policy seam defined in varco_core.auth.policy:

varco_core.auth.PolicyEngine        ← enforce(request) hot path
varco_core.auth.PolicyManagement    ← add/remove/list rules + role assignments
        ↑ both implemented by
varco_casbin.CasbinPolicyEngine     ← wraps casbin.AsyncEnforcer
        ↑ bridged into the service layer by
varco_core.auth.PolicyEngineAuthorizer  (opt-in via CasbinAuthorizationConfiguration)
        ↑ administered over REST by
varco_casbin.CasbinPolicyRouter     ← varco_fastapi GenericRouter (requires the [fastapi] extra)

Install

pip install varco-casbin                 # engine only (in-memory / file policies)
pip install "varco-casbin[sqlalchemy]"   # + durable SQL-backed policy store
pip install "varco-casbin[beanie]"       # + durable MongoDB-backed policy store (Beanie)
pip install "varco-casbin[fastapi]"      # + REST management router

Quick start (DI)

from providify import DIContainer
from varco_casbin.di import bootstrap, enable_policy_authorizer
from varco_core.auth import PolicyEngine, PolicyManagement, AbstractAuthorizer

container = bootstrap(DIContainer())  # scans the engine + settings
enable_policy_authorizer(container)  # opt-in: bind the authorizer

engine: PolicyEngine = await container.aget(PolicyEngine)
mgmt: PolicyManagement = await container.aget(PolicyManagement)

await mgmt.add_role_for_user("alice", "admin")  # g, alice, admin
await mgmt.add_policy("admin", "*", "*")  # p, admin, *, *

Configuration

All settings read from VARCO_CASBIN_* env vars (see CasbinSettings):

Env var Default Meaning
VARCO_CASBIN_MODEL_PRESET rbac acl / rbac / rbac_domains / abac
VARCO_CASBIN_MODEL_PATH explicit .conf model file (overrides preset)
VARCO_CASBIN_ADAPTER memory memory / file / sqlalchemy / beanie
VARCO_CASBIN_DB_URL SQLAlchemy URL for sqlalchemy, or Mongo URL for beanie
VARCO_CASBIN_DB_NAME MongoDB database name — required for adapter=beanie
VARCO_CASBIN_POLICY_PATH CSV path for the file adapter
VARCO_CASBIN_ADMIN_ROLE admin role the REST router requires by default

memory is non-durable (dev/test only); file is single-process (concurrent writers can corrupt the CSV); sqlalchemy and beanie both support dynamic, durable, concurrent CRUD — pick whichever matches the rest of your persistence stack.

REST management

Mount build_policy_router(...) (requires [fastapi]) to administer policies and role assignments over REST — all endpoints guarded by require_roles(admin_role):

from varco_casbin.router import build_policy_router

app.include_router(build_policy_router(engine, server_auth=auth))  # engine = CasbinPolicyEngine
GET/POST/DELETE /authz/policies   # p-rules
GET/POST/DELETE /authz/roles      # g-rules (role assignments)
POST            /authz/check      # test an enforcement decision
POST            /authz/reload     # reload from the durable store

See the varco docs (technical_docs/features/casbin-authorization.md) for the full guide, including the ABAC example.

Download files

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

Source Distribution

varco_casbin-3.0.0.tar.gz (46.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

varco_casbin-3.0.0-py3-none-any.whl (35.0 kB view details)

Uploaded Python 3

File details

Details for the file varco_casbin-3.0.0.tar.gz.

File metadata

  • Download URL: varco_casbin-3.0.0.tar.gz
  • Upload date:
  • Size: 46.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for varco_casbin-3.0.0.tar.gz
Algorithm Hash digest
SHA256 5e809c8553005e87f59c98e3a28ab758deb396e7e442b823bf7aab974c416a25
MD5 2a46c877ba2ed695759b4cb45873afc3
BLAKE2b-256 07a73c1aa15c893042f2f0b31b222892702938c230fb5e549b370f23ca61d058

See more details on using hashes here.

Provenance

The following attestation bundles were made for varco_casbin-3.0.0.tar.gz:

Publisher: release.yml on edoardoscarpaci/varco

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file varco_casbin-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: varco_casbin-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 35.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for varco_casbin-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 73c3793d731951d6def94f8b4f3bb453e8ec84544b6f1745878e20e53a1f7203
MD5 9b17a631d6efb70e0c4725e032a8b74e
BLAKE2b-256 7a91f938235bbd63a61000243d76720bde25113e1a4af6a76fb1d229e089dc7d

See more details on using hashes here.

Provenance

The following attestation bundles were made for varco_casbin-3.0.0-py3-none-any.whl:

Publisher: release.yml on edoardoscarpaci/varco

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

3.2.0

2 files

3.1.0

2 files

This release

3.0.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page