Contributing to Meshery Policies

Background

Meshery has a built-in policy engine, based on Open Policy Agent (OPA). Meshery uses the Rego query language to create these policies.

Prerequisites

To start contributing to Meshery Policy Engine, make sure you have OPA CLI installed on your system. You will also need to clone the Meshery Server project from Github.

Components of Meshery Policy Engine

Rego policies are the declarative logic behind the policy engine. These policies define how the underlying engine understands relationships within Meshery Designs. Rego policies can be found here in the Meshery Github repository.

Currently the Rego policies are invoked from the Go code in Meshery Server. This requires configuring the OPA context as seen here.

The Meshery Policy Engine is invoked by calling the evaluation endpoint. This endpoint is passed a Meshery Design in JSON which it passes to the Meshery Policy Engine for validation.

Working with Meshery Policy Engine

Working with the Meshery Policy Engine can feel complex because of the large number of different relationships a Meshery Design might contain. Contributors must then be careful to test any changes thoroughly to avoid unexpected results. When working with the Rego policies themselves it makes testing and development easier to be able to test the policies directly without running the entire Meshery Server. When working on the policies keep the following in mind:

  • Since we will be running these policies using the OPA CLI directly without the Go bootstrap code we need to provide the necessary context for the policy engine. This means providing a data structure containing the valid Meshery Relationships the policy engine will evaluate against.
  • The input to the policy engine is a Meshery Design as a JSON data structure. When testing the Meshery Policy Engine you will need to provide this design as input. If you are working on a bug you will need to get the design from the issue or directly from the individual who reported the bug.

Executing OPA

You can evaluate the Rego policies against test data stored in the policies/test folder:

make rego-eval

Suggested Reading