Skip to content
铭师堂的云原生升级实践Know more

OPA

Function Description

This plugin implements OPA policy control.

Running Attributes

Plugin Execution Phase: Authentication Phase
Plugin Execution Priority: 225

Configuration Fields

FieldData TypeRequiredDefault ValueDescription
policystringRequired-OPA Policy
timeoutstringRequired-Timeout setting for access
serviceSourcestringRequired-k8s, nacos, ip, route
hoststringOptional-Service host (required if serviceSource is ip)
serviceNamestringOptional-Service name (required if serviceSource is k8s,nacos,ip)
servicePortstringOptional-Service port (required if serviceSource is k8s,nacos,ip)
namespacestringOptional-Namespace (required if serviceSource is k8s,nacos)

Configuration Example

serviceSource: k8s
serviceName: opa
servicePort: 8181
namespace: higress-backend
policy: example1
timeout: 5s

OPA Service Installation Reference

Start OPA Service

Terminal window
docker run -d --name opa -p 8181:8181 openpolicyagent/opa:0.35.0 run -s

Create OPA Policy

Terminal window
curl -X PUT '127.0.0.1:8181/v1/policies/example1' \
-H 'Content-Type: text/plain' \
-d 'package example1
import input.request
default allow = false
allow {
# HTTP method must GET
request.method == "GET"
}'

Query Policy

Terminal window
curl -X POST '127.0.0.1:8181/v1/data/example1/allow' \
-H 'Content-Type: application/json' \
-d '{"input":{"request":{"method":"GET"}}}'