Open dvcorreia opened 1 month ago
I tried to run a demo with OPA and GoGatekeeper, but could not get it to run. The demo docker compose is very out of date. I tried to get it fixed in https://github.com/dvcorreia/demo-docker-compose but then NGLASS-50 was paused and deprecated.
Context
As part of addressing NGLASS-50, we initially explored using Open Policy Agent (OPA) to determine if users had the appropriate permissions when making requests to a specific DicomWeb store. Our setup involved using GoGatekeeper as an OIDC proxy, which natively supports OPA for authorization (documentation here). Given this integration, we found it worth to test OPA for our authorization needs.
This issue provides a summary of the work conducted during the evaluation of OPA. Some exploration code can be seen in https://github.com/MetaCell/mnp/tree/feature/NGLASS-50.
Open Policy Engine
It is a general-purpose policy engine. In it simplest form, we can think of it as a service that takes json as input, executes a policy written in Rego, and outputs the policy evaluation in json, that is, if is allowed of not.
How did it look like for our use case
Our use case was evaluating access to DicomWeb stores. So, from GoGatekeeper example in their documentation, it would send us the following input:
How can we write a policy to work on this input? Here is the example we worked on:
We also wrote some test to validate this policy. They can be run with
opa test
. Here are a few tests for you to see how they look like:Use Cases
Being a general-purpose policy engine, it has been integrated in many things. A few I think that are interesting:
Application Authorization
You can decouple authorization from business logic, so if the policy changes we do not have to make changes to the code. It is much more flexible in that we can deploy the same product with different rules, e.g for a clinic A, employees can access all the medic records, but for clinic B that is only possible if the employee works the night shift from 22pm to 5am, for privacy and emergency reasons.
An example can be seen in https://www.openpolicyagent.org/ in the Application tab.
API Gateway Authorization
Envoy supports it out of the box and is really simple to iterate on it. Here is an example:
Kubernetes Policy Management
Similar to Kyverno, OPA has its own solution for this, called Gatekeeper. The interesting thing is the community library that allows you to easily define polices. Here is an example: ensure that all namespaces have a label describing which product their are part of.
After installing Gatekeeper and the CRD definitions for the library, if you apply the following CRD policy "definition" in the cluster:
Creating the following namespace will be allowed:
But this one will not be:
There are many more things that is possible to do with OPA, but this what the usecases I'm experienced with.