-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4259 from Adityayxt/yxt
add a best practice: envoy-extproc-anti-demo-go.md
- Loading branch information
Showing
3 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
docs/zh/docs/skoala/best-practice/envoy-extproc-anti-demo-go.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# 云原生自定义插件示例: envoy-extproc-anti-replay-demo-go | ||
|
||
[Envoy-extproc-anti-replay-demo-go](https://github.com/projectsesame/envoy-extproc-anti-replay-demo-go)是一个基于[envoy-extproc-sdk-go](https://github.com/wrossmorrow/envoy-extproc-sdk-go)实现的,用以展示如何在Go语言中使用Envoy提供的[ext_proc](https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/ext_proc_filter)功能的示例. | ||
|
||
## 功能 | ||
|
||
它的主要功能是在将Downstream提交的请求路由到Upstream之前,先审核其sign, timestamp, nonce,如果任何一个验证失败,将直接应答401. 以达到防重放的目的. | ||
|
||
## 前置条件 | ||
|
||
- 安装Envoy (Version >= v1.29). | ||
- 安装Go (Verson >= v1.21) 如果只是运行,可跳过此步. | ||
- 支持 HTTP Method:POST的目标服务(以下简称Upstream),且假设其支持以下route: | ||
- /* | ||
- /no-extproc | ||
|
||
## 编译 | ||
|
||
进入项目根目录(如果只是运行,可跳过此步). | ||
|
||
```go | ||
go build . -o extproc | ||
``` | ||
|
||
## 运行 | ||
|
||
- Envoy: | ||
|
||
```go | ||
envoy -c ./envoy.yaml # 此文件位于项目根目录. | ||
``` | ||
|
||
- Caching: | ||
|
||
- 裸金属: | ||
|
||
```go | ||
./extproc anti-replay --log-stream --log-phases timespan "900" | ||
|
||
``` | ||
- k8s: | ||
```go | ||
kubectl apply -f ./deployment.yaml # 此文件位于项目根目录. | ||
``` | ||
- Curl | ||
```go | ||
curl --request POST \ | ||
--url http://127.0.0.1:8080/ \ | ||
--data '{ | ||
"key": "value", | ||
"key2": "", | ||
"sign": "659876b30987883efdf178e69f062896", | ||
"nonce": "6062", | ||
"timestamp": "1712480920" | ||
}' | ||
``` | ||
## 参数说明: | ||
- log-stream: 是否输出关于请求/响应流的日志. | ||
- log-phases: 是否输出各处理阶段的日志. | ||
- update-extproc-header: 是否在响应头中添加此插件的名字. | ||
- update-duration-header: 在结束流时,响应头中添加总处理时间. | ||
**以上参数默认均为false.** | ||
- timespan 900: 请求的时间跨度(**以s计**). | ||
## 注意事项: | ||
1. 此命令行参数中的前4个为全局配置参数,即所有基于[envoy-extproc-sdk-go](https://github.com/wrossmorrow/envoy-extproc-sdk-go)实现的插件都会默认支持它们;而**timespan 900**为插件(envoy-extproc-anti-replay-demo-go)特定之参数,由此插件解析与使用. | ||
2. 在此示例中使用md5作为"签名"算法,仅是为了演示方便,在正式产品中请使用SHA256WithRSA等算法. | ||
3. 以下3个字段为每个请求**必填**字段: | ||
**sign**: 计算方式为:MD5(k1=v1&k2=v2...kN=vN),生成原始字符串时按key的字母升序排列,且忽略掉值为空的key-value对. | ||
``` | ||
eg: sign= MD5("key=value&nonce=6062×tamp=1712480920") = 659876b30987883efdf178e69f062896 | ||
``` | ||
**nonce**: 在时间跨度内同一个nonce只可使用一次. | ||
**timestamp**: 以s计的当前时间. | ||
4. processing_mode的配置项中的**request_body_mode**必须配置为**下图**红框中的选项: | ||
 | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters