Skip to main content

SAPL Policy Enforcement Point (PEP) integration for Django

Project description

sapl-django

Policy-based authorization for Django. Write access control rules as external SAPL policy files and enforce them at runtime through decorators like @pre_enforce and @post_enforce. Policies can be updated without code changes or redeployment.

How It Works

Your application decorates views with enforcement decorators. SAPL intercepts the call, sends an authorization subscription to the Policy Decision Point (PDP), and enforces the decision, including any obligations or advice the policy attaches.

@pre_enforce(action="read", resource="patient")
async def get_patient(request, patient_id):
    return JsonResponse({"id": patient_id, "name": "Jane Doe", "ssn": "123-45-6789"})
policy "permit doctors to read patient data"
permit
  action == "read"
where
  "DOCTOR" in subject.roles;

If the PDP permits, the view runs. If not, PermissionDenied is raised. If the decision carries obligations (like access logging or field redaction), they are enforced automatically through registered constraint handlers.

What You Get

SAPL goes beyond simple permit/deny. Decisions can carry obligations that must be fulfilled, advice that should be attempted, and resource transformations that modify return values before they reach the caller. The library handles all of this transparently.

For streaming views, streaming decorators (@enforce_till_denied, @enforce_drop_while_denied, @enforce_recoverable_if_denied) maintain a live connection to the PDP, so access rights update in real time as policies, attributes, or the environment change. Built-in constraint handlers cover JSON field redaction and collection filtering. Writing custom handlers follows a simple registration pattern via Django app configuration.

Getting Started

pip install sapl-django
INSTALLED_APPS = [
    "sapl_django",
    ...
]

MIDDLEWARE = [
    "sapl_django.middleware.SaplRequestMiddleware",
    ...
]

SAPL_CONFIG = {
    "base_url": "https://localhost:8443",
}

For setup instructions, configuration options, the constraint handler reference, and the full API, see the Django documentation.

Links

License

Apache-2.0

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

sapl_django-4.0.0rc2.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

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

sapl_django-4.0.0rc2-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file sapl_django-4.0.0rc2.tar.gz.

File metadata

  • Download URL: sapl_django-4.0.0rc2.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sapl_django-4.0.0rc2.tar.gz
Algorithm Hash digest
SHA256 6f6a563a96a20971e1ebe580cbdf2686ecc473059a20f82af955e25b92a8b29e
MD5 bcb61db77f8dc2110addeadc3549022b
BLAKE2b-256 f78de30c54a8f7456b4746f41c7450c03d17fd68c1948e2707f53792c6fd904d

See more details on using hashes here.

File details

Details for the file sapl_django-4.0.0rc2-py3-none-any.whl.

File metadata

  • Download URL: sapl_django-4.0.0rc2-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sapl_django-4.0.0rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 b296c2c9e5fb9cbc098720fffd1e8484e1653fe9f61815046cd17cedbef08aeb
MD5 8894dc0a718b6b0b2f767bfb27a5db3a
BLAKE2b-256 d2e3d22cc35aea58d3fa94d98ba241a63ccf9ae7c05e4f308270bd9a9b00bdcd

See more details on using hashes here.

Supported by

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