mirror of
https://github.com/alibaba/higress.git
synced 2026-06-09 12:47:28 +08:00
doc: add missed chinese readme for extensions (#3890)
Signed-off-by: zhoujinyu <2319109590@qq.com>
This commit is contained in:
36
plugins/wasm-go/extensions/hello-world/README.md
Normal file
36
plugins/wasm-go/extensions/hello-world/README.md
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# 功能说明
|
||||||
|
|
||||||
|
`hello-world` 是 Higress Wasm Go 插件的最小示例,用于演示插件开发、本地构建与挂载流程。插件在请求头阶段为请求添加 `hello: world` 头,并直接返回 `200` 及响应体 `hello world`。
|
||||||
|
|
||||||
|
本插件**无配置项**,仅适合学习与调试,请勿用于生产环境。
|
||||||
|
|
||||||
|
# 构建
|
||||||
|
|
||||||
|
在 `plugins/wasm-go` 目录下执行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
PLUGIN_NAME=hello-world make build
|
||||||
|
```
|
||||||
|
|
||||||
|
# 配置示例
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# 无额外配置字段
|
||||||
|
```
|
||||||
|
|
||||||
|
# 引用插件
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
apiVersion: extensions.higress.io/v1alpha1
|
||||||
|
kind: WasmPlugin
|
||||||
|
metadata:
|
||||||
|
name: hello-world
|
||||||
|
namespace: higress-system
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
higress: higress-system-higress-gateway
|
||||||
|
url: oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/hello-world:<version>
|
||||||
|
```
|
||||||
|
|
||||||
|
更多开发说明见 [wasm-go 插件开发文档](../../README.md)。
|
||||||
48
plugins/wasm-go/extensions/http-call/README.md
Normal file
48
plugins/wasm-go/extensions/http-call/README.md
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
# 功能说明
|
||||||
|
|
||||||
|
`http-call` 插件在请求头阶段异步调用外部 HTTP 服务,将其响应体及指定响应头写入当前请求头,再继续转发。适用于转发前向认证、元数据等辅助服务拉取信息的场景。
|
||||||
|
|
||||||
|
# 配置字段
|
||||||
|
|
||||||
|
| 名称 | 数据类型 | 填写要求 | 默认值 | 描述 |
|
||||||
|
| -------- | -------- | -------- | -------- | -------- |
|
||||||
|
| bodyHeader | string | 必填 | - | 将外部服务响应体写入的请求头名称 |
|
||||||
|
| tokenHeader | string | 必填 | - | 从外部服务响应头读取并写入请求头的名称 |
|
||||||
|
| requestPath | string | 必填 | - | 调用外部服务时的请求路径 |
|
||||||
|
| serviceSource | string | 必填 | - | 服务发现类型:`k8s`、`nacos`、`ip`、`dns` |
|
||||||
|
| serviceName | string | 必填 | - | 服务名称 |
|
||||||
|
| servicePort | number | 必填 | - | 服务端口 |
|
||||||
|
| namespace | string | 选填 | - | `k8s` / `nacos` 时的命名空间 |
|
||||||
|
| domain | string | 选填 | - | `dns` 类型时的域名 |
|
||||||
|
|
||||||
|
# 配置示例
|
||||||
|
|
||||||
|
## 调用 K8s 服务
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
bodyHeader: x-auth-body
|
||||||
|
tokenHeader: x-auth-token
|
||||||
|
requestPath: /validate
|
||||||
|
serviceSource: k8s
|
||||||
|
serviceName: auth-service
|
||||||
|
servicePort: 8080
|
||||||
|
namespace: default
|
||||||
|
```
|
||||||
|
|
||||||
|
## 调用 DNS 服务
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
bodyHeader: x-auth-body
|
||||||
|
tokenHeader: authorization
|
||||||
|
requestPath: /api/token
|
||||||
|
serviceSource: dns
|
||||||
|
serviceName: auth.dns
|
||||||
|
servicePort: 443
|
||||||
|
domain: auth.example.com
|
||||||
|
```
|
||||||
|
|
||||||
|
# 说明
|
||||||
|
|
||||||
|
- 外部服务返回非 `200` 时,插件记录错误日志,请求仍会继续转发(不会自动拒绝)。
|
||||||
|
- 响应体中的换行符会被替换为 `#`,避免协议错误。
|
||||||
|
- 插件在异步回调完成前会暂停请求头处理(`HeaderStopAllIterationAndWatermark`)。
|
||||||
50
plugins/wasm-go/extensions/jsonrpc-converter/README.md
Normal file
50
plugins/wasm-go/extensions/jsonrpc-converter/README.md
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
# 功能说明
|
||||||
|
|
||||||
|
`jsonrpc-converter` 是 MCP(Model Context Protocol)相关过滤器,将 JSON-RPC / MCP 请求与响应中的关键字段提取到 Envoy 可路由、可观测的 HTTP 头中,便于在网关侧做日志、路由或策略匹配。
|
||||||
|
|
||||||
|
支持的方法默认包括 `tools/list`、`tools/call`,可通过 `allowed_methods` 扩展。
|
||||||
|
|
||||||
|
# 配置字段
|
||||||
|
|
||||||
|
| 名称 | 数据类型 | 填写要求 | 默认值 | 描述 |
|
||||||
|
| -------- | -------- | -------- | -------- | -------- |
|
||||||
|
| stage | string | 必填 | - | 处理阶段:`request`(请求前写入头)或 `response`(响应前写入头) |
|
||||||
|
| max_header_length | number | 选填 | 4000 | 写入头的字符串最大长度,超出则截断 |
|
||||||
|
| allowed_methods | array of string | 选填 | `tools/list`, `tools/call` | 允许处理的 JSON-RPC 方法列表 |
|
||||||
|
|
||||||
|
# 写入的请求头(stage=request)
|
||||||
|
|
||||||
|
| 请求头 | 说明 |
|
||||||
|
| -------- | -------- |
|
||||||
|
| x-envoy-jsonrpc-id | JSON-RPC id |
|
||||||
|
| x-envoy-jsonrpc-method | 方法名 |
|
||||||
|
| x-envoy-jsonrpc-params | 参数(`tools/call` 除外,见下) |
|
||||||
|
| x-envoy-mcp-tool-name | `tools/call` 的工具名 |
|
||||||
|
| x-envoy-mcp-tool-arguments | `tools/call` 的工具参数 |
|
||||||
|
|
||||||
|
# 写入的响应头(stage=response)
|
||||||
|
|
||||||
|
| 响应头 | 说明 |
|
||||||
|
| -------- | -------- |
|
||||||
|
| x-envoy-jsonrpc-id | JSON-RPC id |
|
||||||
|
| x-envoy-jsonrpc-method | 方法名 |
|
||||||
|
| x-envoy-jsonrpc-result | 结果(部分方法由专用逻辑写入) |
|
||||||
|
| x-envoy-jsonrpc-error | 错误信息 |
|
||||||
|
| x-envoy-mcp-tool-response | `tools/call` 的响应内容 |
|
||||||
|
| x-envoy-mcp-tool-error | `tools/call` 是否出错 |
|
||||||
|
|
||||||
|
# 配置示例
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
stage: request
|
||||||
|
max_header_length: 4000
|
||||||
|
allowed_methods:
|
||||||
|
- tools/list
|
||||||
|
- tools/call
|
||||||
|
```
|
||||||
|
|
||||||
|
# 说明
|
||||||
|
|
||||||
|
- 通常在同一路由上配置两个 WasmPlugin 实例,分别设置 `stage: request` 与 `stage: response`,以在请求链路与响应链路上分别注入头信息。
|
||||||
|
- 与 `stage` 相对的另一侧会自动清理已写入的头,避免头信息残留。
|
||||||
|
- 需配合 Higress MCP 过滤器链使用,详见 [MCP Server 开发指南](../../mcp-servers/README.md)。
|
||||||
84
plugins/wasm-go/extensions/jwt-auth/README.md
Normal file
84
plugins/wasm-go/extensions/jwt-auth/README.md
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
# 功能说明
|
||||||
|
|
||||||
|
`jwt-auth` 插件基于 JWT 对请求进行认证鉴权,支持内联 JWKS 或远程 JWKS 拉取,可从请求头、URL 参数或 Cookie 中提取 Token,校验通过后可把 Payload 中的 Claim 写入请求头转发给后端。
|
||||||
|
|
||||||
|
更完整的说明见官方文档:[JWT 认证插件](https://higress.io/zh-cn/docs/plugins/jwt-auth)。
|
||||||
|
|
||||||
|
# 运行属性
|
||||||
|
|
||||||
|
插件执行阶段:认证阶段
|
||||||
|
|
||||||
|
# 配置字段
|
||||||
|
|
||||||
|
## 全局配置
|
||||||
|
|
||||||
|
| 名称 | 数据类型 | 填写要求 | 默认值 | 描述 |
|
||||||
|
| -------- | -------- | -------- | -------- | -------- |
|
||||||
|
| consumers | array of object | 必填 | - | 调用方(Consumer)列表,至少配置一项 |
|
||||||
|
| global_auth | bool | 选填 | - | `true` 全局生效;`false` 仅对配置了 `_rules_` 的域名/路由生效;未配置时无规则则全局生效 |
|
||||||
|
|
||||||
|
### consumers 项
|
||||||
|
|
||||||
|
| 名称 | 数据类型 | 填写要求 | 默认值 | 描述 |
|
||||||
|
| -------- | -------- | -------- | -------- | -------- |
|
||||||
|
| name | string | 必填 | - | Consumer 名称 |
|
||||||
|
| issuer | string | 必填 | - | JWT 签发者,需与 payload 中 `iss` 一致 |
|
||||||
|
| jwks | string | 与 remote_jwks 二选一 | - | 内联 JWKS JSON 字符串 |
|
||||||
|
| remote_jwks | object | 与 jwks 二选一 | - | 远程 JWKS 端点(需 Higress 可发现的服务) |
|
||||||
|
| jwks_cache_duration | number | 选填 | 600 | 远程 JWKS 缓存时间(秒) |
|
||||||
|
| jwks_fetch_timeout | number | 选填 | 1500 | 远程 JWKS 拉取超时(毫秒) |
|
||||||
|
| claims_to_headers | array of object | 选填 | - | 将 Claim 写入请求头 |
|
||||||
|
| from_headers | array of object | 选填 | Authorization: Bearer | 从请求头提取 JWT |
|
||||||
|
| from_params | array of string | 选填 | access_token | 从 URL 参数提取 JWT |
|
||||||
|
| from_cookies | array of string | 选填 | - | 从 Cookie 提取 JWT |
|
||||||
|
| clock_skew_seconds | number | 选填 | 60 | 校验 `exp`/`iat` 的时钟偏移(秒) |
|
||||||
|
| keep_token | bool | 选填 | true | 转发时是否保留原 JWT |
|
||||||
|
|
||||||
|
### remote_jwks
|
||||||
|
|
||||||
|
| 名称 | 数据类型 | 填写要求 | 描述 |
|
||||||
|
| -------- | -------- | -------- | -------- |
|
||||||
|
| service_name | string | 必填 | Higress 服务名(如 `issuer.example.com.dns`) |
|
||||||
|
| service_host | string | 选填 | JWKS 请求的 Host |
|
||||||
|
| service_port | number | 选填 | 端口,默认 443 |
|
||||||
|
| path | string | 必填 | JWKS 路径,如 `/.well-known/jwks.json` |
|
||||||
|
|
||||||
|
### claims_to_headers 项
|
||||||
|
|
||||||
|
| 名称 | 数据类型 | 描述 |
|
||||||
|
| -------- | -------- | -------- |
|
||||||
|
| claim | string | JWT payload 中的字段名 |
|
||||||
|
| header | string | 写入的请求头名 |
|
||||||
|
| override | bool | 是否覆盖同名请求头,默认 true |
|
||||||
|
|
||||||
|
## 路由/域名级配置(_rules_)
|
||||||
|
|
||||||
|
| 名称 | 数据类型 | 填写要求 | 描述 |
|
||||||
|
| -------- | -------- | -------- | -------- |
|
||||||
|
| allow | array of string | 必填 | 允许访问的 consumer 名称列表 |
|
||||||
|
|
||||||
|
# 配置示例
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
consumers:
|
||||||
|
- name: example-consumer
|
||||||
|
issuer: https://issuer.example.com
|
||||||
|
remote_jwks:
|
||||||
|
service_name: issuer.example.com.dns
|
||||||
|
service_host: issuer.example.com
|
||||||
|
service_port: 443
|
||||||
|
path: /.well-known/jwks.json
|
||||||
|
jwks_cache_duration: 600
|
||||||
|
jwks_fetch_timeout: 1500
|
||||||
|
- name: inline-consumer
|
||||||
|
issuer: https://issuer.example.com
|
||||||
|
jwks: '{"keys":[...]}'
|
||||||
|
```
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
_rules_:
|
||||||
|
- _match_route_:
|
||||||
|
- route-a
|
||||||
|
allow:
|
||||||
|
- example-consumer
|
||||||
|
```
|
||||||
42
plugins/wasm-go/extensions/mcp-server/README.md
Normal file
42
plugins/wasm-go/extensions/mcp-server/README.md
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# 功能说明
|
||||||
|
|
||||||
|
`mcp-server` 是内置 MCP Server 示例插件,在网关侧托管多个 MCP 工具服务。当前版本内置:
|
||||||
|
|
||||||
|
- **quark-search**:夸克搜索相关工具
|
||||||
|
- **amap-tools**:高德地图相关工具
|
||||||
|
|
||||||
|
客户端可通过 MCP 协议(如 `tools/list`、`tools/call`)经 Higress 统一入口调用上述工具,并复用网关的认证、限流与可观测能力。
|
||||||
|
|
||||||
|
> 使用 MCP Server 类插件需要 **Higress 2.1.0** 及以上版本。
|
||||||
|
|
||||||
|
# 配置说明
|
||||||
|
|
||||||
|
本插件通过编译期注册 MCP Server,**WasmPlugin 的 `defaultConfig` 通常无需额外字段**。具体工具列表、参数与鉴权由各子 Server 实现决定,开发新 MCP Server 请参考 [MCP Server 实现指南](../../mcp-servers/README.md)。
|
||||||
|
|
||||||
|
# 配置示例
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# 多数场景下使用空配置或仅配置路由匹配即可
|
||||||
|
{}
|
||||||
|
```
|
||||||
|
|
||||||
|
# 引用插件
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
apiVersion: extensions.higress.io/v1alpha1
|
||||||
|
kind: WasmPlugin
|
||||||
|
metadata:
|
||||||
|
name: mcp-server
|
||||||
|
namespace: higress-system
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
higress: higress-system-higress-gateway
|
||||||
|
url: oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/mcp-server:<version>
|
||||||
|
```
|
||||||
|
|
||||||
|
# 相关文档
|
||||||
|
|
||||||
|
- [MCP 快速开始](https://higress.cn/ai/mcp-quick-start/)
|
||||||
|
- [MCP Server 开发指南](../../mcp-servers/README.md)
|
||||||
|
- [Wasm 插件市场](https://higress.cn/plugin/)
|
||||||
32
plugins/wasm-go/extensions/sni-misdirect/README.md
Normal file
32
plugins/wasm-go/extensions/sni-misdirect/README.md
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# 功能说明
|
||||||
|
|
||||||
|
`sni-misdirect` 用于缓解 HTTPS 场景下 **TLS SNI** 与 HTTP **`:authority`(Host)** 不一致带来的错误路由或错误证书问题。当两者不匹配且不符合通配 SNI 规则时,网关返回 **421 Misdirected Request**。
|
||||||
|
|
||||||
|
# 匹配规则
|
||||||
|
|
||||||
|
插件在以下条件**全部满足**时进行校验:
|
||||||
|
|
||||||
|
- 协议为 HTTP/2 或 HTTP/3(跳过 HTTP/1.x)
|
||||||
|
- 请求为 HTTPS
|
||||||
|
- `Content-Type` 不是 `application/grpc`(gRPC 跳过)
|
||||||
|
|
||||||
|
校验逻辑:
|
||||||
|
|
||||||
|
1. 若 SNI 与 `:authority`(去掉端口后)**完全相同** → 放行
|
||||||
|
2. 若 SNI **不以** `*.` 开头且与 Host 不一致 → 返回 421
|
||||||
|
3. 若 SNI 为 `*.example.com` 形式,则 Host 须包含 `example.com` 后缀,否则返回 421
|
||||||
|
|
||||||
|
# 配置字段
|
||||||
|
|
||||||
|
本插件**无配置项**。
|
||||||
|
|
||||||
|
# 配置示例
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# 无额外配置字段
|
||||||
|
```
|
||||||
|
|
||||||
|
# 说明
|
||||||
|
|
||||||
|
- 适用于多证书、多租户或通配证书场景,避免客户端 SNI 与 HTTP Host 不一致时误打到错误虚拟主机。
|
||||||
|
- 仅作请求头/连接属性检查,不修改上游路由目标。
|
||||||
33
plugins/wasm-go/extensions/streaming-body-example/README.md
Normal file
33
plugins/wasm-go/extensions/streaming-body-example/README.md
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# 功能说明
|
||||||
|
|
||||||
|
`streaming-body-example` 演示 Higress Wasm Go SDK 的**流式请求体/响应体**处理能力,包括:
|
||||||
|
|
||||||
|
- 在请求头/响应头阶段移除 `Content-Length`(便于分块传输)
|
||||||
|
- 通过 `ProcessStreamingRequestBody` / `ProcessStreamingResponseBody` 按 chunk 处理 body
|
||||||
|
- 在示例中将每个 chunk 替换为固定内容 `test\n` 并打日志
|
||||||
|
|
||||||
|
本插件**无配置项**,仅用于学习与参考实现,请勿用于生产环境。
|
||||||
|
|
||||||
|
# 处理流程
|
||||||
|
|
||||||
|
| 阶段 | 行为 |
|
||||||
|
| -------- | -------- |
|
||||||
|
| 请求头 | 删除 `content-length` |
|
||||||
|
| 请求体(流式) | 记录 chunk 日志,返回 `test\n` |
|
||||||
|
| 响应头 | 删除 `content-length` |
|
||||||
|
| 响应体(流式) | 记录 chunk 日志,返回 `test\n` |
|
||||||
|
|
||||||
|
# 配置示例
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# 无额外配置字段
|
||||||
|
```
|
||||||
|
|
||||||
|
# 构建
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd plugins/wasm-go
|
||||||
|
PLUGIN_NAME=streaming-body-example make build
|
||||||
|
```
|
||||||
|
|
||||||
|
开发自定义流式插件时,可参考本目录 `main.go` 与 [wasm-go 插件开发文档](../../README.md)。
|
||||||
Reference in New Issue
Block a user