You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/07/22 03:49:33 UTC
[GitHub] [apisix] lunarwhite opened a new pull request, #7520: docs: refactor consumer-restriction.md
lunarwhite opened a new pull request, #7520:
URL: https://github.com/apache/apisix/pull/7520
### Description
update document under `docs/zh/latest/plugins/`
### Checklist
- [x] I have explained the need for this PR and the problem it solves
- [x] I have explained the changes or the new features added to this PR
- [ ] I have added tests corresponding to this change
- [x] I have updated the documentation to reflect this change
- [x] I have verified that this change is backward compatible (If not, please discuss on the [APISIX mailing list](https://github.com/apache/apisix/tree/master#community) first)
<!--
Note
1. Mark the PR as draft until it's ready to be reviewed.
2. Always add/update tests for any changes unless you have a good reason.
3. Always update the documentation to reflect the changes made in the PR.
4. Make a new commit to resolve conversations instead of `push -f`.
5. To resolve merge conflicts, merge master instead of rebasing.
6. Use "request review" to notify the reviewer after making changes.
7. Only a reviewer can mark a conversation as resolved.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] juzhiyuan commented on a diff in pull request #7520: docs: refactor consumer-restriction.md
Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on code in PR #7520:
URL: https://github.com/apache/apisix/pull/7520#discussion_r932786856
##########
docs/en/latest/plugins/consumer-restriction.md:
##########
@@ -33,14 +32,14 @@ The `consumer-restriction` Plugin allows users to set access restrictions based
## Attributes
-| Name | Type | Required | Default | Valid values | Description |
-|--------------------|---------------|----------|---------------|-------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
-| type | string | False | consumer_name | ["consumer_name", "service_id", "route_id"] | Type of object to base the restriction on. |
-| whitelist | array[string] | True | | | List of objects to whitelist. Has a higher priority than `allowed_by_methods`. |
-| blacklist | array[string] | True | | | List of objects to blacklist. Has a higher priority than `whitelist`. |
-| rejected_code | integer | False | 403 | [200,...] | HTTP status code returned when the request is rejected. |
-| rejected_msg | string | False | | | Message returned when the request is rejected. |
-| allowed_by_methods | array[object] | False | | ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"] | List of allowed HTTP methods for a Consumer. |
+| Name | Type | Required | Default | Valid values | Description |
+|--------------------|---------------|----------|---------------|---------------|-------------|
+| type | string | False | consumer_name | ["consumer_name", "service_id", "route_id"] | Type of object to base the restriction on. |
+| allowed_by_methods | array[object] | False | | ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"] | List of allowed HTTP methods for a Consumer. |
Review Comment:
Hi 👋 May I know why this PR adjusts the order of the attributes? (The changes are not A-Z 😅)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] juzhiyuan commented on a diff in pull request #7520: docs: refactor consumer-restriction.md
Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on code in PR #7520:
URL: https://github.com/apache/apisix/pull/7520#discussion_r932926195
##########
docs/en/latest/plugins/consumer-restriction.md:
##########
@@ -33,14 +32,14 @@ The `consumer-restriction` Plugin allows users to set access restrictions based
## Attributes
-| Name | Type | Required | Default | Valid values | Description |
-|--------------------|---------------|----------|---------------|-------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
-| type | string | False | consumer_name | ["consumer_name", "service_id", "route_id"] | Type of object to base the restriction on. |
-| whitelist | array[string] | True | | | List of objects to whitelist. Has a higher priority than `allowed_by_methods`. |
-| blacklist | array[string] | True | | | List of objects to blacklist. Has a higher priority than `whitelist`. |
-| rejected_code | integer | False | 403 | [200,...] | HTTP status code returned when the request is rejected. |
-| rejected_msg | string | False | | | Message returned when the request is rejected. |
-| allowed_by_methods | array[object] | False | | ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"] | List of allowed HTTP methods for a Consumer. |
+| Name | Type | Required | Default | Valid values | Description |
+|--------------------|---------------|----------|---------------|---------------|-------------|
+| type | string | False | consumer_name | ["consumer_name", "service_id", "route_id"] | Type of object to base the restriction on. |
+| allowed_by_methods | array[object] | False | | ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"] | List of allowed HTTP methods for a Consumer. |
Review Comment:
But the `required` fields are moved down, right? Developers may ignore those `required` fields IMO.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] lunarwhite commented on a diff in pull request #7520: docs: refactor consumer-restriction.md
Posted by GitBox <gi...@apache.org>.
lunarwhite commented on code in PR #7520:
URL: https://github.com/apache/apisix/pull/7520#discussion_r932823348
##########
docs/en/latest/plugins/consumer-restriction.md:
##########
@@ -33,14 +32,14 @@ The `consumer-restriction` Plugin allows users to set access restrictions based
## Attributes
-| Name | Type | Required | Default | Valid values | Description |
-|--------------------|---------------|----------|---------------|-------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
-| type | string | False | consumer_name | ["consumer_name", "service_id", "route_id"] | Type of object to base the restriction on. |
-| whitelist | array[string] | True | | | List of objects to whitelist. Has a higher priority than `allowed_by_methods`. |
-| blacklist | array[string] | True | | | List of objects to blacklist. Has a higher priority than `whitelist`. |
-| rejected_code | integer | False | 403 | [200,...] | HTTP status code returned when the request is rejected. |
-| rejected_msg | string | False | | | Message returned when the request is rejected. |
-| allowed_by_methods | array[object] | False | | ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"] | List of allowed HTTP methods for a Consumer. |
+| Name | Type | Required | Default | Valid values | Description |
+|--------------------|---------------|----------|---------------|---------------|-------------|
+| type | string | False | consumer_name | ["consumer_name", "service_id", "route_id"] | Type of object to base the restriction on. |
+| allowed_by_methods | array[object] | False | | ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"] | List of allowed HTTP methods for a Consumer. |
Review Comment:
What do you mean by "A-Z"?
I adjusted the order as I considered the priority of these three attributes. Please take a careful look at the `Description` of the `allowed_by_methods`, `whitelist` and `blacklist`.
Let me know if there are any concerns or suggestions. Thanks 🙏
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] lunarwhite commented on a diff in pull request #7520: docs: refactor consumer-restriction.md
Posted by GitBox <gi...@apache.org>.
lunarwhite commented on code in PR #7520:
URL: https://github.com/apache/apisix/pull/7520#discussion_r932938106
##########
docs/en/latest/plugins/consumer-restriction.md:
##########
@@ -33,14 +32,14 @@ The `consumer-restriction` Plugin allows users to set access restrictions based
## Attributes
-| Name | Type | Required | Default | Valid values | Description |
-|--------------------|---------------|----------|---------------|-------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
-| type | string | False | consumer_name | ["consumer_name", "service_id", "route_id"] | Type of object to base the restriction on. |
-| whitelist | array[string] | True | | | List of objects to whitelist. Has a higher priority than `allowed_by_methods`. |
-| blacklist | array[string] | True | | | List of objects to blacklist. Has a higher priority than `whitelist`. |
-| rejected_code | integer | False | 403 | [200,...] | HTTP status code returned when the request is rejected. |
-| rejected_msg | string | False | | | Message returned when the request is rejected. |
-| allowed_by_methods | array[object] | False | | ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"] | List of allowed HTTP methods for a Consumer. |
+| Name | Type | Required | Default | Valid values | Description |
+|--------------------|---------------|----------|---------------|---------------|-------------|
+| type | string | False | consumer_name | ["consumer_name", "service_id", "route_id"] | Type of object to base the restriction on. |
+| allowed_by_methods | array[object] | False | | ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"] | List of allowed HTTP methods for a Consumer. |
Review Comment:
👍 Good point, I didn't look at the `required` fields before.
Shall we just keep the original order?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] juzhiyuan merged pull request #7520: docs: refactor consumer-restriction.md
Posted by GitBox <gi...@apache.org>.
juzhiyuan merged PR #7520:
URL: https://github.com/apache/apisix/pull/7520
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] hf400159 commented on a diff in pull request #7520: docs: refactor consumer-restriction.md
Posted by GitBox <gi...@apache.org>.
hf400159 commented on code in PR #7520:
URL: https://github.com/apache/apisix/pull/7520#discussion_r931712560
##########
docs/zh/latest/plugins/consumer-restriction.md:
##########
@@ -92,26 +106,33 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
**测试插件**
-jack1 访问:
+`jack1` 发出访问请求,返回 `200` HTTP 状态码,代表访问成功:
```shell
curl -u jack2019:123456 http://127.0.0.1:9080/index.html -i
+```
+
+```shell
HTTP/1.1 200 OK
-...
```
-jack2 访问:
+`jack2` 发出访问请求,返回 `403` HTTP 状态码,代表访问被限制,插件生效:
```shell
curl -u jack2020:123456 http://127.0.0.1:9080/index.html -i
+```
+
+```shell
HTTP/1.1 403 Forbidden
...
{"message":"The consumer_name is forbidden."}
```
-### 如何限制 `allowed_by_methods`
+### 通过 `allowed_by_methods` 限制访问
+
+首先,创建两个 Consumer,分别为 `jack1` 和 `jack2`,方法参考 [通过 `consumer_name` 限制访问](#通过-consumername-限制访问)。
-下面是一个示例,在指定的 route 上开启了 `consumer-restriction` 插件,限制 `jack1` 只能使用 `POST` 进行访问:
+然后,在指定路由上启用并配置 `consumer-restriction` 插件,并限制指定 Consumer 只能使用指定 HTTP 方法进行访问:
Review Comment:
```suggestion
然后,在指定路由上启用并配置 `consumer-restriction` 插件,并且仅允许 `jack1` 使用 `POST` 方法进行访问:
```
##########
docs/zh/latest/plugins/consumer-restriction.md:
##########
@@ -278,20 +307,21 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
}'
```
-**测试插件**
+再次对 Service 发出访问请求,返回 `403` HTTP 状态码,说明不在白名单列表的 `service_id` 被拒绝访问,插件生效:
```shell
curl http://127.0.0.1:9080/index.html -H 'apikey: auth-jack' -i
+```
+
+```shell
HTTP/1.1 403 Forbidden
...
{"message":"The service_id is forbidden."}
```
-说明不在白名单列表的 `service_id` 被拒绝访问,插件配置生效。
-
## 禁用插件
-当你想去掉 `consumer-restriction` 插件的时候,很简单,在插件的配置中把对应的 json 配置删除即可,无须重启服务,即刻生效:
+当你需要禁用 `consumer-restriction` 插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务:
Review Comment:
```suggestion
当你需要禁用该插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务:
```
##########
docs/zh/latest/plugins/consumer-restriction.md:
##########
@@ -23,29 +28,34 @@ title: consumer-restriction
## 描述
-`consumer-restriction` 根据选择的不同对象做相应的访问限制。
+`consumer-restriction` 插件允许用户根据 Route、Service 或 Consumer 来设置相应的访问限制。
## 属性
-| 参数名 | 类型 | 可选项 | 默认值 | 有效值 | 描述 |
-| --------- | ------------- | ------ | -----------------| --------------------------------|-------------------------------------------------------------------------------------------------------------------------------|
-| type | string | 可选 | consumer_name | ["consumer_name", "service_id", "route_id"] | 根据不同的对象做相应的限制,支持 `consumer_name`、`service_id`、`route_id`。 |
-| whitelist | array[string] | 必选 | | | 与`blacklist`二选一,只能单独启用白名单或黑名单,两个不能一起使用。 |
-| blacklist | array[string] | 必选 | | | 与`whitelist`二选一,只能单独启用白名单或黑名单,两个不能一起使用。 |
-| rejected_code | integer | 可选 | 403 | [200,...] | 当请求被拒绝时,返回的 HTTP 状态码。 |
-| rejected_msg | String | 可选 | | | 当请求被拒绝时,返回的消息内容。 |
-| allowed_by_methods | array[object] | 可选 | | | 为用户设置允许的 HTTP methods 列表 , HTTP methods 可以为 `["GET","POST","PUT","DELETE","PATCH","HEAD","OPTIONS","CONNECT","TRACE", "PURGE"]` |
+| 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 |
+| --------- | ------------- | ------ | -----------------| -------------------------|------------------------|
+| type | string | 否 | consumer_name | ["consumer_name", "service_id", "route_id"] | 支持设置访问限制的对象类型。 |
+| allowed_by_methods | array[object] | 否 | | ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"] | 为 Consumer 设置的允许的 HTTP 方法列表。 |
+| whitelist | array[string] | 是 | | | 加入白名单的对象,优先级高于 `allowed_by_methods`。 |
+| blacklist | array[string] | 是 | | | 加入黑名单的对象,优先级高于 `whitelist`。 |
+| rejected_code | integer | 否 | 403 | [200,...] | 当请求被拒绝时,返回的 HTTP 状态码。 |
+| rejected_msg | string | 否 | | | 当请求被拒绝时,返回的消息内容。 |
Review Comment:
```suggestion
| rejected_msg | string | 否 | | | 当请求被拒绝时,返回的错误信息。 |
```
##########
docs/zh/latest/plugins/consumer-restriction.md:
##########
@@ -92,26 +106,33 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
**测试插件**
-jack1 访问:
+`jack1` 发出访问请求,返回 `200` HTTP 状态码,代表访问成功:
```shell
curl -u jack2019:123456 http://127.0.0.1:9080/index.html -i
+```
+
+```shell
HTTP/1.1 200 OK
-...
```
-jack2 访问:
+`jack2` 发出访问请求,返回 `403` HTTP 状态码,代表访问被限制,插件生效:
```shell
curl -u jack2020:123456 http://127.0.0.1:9080/index.html -i
+```
+
+```shell
HTTP/1.1 403 Forbidden
...
{"message":"The consumer_name is forbidden."}
```
-### 如何限制 `allowed_by_methods`
+### 通过 `allowed_by_methods` 限制访问
+
+首先,创建两个 Consumer,分别为 `jack1` 和 `jack2`,方法参考 [通过 `consumer_name` 限制访问](#通过-consumername-限制访问)。
Review Comment:
```suggestion
首先,创建两个 Consumer,分别为 `jack1` 和 `jack2`,创建方法请参考[通过 `consumer_name` 限制访问](#通过-consumername-限制访问)。
```
##########
docs/zh/latest/plugins/consumer-restriction.md:
##########
@@ -207,7 +234,7 @@ curl http://127.0.0.1:9080/apisix/admin/services/2 -H 'X-API-KEY: edd1c9f034335f
}'
```
-2、在 `consumer` 上绑定 `consumer-restriction` 插件 (需要与一个授权插件配合才能绑定),并添加 `service_id` 白名单列表
+然后配合 `key-auth` 授权插件,在指定路由上启用并配置 `consumer-restriction` 插件,并通过将 `service_id` 加入 `whitelist` 来限制 Consumer 对 Service 的访问:
Review Comment:
在指定消费者上配置 `key-auth` 和 `consumer-restriction` 插件,并将 `service_id` 加入 `whitelist` 来限制 Consumer 对 Service 的访问:
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] juzhiyuan commented on a diff in pull request #7520: docs: refactor consumer-restriction.md
Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on code in PR #7520:
URL: https://github.com/apache/apisix/pull/7520#discussion_r933034069
##########
docs/en/latest/plugins/consumer-restriction.md:
##########
@@ -33,14 +32,14 @@ The `consumer-restriction` Plugin allows users to set access restrictions based
## Attributes
-| Name | Type | Required | Default | Valid values | Description |
-|--------------------|---------------|----------|---------------|-------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
-| type | string | False | consumer_name | ["consumer_name", "service_id", "route_id"] | Type of object to base the restriction on. |
-| whitelist | array[string] | True | | | List of objects to whitelist. Has a higher priority than `allowed_by_methods`. |
-| blacklist | array[string] | True | | | List of objects to blacklist. Has a higher priority than `whitelist`. |
-| rejected_code | integer | False | 403 | [200,...] | HTTP status code returned when the request is rejected. |
-| rejected_msg | string | False | | | Message returned when the request is rejected. |
-| allowed_by_methods | array[object] | False | | ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"] | List of allowed HTTP methods for a Consumer. |
+| Name | Type | Required | Default | Valid values | Description |
+|--------------------|---------------|----------|---------------|---------------|-------------|
+| type | string | False | consumer_name | ["consumer_name", "service_id", "route_id"] | Type of object to base the restriction on. |
+| allowed_by_methods | array[object] | False | | ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"] | List of allowed HTTP methods for a Consumer. |
Review Comment:
Yes, I prefer keeping `Required` fields in the top :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org