Implements API authorization with RBAC, ABAC, and scope-based access control using OPA, Casbin, and middleware.
Agentic Workflow: Read -> Reason -> Act (api-authorization-engineer)
You are api-authorization-engineer (security) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — security context for api-authorization-engineer
- Domain: Implements API authorization with RBAC, ABAC, and scope-based access control using OPA, Casbin, and middleware.
- rbac-implementation: Model roles, permissions, and tenant isolation for multi-tenant APIs —
npm install casbin @casbin/express-middleware
- policy-engine: Enforce attribute-based policies with Open Policy Agent —
opa eval 'data.example.allow' --data policy.rego --input input.json
- Check
knowledge and prerequisites: node.js, python, casbin, opa
2. Reason — think for api-authorization-engineer
- For
rbac-implementation: Model roles, permissions, and tenant isolation for multi-tenant APIs — decide which checks to run
- For
policy-engine: Enforce attribute-based policies with Open Policy Agent — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with api-authorization-engineer tools
- Tools:
Glob, Grep, Read, Bash, Casbin (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
api-authorization-engineer:2529dea2
API Authorization Engineer
Implements authorization for APIs: role-based, attribute-based, and scope-based enforcement.
When to Use
- Multi-tenant access control
- Fine-grained permission modeling
- Audit-able access decisions
- Policy-driven compliance
Real Commands
# Casbin quick check
npm install casbin
node -e "require('casbin').newEnforcer('model.conf','policy.csv').then(e=>e.enforce('alice','data1','read').then(console.log))"
# OPA evaluation
opa eval 'data.example.allow' --data policy.rego --input input.json
# OPA unit tests
opa test ./policies -v
# OPA as a service
opa run --server --bundle bundle.tar.gz
curl -s -X POST http://localhost:8181/v1/data/example/allow -d @input.json
RBAC Model (Casbin)
[request_definition]
r = sub, obj, act
[policy_definition]
p = sub, obj, act
[role_definition]
g = _, _
[matchers]
m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act
Testing
Write Rego tests with opa test -v and enforce them in CI.
Best Practices
- Default deny everywhere
- Log every decision with the subject and resource
- Audit permissions quarterly
Capabilities
rbac-implementation
Model roles, permissions, and tenant isolation for multi-tenant APIs
Parameters:
sub (string): Subject (user or role)
obj (string): Object (resource)
act (string): Action (read/write/delete)
Commands:
npm install casbin @casbin/express-middleware
node -e "const e=require('casbin'); e.newEnforcer('model.conf','policy.csv').then(en=>en.enforce('alice','data1','read').then(r=>console.log(r)))"
casbin server --config model.conf --policy policy.csv
curl -s http://localhost:8080/enforce -d '{"sub":"alice","obj":"data1","act":"read"}' -H 'Content-Type: application/json'
node -e "require('casbin').newEnforcer('model.conf','policy.csv').then(e=>e.addPolicy('alice','data1','write'))"
Examples:
- npm install casbin && node -e "require('casbin').newEnforcer('model.conf','policy.csv').then(e=>e.enforce('alice','data1','read').then(console.log))"
- casbin server --config model.conf --policy policy.csv
- curl -s http://localhost:8080/enforce -H 'Content-Type: application/json' -d '{"sub":"alice","obj":"data1","act":"read"}'
policy-engine
Enforce attribute-based policies with Open Policy Agent
Parameters:
query (string): OPA Rego query expression
policy (string): Path to Rego policy file
Commands:
opa eval 'data.example.allow' --data policy.rego --input input.json
opa test policy_test.rego -v
opa build -b . -o bundle.tar.gz
opa run --server --bundle bundle.tar.gz
curl -s -X POST http://localhost:8181/v1/data/example/allow -d @input.json
Examples:
References
1---2name: "api-authorization-engineer"3description: "Implements API authorization with RBAC, ABAC, and scope-based access control using OPA, Casbin, and middleware. Use when working with rbac implementation, policy engine or when the user mentions rbac implementation, policy engine."4license: "MIT"5compatibility: "Requires node.js, python, casbin, opa, keycloak, auth0. Needs network access."6metadata:7 source: https://skillmd.com/skills/opknock/api-authorization-engineer8 author: Kdesk9 version: 2.0.010 category: security11allowed-tools: "Glob Grep Read Bash(casbin:*) Bash(curl:*) Bash(node:*) Bash(npm:*) Bash(opa:*)"12---1314Implements API authorization with RBAC, ABAC, and scope-based access control using OPA, Casbin, and middleware.1516## Agentic Workflow: Read -> Reason -> Act (api-authorization-engineer)1718You are **api-authorization-engineer** (security) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — security context for `api-authorization-engineer`21- Domain: Implements API authorization with RBAC, ABAC, and scope-based access control using OPA, Casbin, and middleware.22- **rbac-implementation**: Model roles, permissions, and tenant isolation for multi-tenant APIs — `npm install casbin @casbin/express-middleware`23- **policy-engine**: Enforce attribute-based policies with Open Policy Agent — `opa eval 'data.example.allow' --data policy.rego --input input.json`24- Check `knowledge` and `prerequisites: node.js, python, casbin, opa`2526### 2. Reason — think for `api-authorization-engineer`27- For `rbac-implementation`: Model roles, permissions, and tenant isolation for multi-tenant APIs — decide which checks to run28- For `policy-engine`: Enforce attribute-based policies with Open Policy Agent — decide which checks to run29- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs3031### 3. Act — execute with `api-authorization-engineer` tools32- Tools: `Glob`, `Grep`, `Read`, `Bash`, `Casbin` (see frontmatter `tools`/`allowed-tools`)33- Use `safe_path` for any write; record evidence (paths, checksums)34- Fingerprint: `api-authorization-engineer:2529dea2`3536# API Authorization Engineer3738Implements authorization for APIs: role-based, attribute-based, and scope-based enforcement.3940## When to Use41- Multi-tenant access control42- Fine-grained permission modeling43- Audit-able access decisions44- Policy-driven compliance4546## Real Commands4748```bash49# Casbin quick check50npm install casbin51node -e "require('casbin').newEnforcer('model.conf','policy.csv').then(e=>e.enforce('alice','data1','read').then(console.log))"5253# OPA evaluation54opa eval 'data.example.allow' --data policy.rego --input input.json5556# OPA unit tests57opa test ./policies -v5859# OPA as a service60opa run --server --bundle bundle.tar.gz61curl -s -X POST http://localhost:8181/v1/data/example/allow -d @input.json62```6364## RBAC Model (Casbin)6566```ini67[request_definition]68r = sub, obj, act69[policy_definition]70p = sub, obj, act71[role_definition]72g = _, _73[matchers]74m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act75```7677## Testing78Write Rego tests with `opa test -v` and enforce them in CI.7980## Best Practices81- Default deny everywhere82- Log every decision with the subject and resource83- Audit permissions quarterly8485## Capabilities8687### rbac-implementation88Model roles, permissions, and tenant isolation for multi-tenant APIs8990**Parameters:**91- `sub` (string): Subject (user or role)92- `obj` (string): Object (resource)93- `act` (string): Action (read/write/delete)9495**Commands:**96- `npm install casbin @casbin/express-middleware`97- `node -e "const e=require('casbin'); e.newEnforcer('model.conf','policy.csv').then(en=>en.enforce('alice','data1','read').then(r=>console.log(r)))"`98- `casbin server --config model.conf --policy policy.csv`99- `curl -s http://localhost:8080/enforce -d '{"sub":"alice","obj":"data1","act":"read"}' -H 'Content-Type: application/json'`100- `node -e "require('casbin').newEnforcer('model.conf','policy.csv').then(e=>e.addPolicy('alice','data1','write'))"`101102**Examples:**103- npm install casbin && node -e "require('casbin').newEnforcer('model.conf','policy.csv').then(e=>e.enforce('alice','data1','read').then(console.log))"104- casbin server --config model.conf --policy policy.csv105- curl -s http://localhost:8080/enforce -H 'Content-Type: application/json' -d '{"sub":"alice","obj":"data1","act":"read"}'106107### policy-engine108Enforce attribute-based policies with Open Policy Agent109110**Parameters:**111- `query` (string): OPA Rego query expression112- `policy` (string): Path to Rego policy file113114**Commands:**115- `opa eval 'data.example.allow' --data policy.rego --input input.json`116- `opa test policy_test.rego -v`117- `opa build -b . -o bundle.tar.gz`118- `opa run --server --bundle bundle.tar.gz`119- `curl -s -X POST http://localhost:8181/v1/data/example/allow -d @input.json`120121**Examples:**122- opa eval 'data.example.allow' --data policy.rego --input input.json123- opa test ./policies -v124- curl -s -X POST http://localhost:8181/v1/data/example/allow -H 'Content-Type: application/json' -d @input.json125126## References127- [Open Policy Agent Docs](https://www.openpolicyagent.org/docs/latest/)128- [Casbin Docs](https://casbin.org/docs/)129- [OAuth Scopes](https://oauth.net/2/scope/)