If you are looking for TLDR:<p>1. Define policies using declarative language Rego<p>2. Deploy OPA alongside your service as a sidecar in Kubernets<p>3. Make your service queries OPA when it needs to make policy decisions, passing the current state/context as input.<p>4. OPA evaluates the policies written in Rego against the input and returns a decision (allow or deny) back to your service.<p>Found it's hard to convince everyone around to use OPA/Rego and wrap into a managed service. The main objection - wrapping another DSL (domain-specific language) is hard.<p>However it was relatively simple to convince my team to use featured complete Go library Ladon <a href="https://github.com/ory/ladon">https://github.com/ory/ladon</a><p>Ladon is inspired by AWS IAM Policies.<p>{<p><pre><code> "description": "One policy to rule them all.",
"subjects": ["users:<peter|ken>", "users:maria", "groups:admins"],
"actions" : ["delete", "<create|update>"],
"effect": "allow",
"resources": [
"resources:articles:<.*>",
"resources:printer"
],
"conditions": {
"remoteIP": {
"type": "CIDRCondition",
"options": {
"cidr": "192.168.0.1/16"
}
}
}
</code></pre>
}<p>All policies are loaded on the app start, stored in memory (not DB) and checked with the help of small middleware which triggered the following function.<p>func (l *Ladon) DoPoliciesAllow(r *Request, policies []Policy) (err error)<p><a href="https://github.com/ory/ladon/blob/972387f17e29c529ad3ff42a8423117825409cd7/ladon.go#L74">https://github.com/ory/ladon/blob/972387f17e29c529ad3ff42a84...</a><p>Very negligible perfomance hit. Code is very simple, hackable, and can be subject for further optimisations.<p>Ladon is very fast. It's possible to run all user groups against all CRUD routes, and get the basic permission matrix or build some simple UI forms to test condition for better control.<p>P.s. Feel free to ping me in private @reactima (github, telegram) if you want to discuss the edge cases for the above.