Skip to main content

SAPL Policy Enforcement Point (PEP) integration for Flask

Project description

sapl-flask

Policy-based authorization for Flask. 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 view functions 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.

@app.get("/patient/<patient_id>")
@pre_enforce(action="read", resource="patient")
def get_patient(patient_id):
    return {"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, HTTP 403 is returned. 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 SSE endpoints, 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 with the SaplFlask extension.

Getting Started

pip install sapl-flask
from flask import Flask
from sapl_flask.extension import SaplFlask
from sapl_flask.decorators import pre_enforce

app = Flask(__name__)
app.config["SAPL_BASE_URL"] = "https://localhost:8443"

sapl = SaplFlask(app)

For setup instructions, configuration options, the constraint handler reference, and the full API, see the Flask 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_flask-4.0.0rc2.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

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

sapl_flask-4.0.0rc2-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for sapl_flask-4.0.0rc2.tar.gz
Algorithm Hash digest
SHA256 f07cd41adc4fea366d906fe3239e8ef9dc717fc0c921f0daca455ade914056b1
MD5 411db7cc54964fc2e0e288faf970c3b2
BLAKE2b-256 7eeec5a4ed1a858052e9af29ac807758dfc1b7ffc5d37a2750e07cb71dc80b83

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for sapl_flask-4.0.0rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 5e05a5c51556d4cf9f3921460297bd316d94794f8a9c8a4fba2b3e1fe835bcb6
MD5 6edcee37129b0d4e422bd0d3b0fff1d9
BLAKE2b-256 d054f1b51248ab3e0ce54978a452d610fc10c860a93140cd8c764875cb67cf82

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