Skip to content

Commit e64222c

Browse files
committed
feat: enable customization of OPA policy file path
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
1 parent 00cd520 commit e64222c

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

plugins/external/opa/README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,31 @@ The OPA plugin is composed of two components:
1111

1212
### OPA Server
1313
To define a policy file you need to go into opaserver/rego and create a sample policy file for you.
14-
Example -`example.rego` is present.
14+
Example -`policy.rego` is present.
1515
Once you have this file created in this location, when building the server, the opa binaries will be downloaded and a container will be build.
1616
In the `run_server.sh` file, the opa server will run as a background service in the container with the rego policy file.
1717

1818
### OPA Plugin
19-
The OPA plugin runs as an external plugin with pre/post tool invocations. So everytime, a tool invocation is made, and if OPAPluginFilter has been defined in config.yaml file, the tool invocation will pass through this OPA Plugin.
19+
The OPA plugin runs as an external plugin with pre/post tool invocations. So everytime a tool invocation is made, and if OPAPluginFilter has been defined in config.yaml file, the tool invocation will pass through this OPA Plugin.
2020

21+
## Configuration
22+
23+
### MCP Server Container
24+
25+
The following enviornment variables can be used to customize the server container deployment.
26+
27+
- `API_SERVER_SCRIPT`: Path to the server script (optional, auto-detected)
28+
- `PLUGINS_CONFIG_PATH`: Path to the plugin config (optional, default: ./resources/plugins/config.yaml)
29+
- `CHUK_MCP_CONFIG_PATH`: Path to the chuck-mcp-runtime config (optional, default: ./resources/runtime/config.yaml)
30+
- `POLICY_PATH`: Path to the repo policy file (optional, default: ./opaserver/rego/policy.rego)
31+
32+
### MCP Runtime
33+
34+
Changes to the MCP runtime configurations can be made in `resources/runtime/config.yaml`.
35+
36+
### OPA Plugin Configuration
37+
38+
The OPA plugin and loader configuration can be customized in `resources/plugins/config.yaml`.
2139

2240
## Installation
2341

@@ -64,7 +82,7 @@ Under `extensions`, you can specify which policy to run and what endpoint to cal
6482
In the `config` key in `config.yaml` for the OPA plugin, the following attribute must be set to configure the OPA server endpoint:
6583
`opa_base_url` : It is the base url on which opa server is running.
6684

67-
3. Now suppose you have a sample policy in `example.rego` file that allows a tool invocation only when "IBM" key word is present in the repo_path. Add the sample policy file or policy rego file that you defined, in `plugins/external/opa/opaserver/rego`.
85+
3. Now suppose you have a sample policy in `policy.rego` file that allows a tool invocation only when "IBM" key word is present in the repo_path. Add the sample policy file or policy rego file that you defined, in `plugins/external/opa/opaserver/rego`.
6886

6987
3. Once you have your plugin defined in `config.yaml` and policy added in the rego file, run the following commands to build your OPA Plugin external MCP server using:
7088
* `make build`: This will build a docker image named `opapluginfilter`
File renamed without changes.

plugins/external/opa/run-server.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# API_SERVER_SCRIPT : Path to the server script (optional, auto-detected)
1212
# PLUGINS_CONFIG_PATH : Path to the plugin config (optional, default: ./resources/plugins/config.yaml)
1313
# CHUK_MCP_CONFIG_PATH : Path to the chuck-mcp-runtime config (optional, default: ./resources/runtime/config.yaml)
14+
# POLICY_PATH : Path to the repo policy file (optional, default: ./opaserver/rego/policy.rego)
1415
#
1516
# Usage:
1617
# ./run-server.sh # Run server
@@ -36,7 +37,7 @@ fi
3637
#────────────────────────────────────────────────────────────────────────────────
3738

3839
echo "Running OPA server"
39-
opa run --server opaserver/rego/example.rego &
40+
opa run --server ${POLICY_PATH:-opaserver/rego/policy.rego &
4041
4142
#────────────────────────────────────────────────────────────────────────────────
4243
# SECTION 2: Run the API server

0 commit comments

Comments
 (0)