Envoy v3 external authorization server SDK for MoonBit
moon add python123-ops/envoy_ext_authz@0.1.0-rc.1supported_targets = "native"
import {
"python123-ops/envoy_ext_authz" @authz,
"python123-ops/envoy_ext_authz/transport",
}async fn run_gateway_policy(
authenticate : (String) -> String?,
permitted : (String, String, String) -> Bool,
) -> Unit {
let service = @authz.Service::new(
req => {
guard req.headers.get("authorization") is Some(credential) else { return Deny(401) }
guard authenticate(credential) is Some(user) else { return Deny(401) }
guard permitted(user, req.http_method, req.path) else { return Deny(403) }
Allow([("x-authenticated-user", user)])
},
allowed_headers=["authorization"],
identity_headers=["x-authenticated-user"],
)
@transport.serve(service, host="127.0.0.1", port=19001)
}moon update
moon test --target native
moon build --target native --release examples/server
python3 verification/run.py| 策略结果 | 网关行为 |
|---|---|
| Allow(headers) | 将本次给出的身份头覆盖写入上游。对声明过但本次未给出的身份头,要求 Envoy 删除客户端值。 |
| Deny(401)、Deny(403) | 将鉴权拒绝返回客户端,上游收不到请求。 |
| Unavailable、无效策略输出、服务超时或停机 | 走 gRPC 或网关错误路径。随附配置在这些情况下拒绝转发并返回 503。 |
python3 verification/run.py --samples 2000 --concurrency 8 --output verification/linux-results.jsonpub(all) suberror CheckError {
InvalidRequest
InvalidDecision
PolicyUnavailable
RequestTooLarge
} derive(Debug)pub struct Service {
// private fields
}