SuperAPI AI 工具集

custom-builtin-functions

安全与审计

查看项目

更新于 10-15 17:33

技能介绍

用途:为 Chainloop 使用的 OPA/Rego 策略引擎添加用 Go 编写的自定义内置函数(built-in)。

主要能力:通过 Register 接口定义函数名、描述、参数与返回类型,并实现具体逻辑;函数可在 Rego 策略中通过 chainloop.* 命名空间调用。

使用方式:在 pkg/policies/engine/rego/builtins/ 下新建文件,定义 const 函数名(如 chainloop.my_function),编写 Register 与实现函数,在 init() 中自动注册;然后在 .rego 策略中 import rego.v1 后调用,例如 output := chainloop.my_function(input.value) 并据此产生 violations。

限制与约定:所有自定义内置函数必须使用 chainloop.* 命名空间;调用第三方服务的函数需添加 NonRestrictiveBuiltin 类别标记为非限制性;需妥善处理错误并返回有意义信息;应利用 BuiltinContext 支持超时与取消;需在 Description 与参数定义中说明签名与行为。