Open Data Mesh Platform is a platform that manages the full lifecycle of a data product from deployment to retirement. It uses the Data Product Descriptor Specification to create, deploy and operate data product containers in a mesh architecture.
This repository contains an Adapter for OPA (i.e., Open Policy Agent) of the Policy Engine API service on the ODM Utility Plane.
The policy evaluation process is composed of these steps:
-
Registration of a New Policy on the OPA Server:
- The package name is extracted from the policy code, it is mandatory and must be unique.
- The URL to store the policy is composed based on this package name.
- For example, if the policy has
package org.opendatamesh
, a new policy is created with:PUT <...>/v1/policies/org/opendatamesh
-
Policy Validation:
- The policy is validated using the evaluation request content.
- The input object passed for validation has this structure:
{ "input": { // The policy event content (varies based on the event, but always includes currentState/afterState) } }
- An example of a validation call can be:
POST <...>/v1/data/org/opendatamesh
- The supported structure of the validation output is:
where the
{ "decision_id":"403573d5-4130-4303-bd9f-2686dcb1ab5e", "result": { "allow":false, "otherAttribute": "another attribute of the response" } }
allow
attribute represents the evaluation result of the policy.
-
Result Collection and Policy Removal: The result is collected, and the policy is then removed from the OPA server.
Here is a policy example that satisfies this requirement:
package org.opendatamesh
default allow := false
default warning := false
allow := true {
startswith(input.afterState.dataProductVersion.info.fullyQualifiedName, "urn")
}
The project requires the following dependencies:
- Java 11
- Maven 3.8.6
- OPA Rootless
Compile the project:
mvn clean install -DskipTests
Clone the repository and move to the project root folder
git git clone https://github.com/opendatamesh-initiative/odm-platform-adapter-validator-opa.git
cd odm-platform-adapter-validator-opa
Compile the project:
mvn clean package spring-boot:repackage -DskipTests
Run the application:
java -jar opa-policy-server/target/odm-platform-adapter-validator-opa-1.0.1.jar
Note: The application need a reachable OPA server listening on port 8181 to correctly work. See the section "Run OPA server" on how to run an OPA server with Docker.
To stop the application type CTRL+C or just close the shell. To start it again re-execute the following command:
java -jar opa-policy-server/target/odm-platform-adapter-validator-opa-1.0.1.jar
*Dependencies must have been compiled to run this project.
Clone the repository and move it to the project root folder
git git clone https://github.com/opendatamesh-initiative/odm-platform-adapter-validator-opa.git
cd odm-platform-adapter-validator-opa
Here you can find the Dockerfile which creates an image containing the application by directly copying it from the build
executed locally (i.e. from target
folder).
You need to first execute the build locally by running the following command:
mvn clean package spring-boot:repackage -DskipTests
The image generated from Dockerfile contains only the application. It requires an OPA server to run properly. If you do not already have an OPA server available, you can create one by running the following commands:
docker run --name odm-opa-server -d -p 8181:8181 \
openpolicyagent/opa:latest-rootless \
run \
--server \
--log-level=debug \
--log-format=json-pretty \
--set=decision_logs.console=true
Check that the OPA server has started correctly:
docker logs odm-opa-server
Build the Docker image of the application and run it.
docker build -t odm-platform-up-validator-opa-server-app . -f Dockerfile
Run the Docker image.
Note: Before executing the following commands remove the argument --net host
if OPA server is not running
on localhost
docker run --name odm-platform-up-validator-opa-server-app -p 9009:9009 --net host odm-platform-up-validator-opa-server-app
docker stop odm-platform-up-validator-opa-server-app
docker stop odm-opa-server
To restart a stopped application execute the following commands:
docker start odm-opa-server
docker start odm-platform-up-validator-opa-server-app
To remove a stopped application to rebuild it from scratch execute the following commands :
docker rm odm-platform-up-validator-opa-server-app
docker rm odm-opa-server
Create a .env
file in the root directory of the project similar to the following one:
OPA_PORT=8181
SPRING_PORT=9009
OPA_HOSTNAME="opa"
Run the docker-compose images.
docker-compose up
Stop the docker-compose images
docker-compose down
To restart a stopped application execute the following commands:
docker-compose up
You can invoke REST endpoints through OpenAPI UI available at the following url:
You can access to OPA Server browsing tho the following page: