-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: support consumer bind plugins. #544
Merged
Merged
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
6210de1
feature: saved consumer plugin information.
membphis 281c80e
change: name style.
membphis e28f411
feature: supported to merge plugin with consumer and route.
membphis 213a297
bugfix: run `access` phase for global rules.
membphis e0185e7
test: delete route 1(it may cause fail).
membphis b74f1d1
feature: supported to bind plugin on consumer and added test cases.
membphis 0b8bfd3
change: code style.
membphis b8cc9c9
change: name style.
membphis 1612ca7
test: fixed test case.
membphis 4182ced
test: fixed test cases.
membphis e2ad166
change: code style.
membphis 922ed26
change: code style.
membphis 6adf6b5
change: wrote some log for testing.
membphis c870138
doc: updated.
membphis 8227e0b
change: removed `consumer` from core.
membphis 04395af
change: error message more meaningful.
membphis 6e7bee1
change: merged all of the configrations of plugin to `plugins`.
membphis 2464942
doc: reverted.
membphis 1f7217c
change: code style.
membphis 44036ae
doc
membphis 28020f2
doc: style.
membphis b55f765
test: added more test case.
membphis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -369,20 +369,72 @@ APISIX 区别于其他 API 网关的一大特点是允许用户选择不同 Rout | |
|
||
如上图所示,作为 API 网关,需要知道 API Consumer(消费方)具体是谁,这样就可以对不同 API Consumer 配置不同规则。 | ||
|
||
|字段|可选|说明| | ||
|---|----|----| | ||
|username|必选|Consumer 名称。| | ||
|plugins|可选|该 Consumer 对应的插件配置,它的优先级是最高的:Consumer > Route > Service。对于具体插件配置,可以参考 [Plugins](#plugin) 章节。| | ||
|
||
在 APISIX 中,识别 Consumer 的过程如下图: | ||
|
||
<img src="./images/consumer-internal.png" width="50%" height="50%"> | ||
|
||
1. 授权认证:比如有 [key-auth](doc/plugins/key-auth.md)、[JWT](doc/plugins/jwt-auth-cn.md) 等。 | ||
1. 授权认证:比如有 [key-auth](./plugins/key-auth.md)、[JWT](./plugins/jwt-auth-cn.md) 等。 | ||
2. 获取 consumer_id:通过授权认证,即可自然获取到对应的 Consumer `id`,它是 Consumer 对象的唯一识别标识。 | ||
3. 获取 Consumer 上绑定的 Plugin 或 Upstream 信息:完成对不同 Consumer 做不同配置的效果。 | ||
|
||
概括一下,Consumer 是某类服务的消费者,需与用户认证体系配合才能使用。 | ||
比如不同的 Consumer 请求同一个 API,网关服务根据当前请求用户信息,对应不同的 Plugin 或 Upstream 配置。 | ||
|
||
此外,大家也可以参考 [key-auth](doc/plugins/key-auth.md) 认证授权插件的调用逻辑,辅助大家来进一步理解 Consumer 概念和使用。 | ||
此外,大家也可以参考 [key-auth](./plugins/key-auth.md) 认证授权插件的调用逻辑,辅助大家来进一步理解 Consumer 概念和使用。 | ||
|
||
如何对某个 Consumer 开启指定插件,可以看下面例子: | ||
|
||
```shell | ||
# 创建 Consumer ,指定认证插件 key-auth ,并开启特定插件 limit-count | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 应使用中文逗号 |
||
$ curl http://127.0.0.1:9080/apisix/admin/consumers/1 -X PUT -d ' | ||
{ | ||
"username": "jack", | ||
"plugins": { | ||
"key-auth": { | ||
"key": "auth-one" | ||
}, | ||
"limit-count": { | ||
"count": 2, | ||
"time_window": 60, | ||
"rejected_code": 503, | ||
"key": "remote_addr" | ||
} | ||
} | ||
}' | ||
|
||
# 创建 Router,设置路由规则和启用插件配置 | ||
$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d ' | ||
{ | ||
"plugins": { | ||
"key-auth": {} | ||
}, | ||
"upstream": { | ||
"nodes": { | ||
"127.0.0.1:1980": 1 | ||
}, | ||
"type": "roundrobin" | ||
}, | ||
"uri": "/hello" | ||
}' | ||
|
||
# 发测试请求,前两次返回正常,没达到限速阈值 | ||
$ curl http://127.0.0.1:9080/hello -H 'apikey: auth-one' -I | ||
... | ||
|
||
*注意*:目前 APISIX 的 Consumer 还不支持绑定插件或上游信息,如果大家对这个功能点感兴趣,欢迎在社区中反馈交流。 | ||
$ curl http://127.0.0.1:9080/hello -H 'apikey: auth-one' -I | ||
... | ||
|
||
# 第三次测试返回 503,请求被限制 | ||
$ curl http://127.0.0.1:9080/hello -H 'apikey: auth-one' -I | ||
HTTP/1.1 503 Service Temporarily Unavailable | ||
... | ||
|
||
``` | ||
|
||
[返回目录](#目录) | ||
|
||
|
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
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
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
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
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议修改为 必选:是/否
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good, fix later