The API call fails, but nothing is wrong with the code. The access token is valid. The service is running. The problem is policy.
Open Policy Agent (OPA) with Role-Based Access Control (RBAC) solves this exact problem at scale. OPA is a lightweight, CNCF-graduated policy engine that can run anywhere. RBAC is a proven model for controlling who can do what across a system. Together, they give you fine-grained authorization that is easy to reason about and enforce consistently.
With OPA, you define your RBAC rules in Rego, a declarative language built for policy. Instead of scattering access logic across services, you centralize it in one place. This lets you test, version, and roll back rules like code. An RBAC policy in OPA typically checks roles, permissions, and resource attributes. The decision engine evaluates these inputs and returns allow or deny, independent of your application’s business logic.
A minimal RBAC policy in OPA might look like this: