Skip to main content

Enterprise OPA is a drop-in replacement for OPA that provides out-of-the-box integrations for popular data sources and decision log sinks. This tutorial shows how to embed Enterprise OPA into a simple Go application that uses OPA's SDK package.

Add the Go module dependency

Extract the Enterprise OPA tarball into your source directory.

mkdir -p eopa
tar xzvf /path/to/eopa.tar.gz –strip-component=1 -C eopa

Add the following lines to your go.mod file.

require v1.8.0
replace => ./eopa

Import the Enterprise OPA SDK package

Import Enterprise OPA into the application with the following import and then override the options that your application provides when instantiating the SDK.

import eopa_sdk ""
+       opts := eopa_sdk.DefaultOptions()
+ opts.ID = "eopa-test-1"
+ opts.Config = bytes.NewReader(config)
// create an instance of the OPA object
- opa, err := sdk.New(ctx, sdk.Options{
- ID: "opa-test-1",
- Config: bytes.NewReader(config),
- })
+ opa, err := sdk.New(ctx, opts)

The DefaultOptions enables the Enteprise OPA VM target globally as a side-effect.

Since Enterprise OPA's data source and decision log sink features are implemented as standard OPA plugins, there is no additional implementation required. To enable specific sources and sinks edit the configuration passed to the SDK. See the Configuration documentation for details.

Wrap up

This tutorial showed how you can embed Enterprise OPA into a Go application that uses the SDK package. The sample code is hosted on GitHub. For additional examples see the examples/sdk directory from the tarball.