./gradlew run
docker compose -f opa/docker-compose.yml up
Allowed
curl --user alice:password localhost:5000/finance/salary/alice
Forbidden
curl --user alice:password localhost:5000/finance/salary/charlie
On each HTTP request from a client to the API server, the API server asks the OPA server whether the requesting client is authorized to perform this action or not. Depending on the answer of OPA, the client request will be processed or rejected.
Why does the OPA server knows about the permissions of a client? From the policy!
- The policy is defined in the
example-policy.rego
file - From this file a bundle was built using the OPA executable
- This bundle is persisted in and shipped from the bundle server to the OPA server
- Make changes to the policy file
- Download and install the Open Policy Agent. Tip: drop the opa executable to ~/.local/bin, so it is on the PATH.
- Build the policy and move the resulting bundle to the correct folder so that it can be collected by the bundle server
cd opa opa build example-policy.rego mv bundle.tar.gz bundles
- Inspired by https://www.openpolicyagent.org/docs/latest/http-api-authorization/
- Corresponding python implementaion https://github.com/open-policy-agent/contrib/tree/main/api_authz