Files
higress/plugins/wasm-go/extensions/opa/README.md
2024-09-12 21:48:40 +08:00

1.8 KiB
Raw Blame History

title, keywords, description
title keywords description
OPA
higress
opa
OPA 策略控制插件配置参考

功能说明

该插件实现了 OPA 策略控制

运行属性

插件执行阶段:认证阶段 插件执行优先级:225

配置字段

字段 数据类型 填写要求 默认值 描述
policy string 必填 - opa 策略
timeout string 必填 - 访问超时时间设置
serviceSource string 必填 - k8s,nacos,ip,route
host string 非必填 - 服务主机serviceSource为ip必填)
serviceName string 非必填 - 服务名称serviceSource为k8s,nacos,ip必填)
servicePort string 非必填 - 服务端口serviceSource为k8s,nacos,ip必填)
namespace string 非必填 - 服务端口serviceSource为k8s,nacos必填)

配置示例

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

OPA 服务安装参考

启动 OPA 服务

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

创建 OPA 策略

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"
}'

查询策略

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