c3g-flask-opa
The Flask library every Tier 3 C3G app adopts, whether it's 3a (oauth2-proxy stays in
front) or 3b (in-app OIDC via c3g-oidc) — see
web-app-template's for-app-developers.md
(#flask) and README.md for where this fits among the authentication/authorization tiers.
A before_request hook, not a policy engine: it reads your app's groups from wherever your
tier puts them, shapes them into whatever input your app's OPA policy expects, calls your
app's local OPA sidecar, and enforces the answer. The actual authorization rules never live
here or in your app — they live as Rego in
c3g-opa-policies, one directory per app.
Status: working, and verified against a real OPA server. Its default input shape
({method, path, groups_header}) is the one C3G's policies in c3g-opa-policies are written
for, and this repo's test suite runs the library against a real opa run --server instance
loaded with an example policy of that shape, asserting its allow/deny outcomes end to end. See
CLAUDE.md for how to run that yourself.
Pre-1.0: the API may change between minor versions until a first app has adopted it.
Install
pip install c3g-flask-opa
Usage
from flask import Flask, request
from c3g_flask_opa import FlaskOPA, groups_header_from_request
app = Flask(__name__)
opa = FlaskOPA(
app,
groups_source=groups_header_from_request(), # Tier 3a: reads X-Forwarded-Groups
policy_path="project_tracking/authz/allow", # matches the Rego package + rule name
)
@app.route("/healthz")
@opa.exempt
def healthz():
return "ok"
That's the whole integration for an app whose OPA input shape is {method, path, groups_header} (the default). If your app's policy expects something else, pass your own
input_builder:
opa = FlaskOPA(
app,
groups_source=groups_header_from_request(),
input_builder=lambda groups_header: {"action": request.view_args.get("action"), "groups": groups_header},
policy_path="my_app/authz/allow",
)
For a Tier 3b app (in-app OIDC, no oauth2-proxy), swap the groups source for the one that
reads flask.g after c3g-oidc has validated the Bearer token:
from c3g_flask_opa import groups_header_from_g
opa = FlaskOPA(app, groups_source=groups_header_from_g(), policy_path="project_tracking/authz/allow")
FlaskOPA reads the OPA sidecar's URL from the C3G_OPA_URL environment variable by default,
falling back to http://10.0.2.2:8181 — the host-loopback address used throughout
web-app-template's deployment docs — or pass opa_url= explicitly.
Fails closed. Any error reaching OPA (network failure, timeout, non-2xx response, malformed body) is treated as a deny, not an allow — an OPA outage should block requests, not silently disable authorization.
Metadata
Release files for c3g-flask-opa 0.1.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 | |
|---|---|---|---|---|
| c3g_flask_opa-0.1.0.tar.gz | 22.3 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| c3g_flask_opa-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 42.0 kB
Release files / c3g_flask_opa-0.1.0.tar.gz
| Download URL | c3g_flask_opa-0.1.0.tar.gz |
|---|---|
| Size | 22.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
be5f174cad45e09077890cb1ee3e0492a255733f0bf6da029d948f66bd764ccb
|
|
BLAKE2b-256 checksum How to use checksums |
575367ab58d429f83af490848fd8f6e8209ef71e4fdb734092d057aeb2151edd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.
Transparency logRelease files / c3g_flask_opa-0.1.0-py3-none-any.whl
| Download URL | c3g_flask_opa-0.1.0-py3-none-any.whl |
|---|---|
| Size | 19.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c56b76c99f82a9fd98eeacdec103ba39007118b8da6c4b0c3b8464a676544152
|
|
BLAKE2b-256 checksum How to use checksums |
5f478f320d4321fc97233fbafec619faa68b5db58faa7fb1e86f7f349a16831d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.
Transparency logSecurity for c3g-flask-opa 0.1.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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for c3g_flask_opa-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.
Transparency logA 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.