This guide explains how to run Open Policy Agent (OPA) for this project and how to test the policy using Postman.
- Docker (and Docker Compose) — for running OPA in a container
- Postman (or any HTTP client) — for testing the API
From the project root:
docker compose up -d- OPA API: http://localhost:8181
- Stop:
docker compose down - View logs:
docker compose logs -f opa
From the project root:
./scripts/run-project.shThis starts OPA in a container with the policies/ directory mounted and port 8181 exposed.
Health check
- Method: GET
- URL:
http://localhost:8181/health
Expected: 200 OK with a JSON body indicating OPA is healthy.
The project has two policies. Query them via the Data API.
- Method: POST
- URL:
http://localhost:8181/v1/data/authz/allow - Headers:
Content-Type: application/json
- Body (raw JSON):
{
"input": {
"user": "admin"
}
}Expected response: 200 OK with body like:
{
"result": true
}- Method: POST
- URL:
http://localhost:8181/v1/data/authz/allow - Headers:
Content-Type: application/json
- Body (raw JSON):
{
"input": {
"user": "alice"
}
}Expected response: 200 OK with body like:
{
"result": false
}- Method: POST
- URL:
http://localhost:8181/v1/data/authz - Headers:
Content-Type: application/json
- Body (raw JSON):
{
"input": {
"user": "admin"
}
}Expected response: 200 OK with something like:
{
"result": {
"allow": true
}
}Role-based access: admin can do anything; user can only perform read actions.
- Method: POST
- URL:
http://localhost:8181/v1/data/rbac/can_access - Headers:
Content-Type: application/json - Body (admin — allowed):
{
"input": {
"role": "admin",
"action": "write"
}
}Expected: {"result": true}
- Body (user + read — allowed):
{
"input": {
"role": "user",
"action": "read"
}
}Expected: {"result": true}
- Body (user + write — denied):
{
"input": {
"role": "user",
"action": "write"
}
}Expected: {"result": false}
- Create a new request.
- Set method to POST and URL to
http://localhost:8181/v1/data/authz/allow. - In Headers, add
Content-Type: application/json. - In Body, choose raw and JSON, then paste:
{"input": {"user": "admin"}}for allowed, or{"input": {"user": "alice"}}for denied.
- Send the request and check that
resultistrueorfalseas expected.
| Purpose | Method | URL |
|---|---|---|
| Health check | GET | http://localhost:8181/health |
Query authz.allow |
POST | http://localhost:8181/v1/data/authz/allow |
Query rbac.can_access |
POST | http://localhost:8181/v1/data/rbac/can_access |
Query full authz |
POST | http://localhost:8181/v1/data/authz |
All POST endpoints accept a JSON body with an input key; OPA evaluates the policy with that input.