- Real world authorization policies and the associated metadata required to arrive at an authorization decision can be complex and extremely varied (snowflake) from org to org.
Auth0
can help with API authorization via a combination ofRules
,Roles
&Permissions
. This can be called asCoarse Grained Authorization (CGA)
.- However, when policies are/can become fine grained, it is advisable to externalize
Fine Grained Authorization (FGA)
to an org-wide centralized service for cleaner design, flexibility, scalability, CI/CD, and overall better management. OPA
can be the building block for such a service (FGAaaS) by serving as a centralized general purposePolicy Decision Point
.- This repository covers a sample application to demonstrate this pattern for a
Multi-tenant API
.
-
Client app acquires an
Auth0
issuedaccess_token
on behalf of the authenticateduser
- The standard Authorization Code Flow can be used here.
- This flow is not relevant to the authorization logic or decision and hence isn't covered here.
- The
access_token
can be decorated with custom claims usingAuth0 Rules
.- The only custom claim in use in this solution is
http://example.com/authn_loa
which indicates theLevel of Assurance
of the Authentication mechanism used while authenticating the user.
- The only custom claim in use in this solution is
- The standard Authorization Code Flow can be used here.
-
Client app makes an API call with the
access_token
.HTTP-METHOD
/api/v1/:tenant
/:resource
- e.g.
GET /api/v1/cocacola/content_route
- Authorization: Bearer
access_token
-
API code then requests OPA for an Authorization Decision
-
OPA computes the authorization decision
- OPA decodes the
access_token
and extractsuser_id
andauthn_loa
from thesub
andhttp://example.com/authn_loa
claims respectively. - Using all the info OPA then computes the authorization decision and responds to the API.
- OPA decodes the
-
API honours the decision and allows/denies the request.
-
Clone this repo
git clone https://github.com/jatinvaidya/api-fga-auth0-opa.git
-
Change to repo folder
cd api-fga-auth0-opa
-
Create
app/.env
andapi/.env
files referring to the respective.env.sample
files. -
Start
api
andopa
containersdocker-compose up
-
Feed
policy
anddata
to OPAcd opa
curl --request PUT --url http://localhost:8181/v1/policies/example --data-binary @policy.rego
curl --request PUT --url http://localhost:8181/v1/data/example --data-binary @data.json
-
Run the test app with some arguments and check results. See examples below.
docker run --net fga-network fga-demo/app-image:latest --username admin01@example.com --password Mju76yhn --tenant cocacola --resource vpc --action GET
docker run --net fga-network fga-demo/app-image:latest --username user01@example.com --password Mju76yhn --tenant cocacola --resource vpc --action DELETE