Skip to content

OPA v1 Rules Migration Guide

This guide explains how to migrate your custom OSDU policies (Rego rules) to ensure compatibility with OPA v1.

OPA v1 introduced several significant Rego changes which require syntax updates for some existing rules. While you can update these rules manually, we highly recommend using the automatic upgrade tool provided by OPA.

Automatic Rule Upgrade

OPA includes a tool designed to upgrade Rego files automatically. Detailed instructions on its usage can be found here.

In most cases, one of the commands below should be sufficient for your needs.

Option 1: Using a Local OPA Installation

If you can install OPA directly on your computer, use the following command. It will convert the rules in your specified policy file to the v1 format and overwrite the original file.

opa fmt --write --v0-v1 <PATH_TO_YOUR_POLICY>

Option 2: Using Docker

If you cannot or prefer not to install OPA locally, you can achieve the same result using its Docker container. Ensure you use the absolute path to your policy file.

docker run -it -v <ABSOLUTE_PATH_TO_POLICY>:/policy.rego --rm openpolicyagent/opa:1.3.0 fmt --write --v0-v1 /policy.rego

This command will run OPA as a docker container, mount your policy to be visible inside the container and convert it to v1. Command is designed to convert v0 rules to v1, so it will fail on rules already in v1 if they don't have v1 imports and use new v1 syntax features.